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,7 +15,7 @@ module.exports = {
url({ channel, date }) { url({ channel, date }) {
return `https://www.syn.is/api/epg/${channel.site_id}/${date.format('YYYY-MM-DD')}` return `https://www.syn.is/api/epg/${channel.site_id}/${date.format('YYYY-MM-DD')}`
}, },
parser: function ({ content }) { parser: function ({ content, date }) {
let data let data
try { try {
data = JSON.parse(content) data = JSON.parse(content)
@@ -24,25 +24,30 @@ module.exports = {
return [] return []
} }
if (!Array.isArray(data)) return []
const programs = [] const programs = []
if (data && Array.isArray(data)) { data
data.forEach(item => { .filter(item => item?.upphaf)
if (!item) return .forEach(item => {
const start = dayjs.utc(item.upphaf) const start = dayjs.utc(item.upphaf)
const stop = start.add(item.slott, 'm')
if (start.format('YYYY-MM-DD') === date.format('YYYY-MM-DD')) {
programs.push({ programs.push({
title: item.isltitill, title: item.isltitill,
sub_title: item.undirtitill, sub_title: item.undirtitill,
description: item.lysing, description: item.lysing,
category: item.flokkur,
season: item.seria,
episode: item.thattur,
actors: item.adalhlutverk, actors: item.adalhlutverk,
directors: item.leikstjori, directors: item.leikstjori,
start, start,
stop stop: start.add(item.slott, 'm')
})
}) })
} }
})
return programs return programs
}, },

View File

@@ -20,7 +20,7 @@ it('can generate valid url', () => {
it('can parse response', () => { it('can parse response', () => {
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.json')) 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.start = p.start.toISOString()
p.stop = p.stop.toISOString() p.stop = p.stop.toISOString()
return p return p
@@ -41,6 +41,6 @@ it('can parse response', () => {
}) })
it('can handle empty guide', () => { it('can handle empty guide', () => {
const result = parser({ content: '[]' }) const result = parser({ content: '[]', date })
expect(result).toMatchObject([]) expect(result).toMatchObject([])
}) })