Fix linter issues

This commit is contained in:
freearhey 2025-01-04 20:48:37 +03:00
parent 8b0952b915
commit e8f89b216c
4 changed files with 255 additions and 264 deletions

View file

@ -1,60 +1,59 @@
const dayjs = require('dayjs') const dayjs = require('dayjs')
const utc = require('dayjs/plugin/utc') const utc = require('dayjs/plugin/utc')
const timezone = require('dayjs/plugin/timezone') const timezone = require('dayjs/plugin/timezone')
const customParseFormat = require('dayjs/plugin/customParseFormat') const customParseFormat = require('dayjs/plugin/customParseFormat')
const cheerio = require('cheerio')
dayjs.extend(utc)
dayjs.extend(utc) dayjs.extend(timezone)
dayjs.extend(timezone) dayjs.extend(customParseFormat)
dayjs.extend(customParseFormat)
module.exports = {
module.exports = { site: 'cyta.com.cy',
site: 'cyta.com.cy', days: 7,
days: 7, request: {
request: { cache: {
cache: { ttl: 60 * 60 * 1000 // 1 hour
ttl: 60 * 60 * 1000 // 1 hour }
} },
}, url: function ({ date, channel }) {
url: function ({date, channel}) { // Get the epoch timestamp
// Get the epoch timestamp const todayEpoch = date.startOf('day').utc().valueOf()
const todayEpoch = date.startOf('day').utc().valueOf() // Get the epoch timestamp for the next day
// Get the epoch timestamp for the next day const nextDayEpoch = date.add(1, 'day').startOf('day').utc().valueOf()
const nextDayEpoch = date.add(1, 'day').startOf('day').utc().valueOf() return `https://epg.cyta.com.cy/api/mediacatalog/fetchEpg?startTimeEpoch=${todayEpoch}&endTimeEpoch=${nextDayEpoch}&language=1&channelIds=${channel.site_id}`
return `https://epg.cyta.com.cy/api/mediacatalog/fetchEpg?startTimeEpoch=${todayEpoch}&endTimeEpoch=${nextDayEpoch}&language=1&channelIds=${channel.site_id}` },
}, parser: function ({ content }) {
parser: function ({content}) { const data = JSON.parse(content)
const data = JSON.parse(content) const programs = []
const programs = []
data.channelEpgs.forEach(channel => {
data.channelEpgs.forEach(channel => { channel.epgPlayables.forEach(epg => {
channel.epgPlayables.forEach(epg => { const start = new Date(epg.startTime).toISOString()
const start = new Date(epg.startTime).toISOString(); const stop = new Date(epg.endTime).toISOString()
const stop = new Date(epg.endTime).toISOString();
programs.push({
programs.push({ title: epg.name,
title: epg.name, start,
start, stop
stop })
}) })
}) })
})
return programs
return programs },
}, async channels() {
async channels() { const axios = require('axios')
const axios = require('axios') const data = await axios
const data = await axios .get('https://epg.cyta.com.cy/api/mediacatalog/fetchChannels?language=1')
.get(`https://epg.cyta.com.cy/api/mediacatalog/fetchChannels?language=1`) .then(r => r.data)
.then(r => r.data) .catch(console.log)
.catch(console.log)
return data.channels.map(item => {
return data.channels.map(item => { return {
return { lang: 'el',
lang: 'el', site_id: item.id,
site_id: item.id, name: item.name
name: item.name }
} })
}) }
} }
}

View file

@ -1,53 +1,49 @@
const { url, parser } = require('./cyta.com.cy.config.js') const { url, parser } = require('./cyta.com.cy.config.js')
const dayjs = require('dayjs') const dayjs = require('dayjs')
const utc = require('dayjs/plugin/utc') const utc = require('dayjs/plugin/utc')
const customParseFormat = require('dayjs/plugin/customParseFormat') const customParseFormat = require('dayjs/plugin/customParseFormat')
dayjs.extend(utc) dayjs.extend(utc)
dayjs.extend(customParseFormat) dayjs.extend(customParseFormat)
const date = dayjs.utc('2025-01-03', 'YYYY-MM-DD').startOf('day') const date = dayjs.utc('2025-01-03', 'YYYY-MM-DD').startOf('day')
const channel = { const channel = {
site_id: '561066', site_id: '561066',
xmltv_id: 'RIK1.cy' xmltv_id: 'RIK1.cy'
} }
it('can generate valid url', () => { it('can generate valid url', () => {
const generatedUrl = url({ date, channel }) const generatedUrl = url({ date, channel })
expect(generatedUrl).toBe( expect(generatedUrl).toBe(
'https://epg.cyta.com.cy/api/mediacatalog/fetchEpg?startTimeEpoch=1735862400000&endTimeEpoch=1735948800000&language=1&channelIds=561066' 'https://epg.cyta.com.cy/api/mediacatalog/fetchEpg?startTimeEpoch=1735862400000&endTimeEpoch=1735948800000&language=1&channelIds=561066'
) )
}) })
it('can parse response', () => { it('can parse response', () => {
const content = ` const content = `
{ {
"channelEpgs": [ "channelEpgs": [
{ {
"epgPlayables": [ "epgPlayables": [
{ "name": "Πρώτη Ενημέρωση", "startTime": 1735879500000, "endTime": 1735889400000 } { "name": "Πρώτη Ενημέρωση", "startTime": 1735879500000, "endTime": 1735889400000 }
] ]
} }
] ]
}` }`
const result = parser({ content }).map(p => { const result = parser({ content })
p.start = p.start
p.stop = p.stop expect(result).toMatchObject([
return p {
}) title: 'Πρώτη Ενημέρωση',
start: '2025-01-03T04:45:00.000Z',
expect(result).toMatchObject([ stop: '2025-01-03T07:30:00.000Z'
{ }
title: 'Πρώτη Ενημέρωση', ])
start: '2025-01-03T04:45:00.000Z', })
stop: '2025-01-03T07:30:00.000Z'
} it('can handle empty guide', () => {
]) const result = parser({
}) content: '{"channelEpgs":[]}'
})
it('can handle empty guide', () => { expect(result).toMatchObject([])
const result = parser({ })
content: '{"channelEpgs":[]}'
})
expect(result).toMatchObject([])
})

View file

@ -1,68 +1,67 @@
const dayjs = require('dayjs') const dayjs = require('dayjs')
const utc = require('dayjs/plugin/utc') const utc = require('dayjs/plugin/utc')
const axios = require('axios') const axios = require('axios')
dayjs.extend(utc) dayjs.extend(utc)
module.exports = { module.exports = {
site: 'stod2.is', site: 'stod2.is',
channels: 'stod2.is.channels.xml', days: 7,
days: 7, request: {
request: { cache: {
cache: { ttl: 60 * 60 * 1000 // 1 hour
ttl: 60 * 60 * 1000 // 1 hour }
} },
}, url({ channel, date }) {
url({ channel, date }) { return `https://api.stod2.is/dagskra/api/${channel.site_id}/${date.format('YYYY-MM-DD')}`
return `https://api.stod2.is/dagskra/api/${channel.site_id}/${date.format('YYYY-MM-DD')}` },
}, parser: function ({ content }) {
parser: function ({ content }) { let data
let data try {
try { data = JSON.parse(content)
data = JSON.parse(content) } catch (error) {
} catch (error) { console.error('Error parsing JSON:', error)
console.error('Error parsing JSON:', error) return []
return [] }
}
const programs = []
const programs = []
if (data && Array.isArray(data)) {
if (data && Array.isArray(data)) { data.forEach(item => {
data.forEach(item => { if (!item) return
if (!item) return const start = dayjs.utc(item.upphaf)
const start = dayjs.utc(item.upphaf) const stop = start.add(item.slott, 'm')
const stop = start.add(item.slott, 'm')
programs.push({
programs.push({ title: item.isltitill,
title: item.isltitill, sub_title: item.undirtitill,
sub_title: item.undirtitill, description: item.lysing,
description: item.lysing, actors: item.adalhlutverk,
actors: item.adalhlutverk, directors: item.leikstjori,
directors: item.leikstjori, start,
start, stop
stop })
}) })
}) }
}
return programs
return programs },
}, async channels() {
async channels() { try {
try { const response = await axios.get('https://api.stod2.is/dagskra/api')
const response = await axios.get('https://api.stod2.is/dagskra/api') if (!response.data || !Array.isArray(response.data)) {
if (!response.data || !Array.isArray(response.data)) { console.error('Error: No channels data found')
console.error('Error: No channels data found') return []
return [] }
} return response.data.map(item => {
return response.data.map(item => { return {
return { lang: 'is',
lang: 'is', site_id: item
site_id: item }
} })
}) } catch (error) {
} catch (error) { console.error('Error fetching channels:', error)
console.error('Error fetching channels:', error) return []
return [] }
} }
} }
}

View file

@ -1,83 +1,80 @@
const { parser, url } = require('./stod2.is.config.js') const { parser, url } = require('./stod2.is.config.js')
const dayjs = require('dayjs') const dayjs = require('dayjs')
const utc = require('dayjs/plugin/utc') const utc = require('dayjs/plugin/utc')
const customParseFormat = require('dayjs/plugin/customParseFormat') const customParseFormat = require('dayjs/plugin/customParseFormat')
const timezone = require('dayjs/plugin/timezone') const timezone = require('dayjs/plugin/timezone')
const axios = require('axios')
dayjs.extend(utc)
dayjs.extend(utc) dayjs.extend(customParseFormat)
dayjs.extend(customParseFormat) dayjs.extend(timezone)
dayjs.extend(timezone)
const date = dayjs.utc('2025-01-03', 'YYYY-MM-DD').startOf('day')
jest.mock('axios') const channel = { site_id: 'stod2', xmltv_id: 'Stod2.is' }
const date = dayjs.utc('2025-01-03', 'YYYY-MM-DD').startOf('day') const mockEpgData = JSON.stringify([
const channel = { site_id: 'stod2', xmltv_id: 'Stod2.is' } {
midill: 'STOD2',
const mockEpgData = JSON.stringify([ midill_heiti: 'Stöð 2',
{ dagsetning: '2025-01-03T00:00:00Z',
midill: 'STOD2', upphaf: '2025-01-03T08:00:00Z',
midill_heiti: 'Stöð 2', titill: 'Telma Borgþórsdóttir',
dagsetning: '2025-01-03T00:00:00Z', isltitill: 'Heimsókn',
upphaf: '2025-01-03T08:00:00Z', undirtitill: 'Telma Borgþórsdóttir',
titill: 'Telma Borgþórsdóttir', seria: 8,
isltitill: 'Heimsókn', thattur: 5,
undirtitill: 'Telma Borgþórsdóttir', thattafjoldi: 10,
seria: 8, birta_thatt: 1,
thattur: 5, opin: 0,
thattafjoldi: 10, beint: 0,
birta_thatt: 1, frumsyning: 0,
opin: 0, framundan_i_beinni: 0,
beint: 0, tegund: 'SER',
frumsyning: 0, flokkur: 'Icelandic',
framundan_i_beinni: 0, adalhlutverk: '',
tegund: 'SER', leikstjori: '',
flokkur: 'Icelandic', ar: '2019',
adalhlutverk: '', bannad: 'Green',
leikstjori: '', recidefni: 592645105,
ar: '2019', recidlidur: 592645184,
bannad: 'Green', recidsyning: null,
recidefni: 592645105, refno: null,
recidlidur: 592645184, frelsi: 0,
recidsyning: null, netdagar: 0,
refno: null, lysing:
frelsi: 0, 'Frábærir þættir með Sindra Sindrasyni sem lítur inn hjá íslenskum fagurkerum. Heimilin eru jafn ólík og þau eru mörg en eiga það þó eitt sameiginlegt að vera sett saman af alúð og smekklegheitum. Sindri hefur líka einstakt lag á að ná fram því besta í viðmælendum sínum.',
netdagar: 0, slott: 15,
lysing: slotlengd: '00:15'
'Frábærir þættir með Sindra Sindrasyni sem lítur inn hjá íslenskum fagurkerum. Heimilin eru jafn ólík og þau eru mörg en eiga það þó eitt sameiginlegt að vera sett saman af alúð og smekklegheitum. Sindri hefur líka einstakt lag á að ná fram því besta í viðmælendum sínum.', }
slott: 15, ])
slotlengd: '00:15'
} it('can generate valid url', () => {
]) const generatedUrl = url({ date, channel })
expect(generatedUrl).toBe('https://api.stod2.is/dagskra/api/stod2/2025-01-03')
it('can generate valid url', () => { })
const generatedUrl = url({ date, channel })
expect(generatedUrl).toBe('https://api.stod2.is/dagskra/api/stod2/2025-01-03') it('can parse response', () => {
}) const content = mockEpgData
const result = parser({ content }).map(p => {
it('can parse response', () => { p.start = p.start.toISOString()
const content = mockEpgData p.stop = p.stop.toISOString()
const result = parser({ content }).map(p => { return p
p.start = p.start.toISOString() })
p.stop = p.stop.toISOString()
return p expect(result).toMatchObject([
}) {
title: 'Heimsókn',
expect(result).toMatchObject([ sub_title: 'Telma Borgþórsdóttir',
{ description:
title: 'Heimsókn', 'Frábærir þættir með Sindra Sindrasyni sem lítur inn hjá íslenskum fagurkerum. Heimilin eru jafn ólík og þau eru mörg en eiga það þó eitt sameiginlegt að vera sett saman af alúð og smekklegheitum. Sindri hefur líka einstakt lag á að ná fram því besta í viðmælendum sínum.',
sub_title: 'Telma Borgþórsdóttir', actors: '',
description: directors: '',
'Frábærir þættir með Sindra Sindrasyni sem lítur inn hjá íslenskum fagurkerum. Heimilin eru jafn ólík og þau eru mörg en eiga það þó eitt sameiginlegt að vera sett saman af alúð og smekklegheitum. Sindri hefur líka einstakt lag á að ná fram því besta í viðmælendum sínum.', start: '2025-01-03T08:00:00.000Z',
actors: '', stop: '2025-01-03T08:15:00.000Z'
directors: '', }
start: '2025-01-03T08:00:00.000Z', ])
stop: '2025-01-03T08:15:00.000Z' })
}
]) it('can handle empty guide', () => {
}) const result = parser({ content: '[]' })
expect(result).toMatchObject([])
it('can handle empty guide', () => { })
const result = parser({ content: '[]' })
expect(result).toMatchObject([])
})