diff --git a/.github/workflows/magentatv.at.yml b/.github/workflows/magentatv.at.yml new file mode 100644 index 00000000..5d4a70ee --- /dev/null +++ b/.github/workflows/magentatv.at.yml @@ -0,0 +1,17 @@ +name: magentatv.at +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/magentatv.at/magentatv.at.config.js b/sites/magentatv.at/magentatv.at.config.js new file mode 100644 index 00000000..3c5388b5 --- /dev/null +++ b/sites/magentatv.at/magentatv.at.config.js @@ -0,0 +1,70 @@ +const axios = require('axios') +const dayjs = require('dayjs') + +const API_ENDPOINT = `https://prod.oesp.magentatv.at/oesp/v4/AT/deu/web/programschedules` + +module.exports = { + site: 'magentatv.at', + 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://prod.oesp.magentatv.at/oesp/v4/AT/deu/web/channels`) + .then(r => r.data) + .catch(console.log) + + return data.channels.map(item => { + return { + lang: 'de', + site_id: item.id.replace('lgi-at-prodobo-master:101-', ''), + 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-at-prodobo-master:${channel.site_id}`) + + return entity ? entity.l : [] +} diff --git a/sites/magentatv.at/magentatv.at.test.js b/sites/magentatv.at/magentatv.at.test.js new file mode 100644 index 00000000..eee51716 --- /dev/null +++ b/sites/magentatv.at/magentatv.at.test.js @@ -0,0 +1,103 @@ +// npm run channels:parse -- --config=./sites/magentatv.at/magentatv.at.config.js --output=./sites/magentatv.at/magentatv.at_at.channels.xml +// npx epg-grabber --config=sites/magentatv.at/magentatv.at.config.js --channels=sites/magentatv.at/magentatv.at_at.channels.xml --output=guide.xml --days=2 + +const { parser, url } = require('./magentatv.at.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: '13TH_Street_HD', + xmltv_id: '13thStreetDeutschland.us' +} + +it('can generate valid url', () => { + expect(url({ date })).toBe( + 'https://prod.oesp.magentatv.at/oesp/v4/AT/deu/web/programschedules/20220309/1' + ) +}) + +it('can parse response', done => { + const content = `{"entries":[{"o":"lgi-at-prodobo-master:13TH_Street_HD","l":[{"i":"crid:~~2F~~2Fbds.tv~~2F1870513,imi:c83a0bf1b04d6610d0517e63647772c1c8725693","t":"Law & Order: Special Victims Unit","s":1646778600000,"e":1646781300000,"c":"lgi-at-prodobo-master:genre-9","a":false,"r":false,"rm":false,"ad":[],"sl":[]}]}]}` + + axios.get.mockImplementation(url => { + if (url === 'https://prod.oesp.magentatv.at/oesp/v4/AT/deu/web/programschedules/20220309/2') { + return Promise.resolve({ + data: JSON.parse( + `{"entries":[{"o":"lgi-at-prodobo-master:13TH_Street_HD","l":[{"i":"crid:~~2F~~2Fmedia-press.tv~~2F217048123,imi:ee14cfe306cb50502b03c96d58851c32345a9391","t":"FBI: Special Crime Unit","s":1646781300000,"e":1646784000000,"c":"lgi-at-prodobo-master:genre-9","a":false,"r":false,"rm":false,"ad":[],"sl":[]}]}]}` + ) + }) + } else if ( + url === 'https://prod.oesp.magentatv.at/oesp/v4/AT/deu/web/programschedules/20220309/3' + ) { + return Promise.resolve({ + data: JSON.parse( + `{"entries":[{"o":"lgi-at-prodobo-master:13TH_Street_HD","l":[{"i":"crid:~~2F~~2Fmedia-press.tv~~2F224431085,imi:805c5a9b6610edb65cdff319a9b080ab5f65a6c8","t":"FBI: Special Crime Unit","s":1646784000000,"e":1646786700000,"c":"lgi-at-prodobo-master:genre-9","a":false,"r":false,"rm":false,"ad":[],"sl":[]}]}]}` + ) + }) + } else if ( + url === 'https://prod.oesp.magentatv.at/oesp/v4/AT/deu/web/programschedules/20220309/4' + ) { + return Promise.resolve({ + data: JSON.parse( + `{"entries":[{"o":"lgi-at-prodobo-master:13TH_Street_HD","l":[{"i":"crid:~~2F~~2Fbds.tv~~2F918961,imi:f27353bf910e8849d60e0381fdb2d1f7518ef7a2","t":"Law & Order","s":1646786700000,"e":1646789400000,"c":"lgi-at-prodobo-master:genre-9","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:30:00.000Z', + stop: '2022-03-08T23:15:00.000Z', + title: 'Law & Order: Special Victims Unit' + }, + { + start: '2022-03-08T23:15:00.000Z', + stop: '2022-03-09T00:00:00.000Z', + title: 'FBI: Special Crime Unit' + }, + { + start: '2022-03-09T00:00:00.000Z', + stop: '2022-03-09T00:45:00.000Z', + title: 'FBI: Special Crime Unit' + }, + { + start: '2022-03-09T00:45:00.000Z', + stop: '2022-03-09T01:30:00.000Z', + title: 'Law & Order' + } + ]) + 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/magentatv.at/magentatv.at_at.channels.xml b/sites/magentatv.at/magentatv.at_at.channels.xml new file mode 100644 index 00000000..e310eaae --- /dev/null +++ b/sites/magentatv.at/magentatv.at_at.channels.xml @@ -0,0 +1,174 @@ + + + + 1-2-3.tv + 13th Street HD + 3sat + Al Jazeera + ARD-alpha + ARTE Deutsch + ATV + ATV 2 + Baby TV + Bibel TV + Bloomberg + Blue Hustler Europe + Boomerang + Cartoon Network + CGTN + CNBC + CNN + COMEDY CENTRAL + Crime + Investigation + Das Erste + DELUXE MUSIC + Disney Channel Deutschland + DMAX Austria + eSPORTS1 HD + euronews (D) + Eurosport 1 Germany + Evil Angel TV + Fashion TV + Fix&Foxi + France 24 (en francais) + GEO TV HD + Habertürk + Hayat TV + Heimatkanal + HOME & GARDEN TV HD + HR Fernsehen + HRT TV 1 + HSE + HSE Extra + HSE Trend + Hustler TV Europe + Kabel Eins Austria + Kabel Eins Classics + Kabel Eins Doku Austria + KIKA + Kinowelt TV HD + Motorvision + MTV + N24 Doku + NatGeo HD + National Geographic Wild HD + Nick HD + Nick.Jr. + Nitro Austria + N-TV Austria + Oe24 TV + One + ORF 1 + ORF 2 Burgenland + ORF 2 Europe + ORF 2 Kärnten + ORF 2 NiederÖsterreich + ORF 2 OberÖsterreich + ORF 2 Salzburg + ORF 2 Steiermark + ORF 2 Tirol + ORF 2 Vorarlberg + ORF 2 Wien + ORF III + ORF Sport + + Phoenix + Pink Extra + Pink Film + Pink Music + Pink Plus + ProSieben Austria + ProSieben FUN HD + ProSieben Maxx Austria + QVC2 Deutsch + QVC Deutschland + QVC Style Deutschland + QVC ZWEI + Rai Uno + Rai Due + Rai Tre + RBB Berlin + RiC + Romance TV + RTL Austria + RTL Crime Deutschland + RTL Living Deutschland + RTL Passion Deutschland + RTLup + RTL Zwei Austria + RTR Planeta + SAT.1 emotions + Sat. 1 Gold Österreich + Sat. 1 Österreich + Servus TV Österreich + Sixx Austria + 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 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 Austria 1 + Sky Sport Austria 2 + Sky Sport Austria 3 + Sky Sport Austria 4 + Sky Sport Austria 5 + Sky Sport Austria 6 + Sky Sport Austria 7 + 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 + Spiegel Geschichte + Spiegel TV Wissen HD + Sport 1 + Sport 1+ + SPORTDIGITAL FUSSBALL + SR Fernsehen HD + Super RTL Austria + SWR Fernsehen RP + SYFY HD + tagesschau24 HD + Tele 5 + TLC Austria + TV5MONDE Europe + TV Polonia + Universal TV HD + Vox Austria + Warner TV Comedy HD + Warner TV Serie + WDR Fernsehen Köln + ZDF + ZDF Info + ZDF Neo + +