mirror of
https://github.com/iptv-org/epg
synced 2026-03-21 19:30:52 -04:00
.
This commit is contained in:
@@ -15,37 +15,42 @@ module.exports = {
|
||||
url({ channel, date }) {
|
||||
return `https://www.syn.is/api/epg/${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 []
|
||||
}
|
||||
parser: function ({ content, date }) {
|
||||
let data
|
||||
try {
|
||||
data = JSON.parse(content)
|
||||
} catch (error) {
|
||||
console.error('Error parsing JSON:', error)
|
||||
return []
|
||||
}
|
||||
|
||||
const programs = []
|
||||
if (!Array.isArray(data)) return []
|
||||
|
||||
if (data && Array.isArray(data)) {
|
||||
data.forEach(item => {
|
||||
if (!item) return
|
||||
const start = dayjs.utc(item.upphaf)
|
||||
const stop = start.add(item.slott, 'm')
|
||||
const programs = []
|
||||
|
||||
programs.push({
|
||||
title: item.isltitill,
|
||||
sub_title: item.undirtitill,
|
||||
description: item.lysing,
|
||||
actors: item.adalhlutverk,
|
||||
directors: item.leikstjori,
|
||||
start,
|
||||
stop
|
||||
data
|
||||
.filter(item => item?.upphaf)
|
||||
.forEach(item => {
|
||||
const start = dayjs.utc(item.upphaf)
|
||||
|
||||
if (start.format('YYYY-MM-DD') === date.format('YYYY-MM-DD')) {
|
||||
programs.push({
|
||||
title: item.isltitill,
|
||||
sub_title: item.undirtitill,
|
||||
description: item.lysing,
|
||||
category: item.flokkur,
|
||||
season: item.seria,
|
||||
episode: item.thattur,
|
||||
actors: item.adalhlutverk,
|
||||
directors: item.leikstjori,
|
||||
start,
|
||||
stop: start.add(item.slott, 'm')
|
||||
})
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
return programs
|
||||
},
|
||||
return programs
|
||||
},
|
||||
async channels() {
|
||||
try {
|
||||
const response = await axios.get('https://www.syn.is/api/epg?type=schedule')
|
||||
|
||||
@@ -20,7 +20,7 @@ it('can generate valid url', () => {
|
||||
|
||||
it('can parse response', () => {
|
||||
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.json'))
|
||||
const result = parser({ content }).map(p => {
|
||||
const result = parser({ content, date }).map(p => {
|
||||
p.start = p.start.toISOString()
|
||||
p.stop = p.stop.toISOString()
|
||||
return p
|
||||
@@ -41,6 +41,6 @@ it('can parse response', () => {
|
||||
})
|
||||
|
||||
it('can handle empty guide', () => {
|
||||
const result = parser({ content: '[]' })
|
||||
const result = parser({ content: '[]', date })
|
||||
expect(result).toMatchObject([])
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user