diff --git a/.github/workflows/horizon.tv.yml b/.github/workflows/horizon.tv.yml new file mode 100644 index 00000000..b4e46d4d --- /dev/null +++ b/.github/workflows/horizon.tv.yml @@ -0,0 +1,17 @@ +name: horizon.tv +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 }} diff --git a/sites/horizon.tv/horizon.tv.config.js b/sites/horizon.tv/horizon.tv.config.js new file mode 100644 index 00000000..de72115c --- /dev/null +++ b/sites/horizon.tv/horizon.tv.config.js @@ -0,0 +1,70 @@ +const axios = require('axios') +const dayjs = require('dayjs') + +const API_ENDPOINT = `https://legacy-static.oesp.horizon.tv/oesp/v4/DE/deu/web/programschedules` + +module.exports = { + site: 'horizon.tv', + url: function ({ date }) { + return `${API_ENDPOINT}/${date.format('YYYYMMDD')}/1` + }, + async parser({ content, channel, date }) { + let programs = [] + let items = parseItems(content, channel) + if (!items.length) return programs + const d = date.format('YYYYMMDD') + const promises = [ + axios.get(`${API_ENDPOINT}/${d}/2`), + axios.get(`${API_ENDPOINT}/${d}/3`), + axios.get(`${API_ENDPOINT}/${d}/4`) + ] + await Promise.allSettled(promises) + .then(results => { + results.forEach(r => { + if (r.status === 'fulfilled') { + items = items.concat(parseItems(r.value.data, channel)) + } + }) + }) + .catch(console.error) + items.forEach(item => { + programs.push({ + title: item.t, + start: parseStart(item), + stop: parseStop(item) + }) + }) + + return programs + }, + async channels() { + const data = await axios + .get(`https://legacy-dynamic.oesp.horizon.tv/oesp/v4/DE/deu/web/channels`) + .then(r => r.data) + .catch(console.log) + + return data.channels.map(item => { + return { + lang: 'de', + site_id: item.id.replace('lgi-obolite-de-prod-master:65535-', ''), + name: item.title + } + }) + } +} + +function parseStart(item) { + return dayjs(item.s) +} + +function parseStop(item) { + return dayjs(item.e) +} + +function parseItems(content, channel) { + const data = typeof content === 'string' ? JSON.parse(content) : content + if (!data || !Array.isArray(data.entries)) return [] + const entity = data.entries.find(e => e.o === `lgi-obolite-de-prod-master:${channel.site_id}`) + + return entity ? entity.l : [] +} diff --git a/sites/horizon.tv/horizon.tv.test.js b/sites/horizon.tv/horizon.tv.test.js new file mode 100644 index 00000000..9edc73cd --- /dev/null +++ b/sites/horizon.tv/horizon.tv.test.js @@ -0,0 +1,105 @@ +// npm run channels:parse -- --config=./sites/horizon.tv/horizon.tv.config.js --output=./sites/horizon.tv/horizon.tv_de.channels.xml +// npx epg-grabber --config=sites/horizon.tv/horizon.tv.config.js --channels=sites/horizon.tv/horizon.tv_de.channels.xml --output=guide.xml --days=2 + +const { parser, url } = require('./horizon.tv.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('2022-03-09', 'YYYY-MM-DD').startOf('d') +const channel = { + site_id: '123_tv', + xmltv_id: '123TV.de' +} + +it('can generate valid url', () => { + expect(url({ date })).toBe( + 'https://legacy-static.oesp.horizon.tv/oesp/v4/DE/deu/web/programschedules/20220309/1' + ) +}) + +it('can parse response', done => { + const content = `{"entries":[{"o":"lgi-obolite-de-prod-master:123_tv","l":[{"i":"crid:~~2F~~2Fmedia-press.tv~~2F265057185,imi:b6915913733f74d3d92ebdba58340d133fd5632b","t":"DuftGeheimnis","s":1646776800000,"e":1646780400000,"c":"lgi-obolite-de-prod-master:genre-18","a":false,"r":false,"rm":false,"ad":[],"sl":[]}]}]}` + + axios.get.mockImplementation(url => { + if ( + url === 'https://legacy-static.oesp.horizon.tv/oesp/v4/DE/deu/web/programschedules/20220309/2' + ) { + return Promise.resolve({ + data: JSON.parse( + `{"entries":[{"o":"lgi-obolite-de-prod-master:123_tv","l":[{"i":"crid:~~2F~~2Fmedia-press.tv~~2F263411037,imi:152c4e326ba8e52f91d10b28e4fd8544ff9cbade","t":"1-2-3.tv Morning-Deals","s":1646798400000,"e":1646802000000,"c":"lgi-obolite-de-prod-master:genre-18","a":false,"r":false,"rm":false,"ad":[],"sl":[]}]}]}` + ) + }) + } else if ( + url === 'https://legacy-static.oesp.horizon.tv/oesp/v4/DE/deu/web/programschedules/20220309/3' + ) { + return Promise.resolve({ + data: JSON.parse( + `{"entries":[{"o":"lgi-obolite-de-prod-master:123_tv","l":[{"i":"crid:~~2F~~2Fmedia-press.tv~~2F265166355,imi:2c61f3f21d3599e7b1f1aacdec066389688296a6","t":"Confiserie","s":1646820000000,"e":1646823600000,"c":"lgi-obolite-de-prod-master:genre-18","a":false,"r":false,"rm":false,"ad":[],"sl":[]}]}]}` + ) + }) + } else if ( + url === 'https://legacy-static.oesp.horizon.tv/oesp/v4/DE/deu/web/programschedules/20220309/4' + ) { + return Promise.resolve({ + data: JSON.parse( + `{"entries":[{"o":"lgi-obolite-de-prod-master:123_tv","l":[{"i":"crid:~~2F~~2Fmedia-press.tv~~2F265166350,imi:d8e2a799e061e6390f49bcf4f12df65f2c761bb6","t":"Sneaker World","s":1646841600000,"e":1646845200000,"c":"lgi-obolite-de-prod-master:genre-18","a":false,"r":false,"rm":false,"ad":[],"sl":[]}]}]}` + ) + }) + } else { + return Promise.resolve({ data: '' }) + } + }) + + parser({ content, channel, date }) + .then(result => { + result = result.map(p => { + p.start = p.start.toJSON() + p.stop = p.stop.toJSON() + return p + }) + + expect(result).toMatchObject([ + { + start: '2022-03-08T22:00:00.000Z', + stop: '2022-03-08T23:00:00.000Z', + title: 'DuftGeheimnis' + }, + { + start: '2022-03-09T04:00:00.000Z', + stop: '2022-03-09T05:00:00.000Z', + title: '1-2-3.tv Morning-Deals' + }, + { + start: '2022-03-09T10:00:00.000Z', + stop: '2022-03-09T11:00:00.000Z', + title: 'Confiserie' + }, + { + start: '2022-03-09T16:00:00.000Z', + stop: '2022-03-09T17:00:00.000Z', + title: 'Sneaker World' + } + ]) + done() + }) + .catch(done) +}) + +it('can handle empty guide', done => { + parser({ + content: `[{"type":"PATH_PARAM","code":"period","reason":"INVALID"}]`, + channel, + date + }) + .then(result => { + expect(result).toMatchObject([]) + done() + }) + .catch(done) +}) diff --git a/sites/horizon.tv/horizon.tv_de.channels.xml b/sites/horizon.tv/horizon.tv_de.channels.xml new file mode 100644 index 00000000..d9d19a5a --- /dev/null +++ b/sites/horizon.tv/horizon.tv_de.channels.xml @@ -0,0 +1,250 @@ + + + + 1-2-3.tv + 13th Street HD + 3sat + Al Arabiya + Al Jazeera + Antenna TV + ARD-alpha + arte + Astro TV + ATV Avrupa + Baby TV + Balkanika Music Television + BBC World News + Beate Uhse HD + Bibel TV + BILD HD + Bloomberg + BN TV + Boomerang + BR Fernsehen Nord + BR Fernsehen Süd + BVN + 24Horas + Cartoon Network + CGTN + CGTN Documentary + Channel21 + CMC + CNBC + CNN + COMEDY CENTRAL + Crime + Investigation + Das Erste + DELUXE MUSIC + Deutsches Musik Fernsehen + DIE NEUE ZEIT TV + Discovery Channel HD + Disney HD + DMAX + DM SAT + ERT World + eSPORTS1 HD + EURO D + euronews (D) + Eurosport1 HD + EUROSPORT 2 + Eurosport360HD 1 + Eurosport360HD 2 + Eurosport360HD 3 + Eurosport360HD 4 + Eurosport360HD 5 + Eurosport360HD 6 + Eurosport360HD 7 + Eurosport360HD 8 + Eurosport360HD 9 + EURO STAR + Fashion TV + Fix&Foxi + Fox HD + France 2 + France 24 (in English) + France 24 (en francais) + France 3 + France 4 + France 5 + GEO TV HD + Ginx TV + Habertürk + Handystar + Hayat TV + Heimatkanal + HOME & GARDEN TV HD + The HISTORY Channel + HopeTV + hr-fernsehen + HRT TV 1 + HSE + HSE Extra + HSE Trend + itvn + JSTV + Junior + Juwelo + kabel eins classics + Kabel eins HD + kabel eins Doku + Kanal 7 + KIKA + Kinowelt TV HD + Klan Kosova + Kohavision TV + k-tv + Lust Pur + MBC Maghreb al Arabia + MDR Sachsen + MDR S-Anhalt + MDR Thüringen HD + Mediaset + Motorvision + MTV + N24 Doku + Nasch Kinomir + NatGeo HD + National Geographic Wild HD + NDR FS HH + NDR FS MV + NDR FS NDS + NDR FS SH + NHK WORLD-JAPAN + Nick HD + Nick.Jr. + Nitro + Nederland 2 + NRWision HD + ntv + NTV Mir + ONE HD + OstWest + Channel One Russia + phoenix + Pink Extra + Pink Film + Pink FOLK + Pink Music + Pink Plus + ProSieben HD + ProSieben FUN HD + ProSieben MAXX + Pro TV International + KAZAKH TV + QVC + QVC Style + QVC ZWEI + Radio Bremen TV + Rai Uno + Rai Due + Rai Tre + Rai News 24 + Rai Storia + rbb Berlin + rbb Brandenburg + Record Internacional + RiC + Romance TV + RTK1 + RTL Crime HD + RTL + RTL Living HD + RTLup + RTLZWEI + Russia Today + RTPi + RTR Planeta + RTS Sat + RTV21 + SAT.1 + SAT.1 emotions + SAT.1 GOLD + SonLife + ServusTV + Show Max + SHOW TURK + Silverline Movie Channel + SIXX + Sky Atlantic HD + Sky Cinema Action HD + Sky Cinema Best Of HD + Sky Cinema Classics + Sky Cinema Family + Sky Cinema Fun + Sky Cinema Premieren HD + Sky Cinema Premieren +24 + Sky Cinema Special HD + Sky Cinema Thriller HD + Sky Comedy HD + Sky Crime HD + Sky Documentaries HD + Sky Krimi HD + Sky Nature HD + Sky One HD + Sky Replay HD + Sky Serien & Shows HD + Sky Sport 10 HD + Sky Sport 11 HD + Sky Sport 1 HD + Sky Sport 2 HD + Sky Sport 3 HD + Sky Sport 4 HD + Sky Sport 5 HD + Sky Sport 6 HD + Sky Sport 7 HD + Sky Sport 8 HD + Sky Sport 9 HD + Sky Sport Bundesliga 10 HD + Sky Sport Bundesliga 1 HD + Sky Sport Bundesliga 2 HD + Sky Sport Bundesliga 3 HD + Sky Sport Bundesliga 4 HD + Sky Sport Bundesliga 5 HD + Sky Sport Bundesliga 6 HD + Sky Sport Bundesliga 7 HD + Sky Sport Bundesliga 8 HD + Sky Sport Bundesliga 9 HD + Sky Sport F1 HD + Sky Sport News HD + sonnenklar.TV + SONY AXN + SONY CHANNEL HD + Spiegel Geschichte + Spiegel TV Wissen HD + Sport1 HD + Sport1+ + SPORTDIGITAL FUSSBALL + SR Fernsehen HD + Super RTL + SWR BW HD + SWR Fernsehen RP + SYFY HD + tagesschau24 HD + Tele 5 + Telebom / Tele Dom + TLC + TOGGO plus + TRT Türk + TV5MONDE Europe + TV 8 + TV Crne Gore Sat + TVE Internacional + TVN 24 + TV Polonia + iTVS + Universal TV HD + Vodafone TV + VOX + VOXup + Warner TV Comedy HD + Warner TV Film + Warner TV Serie + WDR Aachen + WDR Bonn + WDR Köln HD + WELT + ZDF + ZDFinfo HD + zdf_neo + +