From 5e8c8730a0e2c1a3b0bfbc0bf5f8e45a5bbe1ef7 Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Tue, 18 Jan 2022 20:09:26 +0300 Subject: [PATCH 1/3] Create frikanalen.no.config.js --- sites/frikanalen.no/frikanalen.no.config.js | 51 +++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 sites/frikanalen.no/frikanalen.no.config.js diff --git a/sites/frikanalen.no/frikanalen.no.config.js b/sites/frikanalen.no/frikanalen.no.config.js new file mode 100644 index 00000000..46961c64 --- /dev/null +++ b/sites/frikanalen.no/frikanalen.no.config.js @@ -0,0 +1,51 @@ +const dayjs = require('dayjs') + +module.exports = { + site: 'frikanalen.no', + url({ date }) { + return `https://frikanalen.no/api/scheduleitems/?date=${date.format( + 'YYYY-MM-DD' + )}&format=json&limit=100` + }, + parser({ content }) { + let programs = [] + const items = parseItems(content) + items.forEach(item => { + programs.push({ + title: parseTitle(item), + category: parseCategory(item), + description: parseDescription(item), + start: parseStart(item), + stop: parseStop(item) + }) + }) + + return programs + } +} + +function parseTitle(item) { + return item.video.name +} + +function parseCategory(item) { + return item.video.categories +} + +function parseDescription(item) { + return item.video.header +} + +function parseStart(item) { + return dayjs(item.starttime) +} + +function parseStop(item) { + return dayjs(item.endtime) +} + +function parseItems(content) { + const data = JSON.parse(content) + + return data && Array.isArray(data.results) ? data.results : [] +} From fea445f8b8325a2f9b4d40a1fcef69066df3b292 Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Tue, 18 Jan 2022 20:10:40 +0300 Subject: [PATCH 2/3] Create frikanalen.no.test.js --- sites/frikanalen.no/frikanalen.no.test.js | 48 +++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 sites/frikanalen.no/frikanalen.no.test.js diff --git a/sites/frikanalen.no/frikanalen.no.test.js b/sites/frikanalen.no/frikanalen.no.test.js new file mode 100644 index 00000000..bd93ddec --- /dev/null +++ b/sites/frikanalen.no/frikanalen.no.test.js @@ -0,0 +1,48 @@ +// npx epg-grabber --config=sites/frikanalen.no/frikanalen.no.config.js --channels=sites/frikanalen.no/frikanalen.no_no.channels.xml --output=guide.xml --days=2 + +const { parser, url } = require('./frikanalen.no.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-01-19', 'YYYY-MM-DD').startOf('d') +const channel = { + site_id: '#', + xmltv_id: 'Frikanalen.no' +} + +it('can generate valid url', () => { + expect(url({ date })).toBe( + 'https://frikanalen.no/api/scheduleitems/?date=2022-01-19&format=json&limit=100' + ) +}) + +it('can parse response', () => { + const content = `{"count":83,"next":null,"previous":null,"results":[{"id":135605,"video":{"id":626094,"name":"FSCONS 2017 - Keynote: TBA - Linda Sandvik","header":"Linda Sandvik's keynote at FSCONS 2017\\r\\n\\r\\nRecorded by NUUG for FSCONS.","description":null,"creator":"davidwnoble@gmail.com","organization":{"id":82,"name":"NUUG","homepage":"https://www.nuug.no/","description":"Forening NUUG er for alle som er interessert i fri programvare, åpne standarder og Unix-lignende operativsystemer.","postalAddress":"","streetAddress":"","editorId":2148,"editorName":"David Noble","editorEmail":"davidwnoble@gmail.com","editorMsisdn":"","fkmember":true},"duration":"00:57:55.640000","categories":["Samfunn"]},"schedulereason":5,"starttime":"2022-01-19T00:47:00+01:00","endtime":"2022-01-19T01:44:55.640000+01:00","duration":"00:57:55.640000"}]}` + const result = parser({ content }).map(p => { + p.start = p.start.toJSON() + p.stop = p.stop.toJSON() + return p + }) + + expect(result).toMatchObject([ + { + start: '2022-01-18T23:47:00.000Z', + stop: '2022-01-19T00:44:55.640Z', + title: `FSCONS 2017 - Keynote: TBA - Linda Sandvik`, + category: ['Samfunn'], + description: `Linda Sandvik's keynote at FSCONS 2017\r\n\r\nRecorded by NUUG for FSCONS.` + } + ]) +}) + +it('can handle empty guide', () => { + const result = parser({ + date, + channel, + content: `{"count":0,"next":null,"previous":null,"results":[]}` + }) + expect(result).toMatchObject([]) +}) From 68f322757b06fc22b072b70c6b53c10ef748aa56 Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Tue, 18 Jan 2022 20:10:50 +0300 Subject: [PATCH 3/3] Create frikanalen.no_no.channels.xml --- sites/frikanalen.no/frikanalen.no_no.channels.xml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 sites/frikanalen.no/frikanalen.no_no.channels.xml diff --git a/sites/frikanalen.no/frikanalen.no_no.channels.xml b/sites/frikanalen.no/frikanalen.no_no.channels.xml new file mode 100644 index 00000000..4cd7379b --- /dev/null +++ b/sites/frikanalen.no/frikanalen.no_no.channels.xml @@ -0,0 +1,6 @@ + + + + Frikanalen + + \ No newline at end of file