From c73054f785168bd33e642a16ca110a4f16ee0aed Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Sat, 5 Mar 2022 19:45:16 +0300 Subject: [PATCH 1/4] Create tv.nu.test.js --- sites/tv.nu/tv.nu.test.js | 48 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 sites/tv.nu/tv.nu.test.js diff --git a/sites/tv.nu/tv.nu.test.js b/sites/tv.nu/tv.nu.test.js new file mode 100644 index 00000000..322ea8fd --- /dev/null +++ b/sites/tv.nu/tv.nu.test.js @@ -0,0 +1,48 @@ +// npx epg-grabber --config=sites/tv.nu/tv.nu.config.js --channels=sites/tv.nu/tv.nu_se.channels.xml --output=guide.xml --days=2 + +const { parser, url } = require('./tv.nu.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-03-06', 'YYYY-MM-DD').startOf('d') +const channel = { + site_id: '3sat', + xmltv_id: '3sat.de' +} + +it('can generate valid url', () => { + expect(url({ channel, date })).toBe( + 'https://web-api.tv.nu/channels/3sat/schedule?date=2022-03-06&fullDay=true' + ) +}) + +it('can parse response', () => { + const content = `{"data":{"broadcasts":[{"type":"broadcast","id":"1NqJwy-2l-8enC","slug":"vielfaltige-vogelwelt-osterreich","programId":"174565","isPlay":false,"isMovie":false,"isSeries":false,"isLive":false,"title":"Vielfältige Vogelwelt Österreich","description":"In Österreich sind mehr als 400 Vogelarten nachgewiesen und manche von ihnen fallen durch optische Eigenheiten ganz besonders auf. Diese Dokumentation befasst sich mit dem Bienenfresser, dem Fichtenkreuzschnäbel und dem Stelzenläufer.","imagePortrait":"https://new.static.tv.nu/86184349","imageLandscape":"https://new.static.tv.nu/86184347","genres":["Natur","Special"],"playProviders":[],"broadcast":{"id":"1NqJwy-2l-8enC","startTime":1646542800000,"endTime":1646543700000,"channel":{"name":"3sat","slug":"3sat","themedLogo":{"light":{"url":"https://new.static.tv.nu/19402383","isFallback":false},"dark":{"url":"https://new.static.tv.nu/59995595","isFallback":true}}}}}]}}` + const result = parser({ content }).map(p => { + p.start = p.start.toJSON() + p.stop = p.stop.toJSON() + return p + }) + + expect(result).toMatchObject([ + { + start: '2022-03-06T05:00:00.000Z', + stop: '2022-03-06T05:15:00.000Z', + title: 'Vielfältige Vogelwelt Österreich', + description: + 'In Österreich sind mehr als 400 Vogelarten nachgewiesen und manche von ihnen fallen durch optische Eigenheiten ganz besonders auf. Diese Dokumentation befasst sich mit dem Bienenfresser, dem Fichtenkreuzschnäbel und dem Stelzenläufer.', + icon: 'https://new.static.tv.nu/86184347', + category: ['Natur', 'Special'] + } + ]) +}) + +it('can handle empty guide', () => { + const result = parser({ + content: `{"meta":{"status":200},"data":{"broadcasts":[]}}` + }) + expect(result).toMatchObject([]) +}) From a1c170072e9dec235dd23995c75f079573ccbfad Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Sat, 5 Mar 2022 19:45:20 +0300 Subject: [PATCH 2/4] Create tv.nu.config.js --- sites/tv.nu/tv.nu.config.js | 45 +++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 sites/tv.nu/tv.nu.config.js diff --git a/sites/tv.nu/tv.nu.config.js b/sites/tv.nu/tv.nu.config.js new file mode 100644 index 00000000..098d6c59 --- /dev/null +++ b/sites/tv.nu/tv.nu.config.js @@ -0,0 +1,45 @@ +const dayjs = require('dayjs') + +module.exports = { + site: 'tv.nu', + url: function ({ channel, date }) { + return `https://web-api.tv.nu/channels/${channel.site_id}/schedule?date=${date.format( + 'YYYY-MM-DD' + )}&fullDay=true` + }, + parser: function ({ content }) { + let programs = [] + const items = parseItems(content) + items.forEach(item => { + programs.push({ + title: item.title, + description: item.description, + icon: item.imageLandscape, + category: item.genres, + start: parseStart(item), + stop: parseStop(item) + }) + }) + + return programs + } +} + +function parseStart(item) { + if (!item.broadcast || !item.broadcast.startTime) return null + + return dayjs(item.broadcast.startTime) +} + +function parseStop(item) { + if (!item.broadcast || !item.broadcast.endTime) return null + + return dayjs(item.broadcast.endTime) +} + +function parseItems(content) { + const data = JSON.parse(content) + if (!data || !data.data || !Array.isArray(data.data.broadcasts)) return [] + + return data.data.broadcasts +} From 92246b1050bf3c3ee2f387edf54dcc0b3aa4a2ed Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Sat, 5 Mar 2022 19:45:26 +0300 Subject: [PATCH 3/4] Create tv.nu_se.channels.xml --- sites/tv.nu/tv.nu_se.channels.xml | 156 ++++++++++++++++++++++++++++++ 1 file changed, 156 insertions(+) create mode 100644 sites/tv.nu/tv.nu_se.channels.xml diff --git a/sites/tv.nu/tv.nu_se.channels.xml b/sites/tv.nu/tv.nu_se.channels.xml new file mode 100644 index 00000000..286bf4f3 --- /dev/null +++ b/sites/tv.nu/tv.nu_se.channels.xml @@ -0,0 +1,156 @@ + + + + 3sat + Al Jazeera English + Animal Planet + ARTE + ATG Live + BBC Brit + BBC Earth + BBC World News + Bloomberg TV HD + Boomerang + BraZZers TV Plus + Cartoon Network + CBS Reality + Club MTV + C More First + C More Fotboll + C More Mix + C More Hits + C More Hockey + C More Live + C More Live 2 + C More Live 3 + C More Live 4 + C More Live 5 + C More Series + C More Stars + CNBC + CNN + Das Erste + Discovery Channel + Discovery Science + Disney Channel + Disney Junior + DMAX + DR1 + DR2 + DR Ramasjang + DW + E! + eSportsone + Euro News + Eurosport 1 + Eurosport 2 + Expressen TV + Extreme Sports Channel + FTV + Fight Sports + France 2 + France 24 English HD + FULE TV + GINX eSports TV + Godare + GOD TV + H2 + History HD + History HD (Internationell) + Horse & Country TV + HRT1 + Hustler TV + Investigation Discovery + Kanal 10 + Kanal 11 + Kanal 5 Danmark + Kanal 5 + Kanal 9 + Kunskapskanalen + Mezzo + Mezzo Live HD + Motorvision TV + MTV3 + MTV Hits + MTV Live HD + MTV + National Geographic + National Geographic + Nautical Channel + Nelonen + NFL Network + NHK World Europe + Nickelodeon + Nick JR + Nicktoons + NRK1 + NRK2 + NRK3 + Outdoor Channel HD + OUTtv + Paramount Network + Pink Plus + Playboy TV Europe + ProSieben + Rai 1 + Rai 2 + RTL + RTLZWEI + SF Kanalen + Sjuan + Sky News + Sportkanalen + Stingray Classica + Djazz HD + STRIVE Sport TV + Super RTL + SVT1 + SVT2 + SVT24 + SVT Barn + TLC + Trace Urban HD + Travel Channel + TV10 + TV12 + TV2 + TV3 Danmark + TV3 Norge + 3 Plus Danmark + TV3 + TV4 + TV4 Fakta + TV4 Film + TV4 Guld + TV5 Monde Europe + TV6 + TV8 + TV Chile Internacional + TVE Internacional + TV Polonia + V Film Action + V Film Family + V Film Hits + V Film Premiere + VH1 + Viasat Explore + Viasat History + Viasat Nature + Viasat Sport HD + VOX + V Series + V Sport 1 + V Sport Extra + V Sport Fotball + V Sport Golf + V Sport Hockey + V Sport Motor + V Sport Premium + V Sport Ultra HD + WILD TV HD + Yle TV1 + Yle TV2 + Yle Teema & Fem + ZDF + + From c8a2717727e947c9259ab3f3f795129a6167f466 Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Sat, 5 Mar 2022 19:45:29 +0300 Subject: [PATCH 4/4] Create tv.nu.yml --- .github/workflows/tv.nu.yml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 .github/workflows/tv.nu.yml diff --git a/.github/workflows/tv.nu.yml b/.github/workflows/tv.nu.yml new file mode 100644 index 00000000..dcfff814 --- /dev/null +++ b/.github/workflows/tv.nu.yml @@ -0,0 +1,17 @@ +name: tv.nu +on: + schedule: + - cron: '0 0 * * *' + workflow_dispatch: + workflow_run: + workflows: [_trigger] + types: + - completed +jobs: + load: + uses: ./.github/workflows/_load.yml + with: + site: ${{github.workflow}} + secrets: + APP_ID: ${{ secrets.APP_ID }} + APP_PRIVATE_KEY: ${{ secrets.APP_PRIVATE_KEY }}