diff --git a/sites/delta.nl/delta.nl.config.js b/sites/delta.nl/delta.nl.config.js index e3be8d1a..90cbfbf1 100644 --- a/sites/delta.nl/delta.nl.config.js +++ b/sites/delta.nl/delta.nl.config.js @@ -8,17 +8,19 @@ module.exports = { .add(1, 'd') .unix()}&includeDetails=true&channels=${channel.site_id}` }, - parser: function ({ content, channel }) { + async parser({ content, channel }) { let programs = [] const items = parseItems(content, channel) - items.forEach(item => { + for (let item of items) { + const details = await loadProgramDetails(item) programs.push({ title: item.title, icon: item.images.thumbnail.url, + description: details.description, start: parseStart(item).toJSON(), stop: parseStop(item).toJSON() }) - }) + } return programs }, @@ -40,6 +42,17 @@ module.exports = { } } +async function loadProgramDetails(item) { + if (!item.ID) return {} + const url = `https://clientapi.tv.delta.nl/guide/4/details/${item.ID}?X-Response-Version=4.5` + const data = await axios + .get(url) + .then(r => r.data) + .catch(console.log) + + return data || {} +} + function parseStart(item) { return dayjs.unix(item.start) } diff --git a/sites/delta.nl/delta.nl.test.js b/sites/delta.nl/delta.nl.test.js index cb7fa226..2f979ba1 100644 --- a/sites/delta.nl/delta.nl.test.js +++ b/sites/delta.nl/delta.nl.test.js @@ -1,13 +1,16 @@ -// node ./scripts/channels.js --config=./sites/delta.nl/delta.nl.config.js --output=./sites/delta.nl/delta.nl_nl.channels.xml -// npx epg-grabber --config=sites/delta.nl/delta.nl.config.js --channels=sites/delta.nl/delta.nl_nl.channels.xml --output=.gh-pages/guides/nl/delta.nl.epg.xml --days=2 +// npm run channels:parse --config=./sites/delta.nl/delta.nl.config.js --output=./sites/delta.nl/delta.nl_nl.channels.xml +// npx epg-grabber --config=sites/delta.nl/delta.nl.config.js --channels=sites/delta.nl/delta.nl_nl.channels.xml --output=guide.xml --days=2 const { parser, url, request } = require('./delta.nl.config.js') +const axios = require('axios') const dayjs = require('dayjs') const utc = require('dayjs/plugin/utc') const customParseFormat = require('dayjs/plugin/customParseFormat') dayjs.extend(customParseFormat) dayjs.extend(utc) +jest.mock('axios') + const date = dayjs.utc('2021-11-12', 'YYYY-MM-DD').startOf('d') const channel = { site_id: '1', @@ -20,25 +23,47 @@ it('can generate valid url', () => { ) }) -it('can parse response', () => { - const content = `{"1":[{"ID":"P~945cb98e-3d19-11ec-8456-953363d7a344","seriesID":"S~d37c4626-b691-11ea-ba69-255835135f02","channelID":"1","start":1636674960,"end":1636676520,"catchupAvailableUntil":1637279760,"title":"NOS Journaal","images":{"thumbnail":{"url":"https://cdn.gvidi.tv/img/booxmedia/e19c/static/NOS%20Journaal5.jpg"}},"additionalInformation":{"metadataID":"M~944f3c6e-3d19-11ec-9faf-2735f2e98d2a","externalMetadataID":"E~TV01-2026117420668"},"parentalGuidance":{"kijkwijzer":["AL"]},"restrictions":{"startoverDisabled":false,"catchupDisabled":false,"recordingDisabled":false},"isFiller":false}]}` - const result = parser({ date, channel, content }) +it('can parse response', done => { + axios.get.mockImplementation(() => + Promise.resolve({ + data: JSON.parse( + `{"ID":"P~945cb98e-3d19-11ec-8456-953363d7a344","seriesID":"S~d37c4626-b691-11ea-ba69-255835135f02","channelID":"1","start":1636674960,"end":1636676520,"catchupAvailableUntil":1637279760,"title":"Eigen Huis & Tuin: Lekker Leven","description":"Nederlands lifestyleprogramma uit 2022 (ook in HD) met dagelijkse inspiratie voor een lekker leven in en om het huis.\\nPresentatrice Froukje de Both, kok Hugo Kennis en een team van experts, onder wie tuinman Tom Groot, geven praktische tips op het gebied van wonen, lifestyle, tuinieren en koken. Daarmee kun je zelf direct aan de slag om je leven leuker én gezonder te maken. Afl. 15 van seizoen 4.","images":{"thumbnail":{"url":"https://cdn.gvidi.tv/img/booxmedia/b291/561946.jpg"}},"additionalInformation":{"metadataID":"M~c512c206-95e5-11ec-87d8-494f70130311","externalMetadataID":"E~RTL4-89d99356_6599_4b65_a7a0_a93f39019645"},"parentalGuidance":{"kijkwijzer":["AL"]},"restrictions":{"startoverDisabled":false,"catchupDisabled":false,"recordingDisabled":false},"isFiller":false}` + ) + }) + ) - expect(result).toMatchObject([ - { - start: '2021-11-11T23:56:00.000Z', - stop: '2021-11-12T00:22:00.000Z', - title: 'NOS Journaal', - icon: 'https://cdn.gvidi.tv/img/booxmedia/e19c/static/NOS%20Journaal5.jpg' - } - ]) + const content = `{"1":[{"ID":"P~945cb98e-3d19-11ec-8456-953363d7a344","seriesID":"S~d37c4626-b691-11ea-ba69-255835135f02","channelID":"1","start":1636674960,"end":1636676520,"catchupAvailableUntil":1637279760,"title":"NOS Journaal","images":{"thumbnail":{"url":"https://cdn.gvidi.tv/img/booxmedia/e19c/static/NOS%20Journaal5.jpg"}},"additionalInformation":{"metadataID":"M~944f3c6e-3d19-11ec-9faf-2735f2e98d2a","externalMetadataID":"E~TV01-2026117420668"},"parentalGuidance":{"kijkwijzer":["AL"]},"restrictions":{"startoverDisabled":false,"catchupDisabled":false,"recordingDisabled":false},"isFiller":false}]}` + + parser({ date, channel, content }) + .then(result => { + expect(result).toMatchObject([ + { + start: '2021-11-11T23:56:00.000Z', + stop: '2021-11-12T00:22:00.000Z', + title: 'NOS Journaal', + description: + 'Nederlands lifestyleprogramma uit 2022 (ook in HD) met dagelijkse inspiratie voor een lekker leven in en om het huis.\nPresentatrice Froukje de Both, kok Hugo Kennis en een team van experts, onder wie tuinman Tom Groot, geven praktische tips op het gebied van wonen, lifestyle, tuinieren en koken. Daarmee kun je zelf direct aan de slag om je leven leuker én gezonder te maken. Afl. 15 van seizoen 4.', + icon: 'https://cdn.gvidi.tv/img/booxmedia/e19c/static/NOS%20Journaal5.jpg' + } + ]) + done() + }) + .catch(error => { + done(error) + }) }) -it('can handle empty guide', () => { - const result = parser({ +it('can handle empty guide', done => { + parser({ date, channel, content: `{"code":500,"message":"Error retrieving guide"}` }) - expect(result).toMatchObject([]) + .then(result => { + expect(result).toMatchObject([]) + done() + }) + .catch(error => { + done(error) + }) }) diff --git a/sites/delta.nl/delta.nl_nl.channels.xml b/sites/delta.nl/delta.nl_nl.channels.xml index e175fd07..a3f7745a 100644 --- a/sites/delta.nl/delta.nl_nl.channels.xml +++ b/sites/delta.nl/delta.nl_nl.channels.xml @@ -1,10 +1,10 @@ - 3sat - 24 Kitchen Nederland 100% NL TV 192 TV + 24 Kitchen Nederland + 3sat AAVISIE Albrandswaard TV Aljazeera English @@ -69,8 +69,8 @@ FilmBox Nederland Fox NL France 2 - France 3 France 24 Français + France 3 Gemeente Westland TV GL8 GO-TV @@ -82,7 +82,7 @@ Hustler TV Europe Ideaal TV Ijsselmond TV - Insight HD + Insight TV Investigation Discovery Europe JenZ Kabel Eins Deutschland @@ -166,6 +166,7 @@ RTV Arnhem TV RTV Focus TV RTV Horizon + RTV Oost RTV Purmerend RTV Rijnstreek TV RTV Scheldemond @@ -199,8 +200,8 @@ Trace Sport Stars Trace Urban TRT Türk - TV5Monde Europe TV 538 + TV5Monde Europe TV Berghem TV Drenthe TVE Internacional Europa @@ -208,7 +209,6 @@ TV Krimpenerwaard TV Noord TV Nunspeet - TV Oost TV Oranje TV Rijnmond TV Stichtse Vecht