This commit is contained in:
theofficialomega
2026-02-23 01:50:03 +01:00
parent 4f22f306ba
commit 575000e0f3
2 changed files with 33 additions and 28 deletions

View File

@@ -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')

View File

@@ -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([])
})