Update config / test

This commit is contained in:
RevGear 2022-12-22 17:34:12 +00:00
parent f126cd812d
commit c365d97cde
2 changed files with 18 additions and 11 deletions

View file

@ -29,8 +29,9 @@ module.exports = {
season: parseSeason(item),
episode: parseEpisode(item),
rating: parseRating(item),
start: dayjs.utc(item.start_time),
stop: dayjs.utc(item.end_time)
icon: parseIcon(item),
start: parseTime(item.start_time),
stop: parseTime(item.end_time)
})
})
@ -39,12 +40,16 @@ module.exports = {
}
function parseItems(content, channel) {
const data = JSON.parse(content)
if (!data) return []
if (!Array.isArray(data.schedule)) return []
try {
const data = JSON.parse(content)
if (!data) return []
if (!Array.isArray(data.schedule)) return []
const channelData = data.schedule.filter(i => i.channel == channel.site_id)
return channelData.listing && Array.isArray(channelData.listing) ? channelData.listing : []
const channelData = data.schedule.find(i => i.channel == channel.site_id)
return channelData.listing && Array.isArray(channelData.listing) ? channelData.listing : []
} catch (err) {
return []
}
}
function parseSeason(item) {
@ -56,7 +61,7 @@ function parseEpisode(item) {
function parseTime(time) {
return dayjs.tz(time, 'YYYY-MM-DD HH:mm', 'Australia/Sydney')
}
function parseIcon(tem) {
function parseIcon(item) {
return item.image_file ? `https://www.abc.net.au/tv/common/images/publicity/${item.image_file}` : null
}
function parseRating(item) {

View file

@ -12,7 +12,7 @@ const channel = {
}
it('can generate valid url', () => {
expect(url({ date })).toBe(
'https://epg.abctv.net.au/processed/Sydney_2022-12-22.json
'https://epg.abctv.net.au/processed/Sydney_2022-12-22.json'
)
})
@ -30,8 +30,10 @@ it('can parse response', () => {
title: 'Silent Witness',
sub_title: 'Lift Up Your Hearts (part Two)',
description: `When tragedy strikes close to home, it puts head teacher Noah Taylor on a collision course with the criminals responsible. Can the Lyell team help him stop the cycle of violence?`,
category: 'Entertainment',
rating: 'M',
category: ['Entertainment'],
rating: {
system: 'ACB',
value: 'M'},
season: 22,
episode: 4,
icon: 'https://www.abc.net.au/tv/common/images/publicity/ZW2178A004S00_460.jpg',