diff --git a/scripts/channels.js b/scripts/channels.js index 13147826..53e2de4a 100644 --- a/scripts/channels.js +++ b/scripts/channels.js @@ -17,6 +17,12 @@ async function main() { if (isPromise(channels)) { channels = await channels } + channels = channels.map(channel => { + if (!channel.xmltv_id) { + channel.xmltv_id = channel.name + } + return channel + }) const xml = json2xml(channels, config.site) const dir = path.parse(options.config).dir diff --git a/scripts/utils.js b/scripts/utils.js index 1e934b24..52fcf4e0 100644 --- a/scripts/utils.js +++ b/scripts/utils.js @@ -6,9 +6,9 @@ function json2xml(items, site) { const xmltv_id = channel.xmltv_id || '' const lang = channel.lang || '' const site_id = channel.site_id || '' - output += ` ${escapeString( - channel.name - )}\r\n` + output += ` ${escapeString(channel.name)}\r\n` }) output += ` \r\n\r\n` diff --git a/sites/delta.nl/delta.nl.config.js b/sites/delta.nl/delta.nl.config.js new file mode 100644 index 00000000..b08ac61a --- /dev/null +++ b/sites/delta.nl/delta.nl.config.js @@ -0,0 +1,60 @@ +const axios = require('axios') +const dayjs = require('dayjs') + +module.exports = { + site: 'delta.nl', + url: function ({ channel, date }) { + return `https://clientapi.tv.delta.nl/guide/channels/list?start=${date.unix()}&end=${date + .add(1, 'd') + .unix()}&includeDetails=true&channels=${channel.site_id}` + }, + logo({ channel }) { + return channel.logo + }, + parser: function ({ content, channel }) { + let programs = [] + const items = parseItems(content, channel) + items.forEach(item => { + programs.push({ + title: item.title, + icon: item.images.thumbnail.url, + start: parseStart(item).toJSON(), + stop: parseStop(item).toJSON() + }) + }) + + return programs + }, + async channels() { + const items = await axios + .get('https://clientapi.tv.delta.nl/channels/list') + .then(r => r.data) + .catch(console.log) + + return items + .filter(i => i.type === 'TV') + .map(item => { + return { + lang: 'nl', + site_id: item['ID'], + name: item.name, + logo: item.images.logo + } + }) + } +} + +function parseStart(item) { + return dayjs.unix(item.start) +} + +function parseStop(item) { + return dayjs.unix(item.end) +} + +function parseItems(content, channel) { + const data = JSON.parse(content) + if (!data) return [] + + return data[channel.site_id] || [] +} diff --git a/sites/delta.nl/delta.nl.test.js b/sites/delta.nl/delta.nl.test.js new file mode 100644 index 00000000..44d2087c --- /dev/null +++ b/sites/delta.nl/delta.nl.test.js @@ -0,0 +1,51 @@ +// 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 + +const { parser, url, request, logo } = require('./delta.nl.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('2021-11-12', 'YYYY-MM-DD').startOf('d') +const channel = { + site_id: '1', + xmltv_id: 'NPO1.nl', + logo: 'https://tv.delta.nl/assets/graphics/thumbnails/channel/delta/npo1.svg' +} + +it('can generate valid url', () => { + expect(url({ channel, date })).toBe( + 'https://clientapi.tv.delta.nl/guide/channels/list?start=1636675200&end=1636761600&includeDetails=true&channels=1' + ) +}) + +it('can get logo url', () => { + expect(logo({ channel })).toBe( + 'https://tv.delta.nl/assets/graphics/thumbnails/channel/delta/npo1.svg' + ) +}) + +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 }) + + 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' + } + ]) +}) + +it('can handle empty guide', () => { + const result = parser({ + date, + channel, + content: `{"code":500,"message":"Error retrieving guide"}` + }) + expect(result).toMatchObject([]) +}) diff --git a/sites/delta.nl/delta.nl_nl.channels.xml b/sites/delta.nl/delta.nl_nl.channels.xml new file mode 100644 index 00000000..31723417 --- /dev/null +++ b/sites/delta.nl/delta.nl_nl.channels.xml @@ -0,0 +1,232 @@ + + + + 3sat + 24 Kitchen Nederland + 100% NL TV + 192 TV + AAVISIE + Albrandswaard TV + Aljazeera English + Altena TV + Animal Planet Europe + ARTE Deutsch + Assen TV + AT5 + ATOS TV + Babes TV + Baby TV Europe + BBC Entertainment Europe + BBC First Nederland + BBC Four + BBC One + BBC Two + BBC World News Europe + Beek TV + Bloomberg TV Europe + Boomerang Central & Eastern Europe + BR6 TV + Brazzers TV Europe + BredaNu TV + Canvas + Cartoon Network Nederland + Castricum TV + CBeebies UK + Centraal TV + CGTN + CNN International Europe + Comedy Central Extra UK + Comedy Central Nederland + Crime + Investigation UK + Das Erste + Delta TV + Den Haag TV + Discovery Channel Nederland + Discovery Science + Disney Channel Nederland + Disney XD Nederland + DRTV + DTV Oss & Bernheze + Dusk + Één + E! Europe + ESPN 2 Nederland + ESPN 3 Nederland + ESPN 4 Nederland + ESPN Nederland + EuroNews English + Eurosport 1 + Eurosport 2 + Extreme Sports Channel + Family 7 + FashionTV Europe + Favoriet TV + Feel Good TV + Film 1 Action + Film 1 Drama + Film 1 Family + Film 1 Premiere + FilmBox Nederland + Fox NL + France 2 + France 3 + France 24 Français + Gemeente Westland TV + GL8 + GO-TV + Gouwestad TV + History Benelux + Hofstreek TV + HOi TV + Horse & Country TV + Hustler TV Europe + Ideaal TV + Ijsselmond TV + Insight HD + Investigation Discovery Europe + JenZ + Kabel Eins Deutschland + Ketnet + KIKA + Kontakt TV + L1 TV + Lansingerland TV + Loco TV + LOE TV + LOK TV + LON TV + LOS TV + Meiden van Holland Hard + Meppel TV + Mezzo + ML5 TV + MLA TV + MTV 00s + MTV 80s + MTV Hits Europe + MTV Live HD + MTV NL + National Geographic Nederland + National Geographic Wild Europe + Nautical Channel + NDR Fernsehen Hamburg + Net 5 + NHK World Japan + NH TV + Nickelodeon Nederland & België + Nick Jr Central & Eastern Europe + NickMusic + NickToons UK + NOOS TV + NPO 1 + NPO 1 Extra + NPO 2 + NPO 2 Extra + NPO 3 + NPO Nieuws + NPO Politiek + NPO Zappelin Extra + N-TV + Omroep Brabant TV + Omroep Flevoland TV + Omroep Hulst TV + Omroep Meierijstad TV + Omroep Tilburg TV + Omroep Venlo TV + Omroep Zeeland TV + Omrop Fryslân TV + ONS + Ons West Brabant TV + OPEN Rotterdam TV + Out TV + Passion XXX + Pebble TV + Phoenix CNE + Playboy TV Europe + P&M TV + ProSieben Deutschland + Pure Babes + Radio Aalsmeer TV + Rai 1 + Regio8 TV + Regio90 TV + RN7 + Ronde Venen TV + RTBF La Une + RTL 4 + RTL 5 + RTL 7 + RTL 8 + RTL Crime Nederland + RTL Deutschland + RTL Lounge + RTL Telekids + RTL Z + RTV 1 + RTV Arnhem TV + RTV Focus TV + RTV Horizon + RTV Purmerend + RTV Rijnstreek TV + RTV Scheldemond + RTV Slingeland + RTV SLOS + RTV Utrecht + RTV Veluwezoom TV + Samen1 TV + Sat. 1 Deutschland + SBS 6 + SBS 9 + Schie TV + Schlager TV + Shorts TV + Siris TV + Slam! + SLOGO TV + SLOS TV + Slotstad TV + Spike Nederland + Stingray Classica + Stingray Djazz + Stingray IConcerts + Stingray Lite TV + StreekTV + Studio Alphen TV + SWR Fernsehen Baden-Württemberg + Tholen TV + Tipik + TLC Nederland + Trace Sport Stars + Trace Urban + TRT Türk + TV5Monde Europe + TV 538 + TV Berghem + TV Drenthe + TVE Internacional Europa + TV Gelderland + TV Krimpenerwaard + TV Noord + TV Nunspeet + TV Oost + TV Oranje + TV Rijnmond + TV Stichtse Vecht + TV West + Twente TV + Vechtdal TV + Veronica + Vox Deutschland + WDR Fernsehen Köln + WOS + ZDF + Ziggo Sport Docu + Ziggo Sport Golf + Ziggo Sport Racing + Ziggo Sport Select + Ziggo Sport Tennis + Ziggo Sport Voetbal + ZuidWest TV + ZVT-AVS + + \ No newline at end of file