mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-09 08:30:06 -04:00
Fix linter issues
This commit is contained in:
parent
8b0952b915
commit
e8f89b216c
4 changed files with 255 additions and 264 deletions
|
@ -1,60 +1,59 @@
|
|||
const dayjs = require('dayjs')
|
||||
const utc = require('dayjs/plugin/utc')
|
||||
const timezone = require('dayjs/plugin/timezone')
|
||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||
const cheerio = require('cheerio')
|
||||
|
||||
dayjs.extend(utc)
|
||||
dayjs.extend(timezone)
|
||||
dayjs.extend(customParseFormat)
|
||||
|
||||
module.exports = {
|
||||
site: 'cyta.com.cy',
|
||||
days: 7,
|
||||
request: {
|
||||
cache: {
|
||||
ttl: 60 * 60 * 1000 // 1 hour
|
||||
}
|
||||
},
|
||||
url: function ({date, channel}) {
|
||||
// Get the epoch timestamp
|
||||
const todayEpoch = date.startOf('day').utc().valueOf()
|
||||
// Get the epoch timestamp for the next day
|
||||
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}`
|
||||
},
|
||||
parser: function ({content}) {
|
||||
const data = JSON.parse(content)
|
||||
const programs = []
|
||||
|
||||
data.channelEpgs.forEach(channel => {
|
||||
channel.epgPlayables.forEach(epg => {
|
||||
const start = new Date(epg.startTime).toISOString();
|
||||
const stop = new Date(epg.endTime).toISOString();
|
||||
|
||||
programs.push({
|
||||
title: epg.name,
|
||||
start,
|
||||
stop
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
return programs
|
||||
},
|
||||
async channels() {
|
||||
const axios = require('axios')
|
||||
const data = await axios
|
||||
.get(`https://epg.cyta.com.cy/api/mediacatalog/fetchChannels?language=1`)
|
||||
.then(r => r.data)
|
||||
.catch(console.log)
|
||||
|
||||
return data.channels.map(item => {
|
||||
return {
|
||||
lang: 'el',
|
||||
site_id: item.id,
|
||||
name: item.name
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
const dayjs = require('dayjs')
|
||||
const utc = require('dayjs/plugin/utc')
|
||||
const timezone = require('dayjs/plugin/timezone')
|
||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||
|
||||
dayjs.extend(utc)
|
||||
dayjs.extend(timezone)
|
||||
dayjs.extend(customParseFormat)
|
||||
|
||||
module.exports = {
|
||||
site: 'cyta.com.cy',
|
||||
days: 7,
|
||||
request: {
|
||||
cache: {
|
||||
ttl: 60 * 60 * 1000 // 1 hour
|
||||
}
|
||||
},
|
||||
url: function ({ date, channel }) {
|
||||
// Get the epoch timestamp
|
||||
const todayEpoch = date.startOf('day').utc().valueOf()
|
||||
// Get the epoch timestamp for the next day
|
||||
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}`
|
||||
},
|
||||
parser: function ({ content }) {
|
||||
const data = JSON.parse(content)
|
||||
const programs = []
|
||||
|
||||
data.channelEpgs.forEach(channel => {
|
||||
channel.epgPlayables.forEach(epg => {
|
||||
const start = new Date(epg.startTime).toISOString()
|
||||
const stop = new Date(epg.endTime).toISOString()
|
||||
|
||||
programs.push({
|
||||
title: epg.name,
|
||||
start,
|
||||
stop
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
return programs
|
||||
},
|
||||
async channels() {
|
||||
const axios = require('axios')
|
||||
const data = await axios
|
||||
.get('https://epg.cyta.com.cy/api/mediacatalog/fetchChannels?language=1')
|
||||
.then(r => r.data)
|
||||
.catch(console.log)
|
||||
|
||||
return data.channels.map(item => {
|
||||
return {
|
||||
lang: 'el',
|
||||
site_id: item.id,
|
||||
name: item.name
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,53 +1,49 @@
|
|||
const { url, parser } = require('./cyta.com.cy.config.js')
|
||||
const dayjs = require('dayjs')
|
||||
const utc = require('dayjs/plugin/utc')
|
||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||
dayjs.extend(utc)
|
||||
dayjs.extend(customParseFormat)
|
||||
|
||||
const date = dayjs.utc('2025-01-03', 'YYYY-MM-DD').startOf('day')
|
||||
const channel = {
|
||||
site_id: '561066',
|
||||
xmltv_id: 'RIK1.cy'
|
||||
}
|
||||
|
||||
it('can generate valid url', () => {
|
||||
const generatedUrl = url({ date, channel })
|
||||
expect(generatedUrl).toBe(
|
||||
'https://epg.cyta.com.cy/api/mediacatalog/fetchEpg?startTimeEpoch=1735862400000&endTimeEpoch=1735948800000&language=1&channelIds=561066'
|
||||
)
|
||||
})
|
||||
|
||||
it('can parse response', () => {
|
||||
const content = `
|
||||
{
|
||||
"channelEpgs": [
|
||||
{
|
||||
"epgPlayables": [
|
||||
{ "name": "Πρώτη Ενημέρωση", "startTime": 1735879500000, "endTime": 1735889400000 }
|
||||
]
|
||||
}
|
||||
]
|
||||
}`
|
||||
|
||||
const result = parser({ content }).map(p => {
|
||||
p.start = p.start
|
||||
p.stop = p.stop
|
||||
return p
|
||||
})
|
||||
|
||||
expect(result).toMatchObject([
|
||||
{
|
||||
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":[]}'
|
||||
})
|
||||
expect(result).toMatchObject([])
|
||||
})
|
||||
const { url, parser } = require('./cyta.com.cy.config.js')
|
||||
const dayjs = require('dayjs')
|
||||
const utc = require('dayjs/plugin/utc')
|
||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||
dayjs.extend(utc)
|
||||
dayjs.extend(customParseFormat)
|
||||
|
||||
const date = dayjs.utc('2025-01-03', 'YYYY-MM-DD').startOf('day')
|
||||
const channel = {
|
||||
site_id: '561066',
|
||||
xmltv_id: 'RIK1.cy'
|
||||
}
|
||||
|
||||
it('can generate valid url', () => {
|
||||
const generatedUrl = url({ date, channel })
|
||||
expect(generatedUrl).toBe(
|
||||
'https://epg.cyta.com.cy/api/mediacatalog/fetchEpg?startTimeEpoch=1735862400000&endTimeEpoch=1735948800000&language=1&channelIds=561066'
|
||||
)
|
||||
})
|
||||
|
||||
it('can parse response', () => {
|
||||
const content = `
|
||||
{
|
||||
"channelEpgs": [
|
||||
{
|
||||
"epgPlayables": [
|
||||
{ "name": "Πρώτη Ενημέρωση", "startTime": 1735879500000, "endTime": 1735889400000 }
|
||||
]
|
||||
}
|
||||
]
|
||||
}`
|
||||
|
||||
const result = parser({ content })
|
||||
|
||||
expect(result).toMatchObject([
|
||||
{
|
||||
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":[]}'
|
||||
})
|
||||
expect(result).toMatchObject([])
|
||||
})
|
||||
|
|
|
@ -1,68 +1,67 @@
|
|||
const dayjs = require('dayjs')
|
||||
const utc = require('dayjs/plugin/utc')
|
||||
const axios = require('axios')
|
||||
|
||||
dayjs.extend(utc)
|
||||
|
||||
module.exports = {
|
||||
site: 'stod2.is',
|
||||
channels: 'stod2.is.channels.xml',
|
||||
days: 7,
|
||||
request: {
|
||||
cache: {
|
||||
ttl: 60 * 60 * 1000 // 1 hour
|
||||
}
|
||||
},
|
||||
url({ channel, date }) {
|
||||
return `https://api.stod2.is/dagskra/api/${channel.site_id}/${date.format('YYYY-MM-DD')}`
|
||||
},
|
||||
parser: function ({ content }) {
|
||||
let data
|
||||
try {
|
||||
data = JSON.parse(content)
|
||||
} catch (error) {
|
||||
console.error('Error parsing JSON:', error)
|
||||
return []
|
||||
}
|
||||
|
||||
const programs = []
|
||||
|
||||
if (data && Array.isArray(data)) {
|
||||
data.forEach(item => {
|
||||
if (!item) return
|
||||
const start = dayjs.utc(item.upphaf)
|
||||
const stop = start.add(item.slott, 'm')
|
||||
|
||||
programs.push({
|
||||
title: item.isltitill,
|
||||
sub_title: item.undirtitill,
|
||||
description: item.lysing,
|
||||
actors: item.adalhlutverk,
|
||||
directors: item.leikstjori,
|
||||
start,
|
||||
stop
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
return programs
|
||||
},
|
||||
async channels() {
|
||||
try {
|
||||
const response = await axios.get('https://api.stod2.is/dagskra/api')
|
||||
if (!response.data || !Array.isArray(response.data)) {
|
||||
console.error('Error: No channels data found')
|
||||
return []
|
||||
}
|
||||
return response.data.map(item => {
|
||||
return {
|
||||
lang: 'is',
|
||||
site_id: item
|
||||
}
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('Error fetching channels:', error)
|
||||
return []
|
||||
}
|
||||
}
|
||||
}
|
||||
const dayjs = require('dayjs')
|
||||
const utc = require('dayjs/plugin/utc')
|
||||
const axios = require('axios')
|
||||
|
||||
dayjs.extend(utc)
|
||||
|
||||
module.exports = {
|
||||
site: 'stod2.is',
|
||||
days: 7,
|
||||
request: {
|
||||
cache: {
|
||||
ttl: 60 * 60 * 1000 // 1 hour
|
||||
}
|
||||
},
|
||||
url({ channel, date }) {
|
||||
return `https://api.stod2.is/dagskra/api/${channel.site_id}/${date.format('YYYY-MM-DD')}`
|
||||
},
|
||||
parser: function ({ content }) {
|
||||
let data
|
||||
try {
|
||||
data = JSON.parse(content)
|
||||
} catch (error) {
|
||||
console.error('Error parsing JSON:', error)
|
||||
return []
|
||||
}
|
||||
|
||||
const programs = []
|
||||
|
||||
if (data && Array.isArray(data)) {
|
||||
data.forEach(item => {
|
||||
if (!item) return
|
||||
const start = dayjs.utc(item.upphaf)
|
||||
const stop = start.add(item.slott, 'm')
|
||||
|
||||
programs.push({
|
||||
title: item.isltitill,
|
||||
sub_title: item.undirtitill,
|
||||
description: item.lysing,
|
||||
actors: item.adalhlutverk,
|
||||
directors: item.leikstjori,
|
||||
start,
|
||||
stop
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
return programs
|
||||
},
|
||||
async channels() {
|
||||
try {
|
||||
const response = await axios.get('https://api.stod2.is/dagskra/api')
|
||||
if (!response.data || !Array.isArray(response.data)) {
|
||||
console.error('Error: No channels data found')
|
||||
return []
|
||||
}
|
||||
return response.data.map(item => {
|
||||
return {
|
||||
lang: 'is',
|
||||
site_id: item
|
||||
}
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('Error fetching channels:', error)
|
||||
return []
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,83 +1,80 @@
|
|||
const { parser, url } = require('./stod2.is.config.js')
|
||||
const dayjs = require('dayjs')
|
||||
const utc = require('dayjs/plugin/utc')
|
||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||
const timezone = require('dayjs/plugin/timezone')
|
||||
const axios = require('axios')
|
||||
|
||||
dayjs.extend(utc)
|
||||
dayjs.extend(customParseFormat)
|
||||
dayjs.extend(timezone)
|
||||
|
||||
jest.mock('axios')
|
||||
|
||||
const date = dayjs.utc('2025-01-03', 'YYYY-MM-DD').startOf('day')
|
||||
const channel = { site_id: 'stod2', xmltv_id: 'Stod2.is' }
|
||||
|
||||
const mockEpgData = JSON.stringify([
|
||||
{
|
||||
midill: 'STOD2',
|
||||
midill_heiti: 'Stöð 2',
|
||||
dagsetning: '2025-01-03T00:00:00Z',
|
||||
upphaf: '2025-01-03T08:00:00Z',
|
||||
titill: 'Telma Borgþórsdóttir',
|
||||
isltitill: 'Heimsókn',
|
||||
undirtitill: 'Telma Borgþórsdóttir',
|
||||
seria: 8,
|
||||
thattur: 5,
|
||||
thattafjoldi: 10,
|
||||
birta_thatt: 1,
|
||||
opin: 0,
|
||||
beint: 0,
|
||||
frumsyning: 0,
|
||||
framundan_i_beinni: 0,
|
||||
tegund: 'SER',
|
||||
flokkur: 'Icelandic',
|
||||
adalhlutverk: '',
|
||||
leikstjori: '',
|
||||
ar: '2019',
|
||||
bannad: 'Green',
|
||||
recidefni: 592645105,
|
||||
recidlidur: 592645184,
|
||||
recidsyning: null,
|
||||
refno: null,
|
||||
frelsi: 0,
|
||||
netdagar: 0,
|
||||
lysing:
|
||||
'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 parse response', () => {
|
||||
const content = mockEpgData
|
||||
const result = parser({ content }).map(p => {
|
||||
p.start = p.start.toISOString()
|
||||
p.stop = p.stop.toISOString()
|
||||
return p
|
||||
})
|
||||
|
||||
expect(result).toMatchObject([
|
||||
{
|
||||
title: 'Heimsókn',
|
||||
sub_title: 'Telma Borgþórsdóttir',
|
||||
description:
|
||||
'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.',
|
||||
actors: '',
|
||||
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([])
|
||||
})
|
||||
const { parser, url } = require('./stod2.is.config.js')
|
||||
const dayjs = require('dayjs')
|
||||
const utc = require('dayjs/plugin/utc')
|
||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||
const timezone = require('dayjs/plugin/timezone')
|
||||
|
||||
dayjs.extend(utc)
|
||||
dayjs.extend(customParseFormat)
|
||||
dayjs.extend(timezone)
|
||||
|
||||
const date = dayjs.utc('2025-01-03', 'YYYY-MM-DD').startOf('day')
|
||||
const channel = { site_id: 'stod2', xmltv_id: 'Stod2.is' }
|
||||
|
||||
const mockEpgData = JSON.stringify([
|
||||
{
|
||||
midill: 'STOD2',
|
||||
midill_heiti: 'Stöð 2',
|
||||
dagsetning: '2025-01-03T00:00:00Z',
|
||||
upphaf: '2025-01-03T08:00:00Z',
|
||||
titill: 'Telma Borgþórsdóttir',
|
||||
isltitill: 'Heimsókn',
|
||||
undirtitill: 'Telma Borgþórsdóttir',
|
||||
seria: 8,
|
||||
thattur: 5,
|
||||
thattafjoldi: 10,
|
||||
birta_thatt: 1,
|
||||
opin: 0,
|
||||
beint: 0,
|
||||
frumsyning: 0,
|
||||
framundan_i_beinni: 0,
|
||||
tegund: 'SER',
|
||||
flokkur: 'Icelandic',
|
||||
adalhlutverk: '',
|
||||
leikstjori: '',
|
||||
ar: '2019',
|
||||
bannad: 'Green',
|
||||
recidefni: 592645105,
|
||||
recidlidur: 592645184,
|
||||
recidsyning: null,
|
||||
refno: null,
|
||||
frelsi: 0,
|
||||
netdagar: 0,
|
||||
lysing:
|
||||
'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 parse response', () => {
|
||||
const content = mockEpgData
|
||||
const result = parser({ content }).map(p => {
|
||||
p.start = p.start.toISOString()
|
||||
p.stop = p.stop.toISOString()
|
||||
return p
|
||||
})
|
||||
|
||||
expect(result).toMatchObject([
|
||||
{
|
||||
title: 'Heimsókn',
|
||||
sub_title: 'Telma Borgþórsdóttir',
|
||||
description:
|
||||
'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.',
|
||||
actors: '',
|
||||
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([])
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue