From a44d27ea30d8ca3f752fbfb530782023fcdc0684 Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Tue, 4 Oct 2022 16:26:48 +0300 Subject: [PATCH 1/2] Create tvguide.com.test.js --- sites/tvguide.com/tvguide.com.test.js | 47 +++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 sites/tvguide.com/tvguide.com.test.js diff --git a/sites/tvguide.com/tvguide.com.test.js b/sites/tvguide.com/tvguide.com.test.js new file mode 100644 index 00000000..cfd2ee87 --- /dev/null +++ b/sites/tvguide.com/tvguide.com.test.js @@ -0,0 +1,47 @@ +// npx epg-grabber --config=sites/tvguide.com/tvguide.com.config.js --channels=sites/tvguide.com/tvguide.com_us.channels.xml --output=guide.xml --days=2 + +const { parser, url } = require('./tvguide.com.config.js') +const dayjs = require('dayjs') +const utc = require('dayjs/plugin/utc') +const customParseFormat = require('dayjs/plugin/customParseFormat') +dayjs.extend(customParseFormat) +dayjs.extend(utc) + +const date = dayjs.utc('2022-10-04', 'YYYY-MM-DD').startOf('d') +const channel = { + site_id: '9100001138#9233011874', + xmltv_id: 'ABCEast.us' +} + +it('can generate valid url', () => { + expect(url({ date, channel })).toBe( + 'https://cmg-prod.apigee.net/v1/xapi/tvschedules/tvguide/9100001138/web?start=1664841600&duration=1439&channelSourceIds=9233011874' + ) +}) + +it('can parse response', () => { + const content = `{"data":{"duration":"1439","providerId":"9100001138","startTime":"1664841600","items":[{"channel":{"fullName":"ABC","name":"ABC","number":null,"sourceId":9233011874,"legacySourceId":5942,"networkName":"ABC","networkId":2,"logo":"/provider/1/4/1-4124037679.png"},"programSchedules":[{"airingAttrib":533524,"catId":5,"startTime":1664841600,"endTime":1664848800,"programId":6033556709,"title":"Bachelor in Paradise","rating":"TV-14","programDetails":"https://cmg-prod.apigee.net/v1/xapi/tvschedules/tvguide/programdetails/6033556709/web"}]}]}}` + + const result = parser({ date, channel, content }).map(p => { + p.start = p.start.toJSON() + p.stop = p.stop.toJSON() + return p + }) + + expect(result).toMatchObject([ + { + start: '2022-10-04T00:00:00.000Z', + stop: '2022-10-04T02:00:00.000Z', + title: 'Bachelor in Paradise' + } + ]) +}) + +it('can handle empty guide', () => { + const result = parser({ + date, + channel, + content: `{"data":{"duration":"1439","providerId":"9100001138","startTime":"1664841600","items":[]},"links":{"self":{"href":"https://cmg-prod.apigee.net/v1/xapi/tvschedules/tvguide/9100001138/web?start=1664841600&duration=1439&channelSourceIds=923301187"},"prev":{"href":null},"next":{"href":"https://cmg-prod.apigee.net/v1/xapi/tvschedules/tvguide/9100001138/web?start=1664841600&duration=1439&channelSourceIds=923301187&offset=1664843039&limit=1664841600"}},"meta":{"componentName":null,"componentDisplayName":null,"componentType":null}}` + }) + expect(result).toMatchObject([]) +}) From 3a9ae1dbae5da880ce880718e4acc35018fddc8d Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Tue, 4 Oct 2022 16:26:51 +0300 Subject: [PATCH 2/2] Update tvguide.com.config.js --- sites/tvguide.com/tvguide.com.config.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sites/tvguide.com/tvguide.com.config.js b/sites/tvguide.com/tvguide.com.config.js index 9bc9c563..14f72092 100644 --- a/sites/tvguide.com/tvguide.com.config.js +++ b/sites/tvguide.com/tvguide.com.config.js @@ -37,7 +37,8 @@ function parseTime(timestamp) { } function parseItems(content) { - const json = JSON.parse(content) + const data = JSON.parse(content) + if (!Array.isArray(data.data.items) || !data.data.items.length) return [] - return json.data.items[0].programSchedules + return data.data.items[0].programSchedules }