From 96b80d003e168d47bc3612cd201408846780092a Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Mon, 7 Mar 2022 17:00:53 +0300 Subject: [PATCH 1/5] Create canalplus.com.test.js --- sites/canalplus.com/canalplus.com.test.js | 101 ++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 sites/canalplus.com/canalplus.com.test.js diff --git a/sites/canalplus.com/canalplus.com.test.js b/sites/canalplus.com/canalplus.com.test.js new file mode 100644 index 00000000..3a6e3428 --- /dev/null +++ b/sites/canalplus.com/canalplus.com.test.js @@ -0,0 +1,101 @@ +// npm run channels:parse -- --config=./sites/canalplus.com/canalplus.com.config.js --output=./sites/canalplus.com/canalplus.com_fr.channels.xml +// npx epg-grabber --config=sites/canalplus.com/canalplus.com.config.js --channels=sites/canalplus.com/canalplus.com_fr.channels.xml --output=guide.xml --days=2 + +const { parser, url } = require('./canalplus.com.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) + +const date = dayjs.utc('2022-03-07', 'YYYY-MM-DD').startOf('d') +const channel = { + site_id: '312', + xmltv_id: 'TF1.fr' +} + +jest.mock('axios') + +it('can generate valid url for today', () => { + const today = dayjs.utc('2022-03-07', 'YYYY-MM-DD').startOf('d') + expect(url({ channel, date: today })).toBe( + 'https://hodor.canalplus.pro/api/v2/mycanal/channels/f55e5c7ddf0afba59d1c64581358910d/312/broadcasts/day/0' + ) +}) + +it('can generate valid url for tomorrow', () => { + const tomorrow = dayjs.utc('2022-03-08', 'YYYY-MM-DD').startOf('d') + expect(url({ channel, date: tomorrow })).toBe( + 'https://hodor.canalplus.pro/api/v2/mycanal/channels/f55e5c7ddf0afba59d1c64581358910d/312/broadcasts/day/1' + ) +}) + +it('can parse response', done => { + const content = `{"timeSlices":[{"timeSlice":"0","contents":[{"contentID":"18257183_50061","title":"TFou","subtitle":"Emission du 07 mars 2022","startTime":1646630700000,"onClick":{"displayTemplate":"detailSeason","displayName":"TFou","path":"/jeunesse/tfou/h/10709960_50061","URLPage":"https://hodor.canalplus.pro/api/v2/mycanal/detail/f55e5c7ddf0afba59d1c64581358910d/okapi/10709339_50061.json?detailType=detailSeason&objectType=season&broadcastID=PLM_1094261940&episodeId=18257183_50061&brandID=10709960_50061&fromDiff=true"}}]},{"timeSlice":"1","contents":[{"contentID":"18257202_50061","title":"Petits plats en équilibre","subtitle":"Mag. Gastronomie","startTime":1646654100000,"onClick":{"displayTemplate":"detailPage","displayName":"Petits plats en équilibre","path":"/divertissement/petits-plats-en-equilibre-mag-gastronomie/h/18257202_50061","URLPage":"https://hodor.canalplus.pro/api/v2/mycanal/detail/f55e5c7ddf0afba59d1c64581358910d/okapi/18257202_50061.json?detailType=detailPage&objectType=unit&broadcastID=PLM_1094380194&fromDiff=true"}}]}]}` + + axios.get.mockImplementation(url => { + if ( + url === + 'https://hodor.canalplus.pro/api/v2/mycanal/detail/f55e5c7ddf0afba59d1c64581358910d/okapi/10709339_50061.json?detailType=detailSeason&objectType=season&broadcastID=PLM_1094261940&episodeId=18257183_50061&brandID=10709960_50061&fromDiff=true' + ) { + return Promise.resolve({ + data: JSON.parse( + `{"detail":{"informations":{"URLImage":"https://thumb.canalplus.pro/http/unsafe/{resolutionXY}/filters:quality({imageQualityPercentage})/img-hapi.canalplus.pro:80/ServiceImage/ImageID/97215037","summary":"Une émission jeunesse qui propose les meilleures séries de dessins animés du moment."}}}` + ) + }) + } else if ( + url === + 'https://hodor.canalplus.pro/api/v2/mycanal/detail/f55e5c7ddf0afba59d1c64581358910d/okapi/18257202_50061.json?detailType=detailPage&objectType=unit&broadcastID=PLM_1094380194&fromDiff=true' + ) { + return Promise.resolve({ + data: JSON.parse( + `{"detail":{"informations":{"URLImage":"https://thumb.canalplus.pro/http/unsafe/{resolutionXY}/filters:quality({imageQualityPercentage})/img-hapi.canalplus.pro:80/ServiceImage/ImageID/100841894","summary":"Chaque jour, Laurent Mariotte propose des recettes simples et savoureuses pour profiter des ingrédients de saison, en donnant la part belle aux produits locaux."}}}` + ) + }) + } else { + return Promise.resolve({ data: '' }) + } + }) + + parser({ content }) + .then(result => { + result.map(p => { + p.start = p.start.toJSON() + p.stop = p.stop.toJSON() + return p + }) + + expect(result).toMatchObject([ + { + start: '2022-03-07T05:25:00.000Z', + stop: '2022-03-07T11:55:00.000Z', + title: 'TFou', + description: + 'Une émission jeunesse qui propose les meilleures séries de dessins animés du moment.', + icon: 'https://thumb.canalplus.pro/http/unsafe/{resolutionXY}/filters:quality({imageQualityPercentage})/img-hapi.canalplus.pro:80/ServiceImage/ImageID/97215037' + }, + { + start: '2022-03-07T11:55:00.000Z', + stop: '2022-03-07T12:55:00.000Z', + title: 'Petits plats en équilibre', + description: + 'Chaque jour, Laurent Mariotte propose des recettes simples et savoureuses pour profiter des ingrédients de saison, en donnant la part belle aux produits locaux.', + icon: 'https://thumb.canalplus.pro/http/unsafe/{resolutionXY}/filters:quality({imageQualityPercentage})/img-hapi.canalplus.pro:80/ServiceImage/ImageID/100841894' + } + ]) + done() + }) + .catch(done) +}) + +it('can handle empty guide', done => { + parser({ + content: `{"currentPage":{"displayTemplate":"error","displayName":"Page introuvable","path":"/erreur","BOName":"Page introuvable","BOLayoutName":"Erreur 404"},"title":"Page introuvable","text":"La page que vous demandez est introuvable. Si le problème persiste, vous pouvez contacter l'assistance de CANAL+.","code":404}` + }) + .then(result => { + expect(result).toMatchObject([]) + done() + }) + .catch(done) +}) From 822b1e1bd08bbf3330ffc1c84632a217bb6a0913 Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Mon, 7 Mar 2022 17:00:57 +0300 Subject: [PATCH 2/5] Create canalplus.com.config.js --- sites/canalplus.com/canalplus.com.config.js | 83 +++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 sites/canalplus.com/canalplus.com.config.js diff --git a/sites/canalplus.com/canalplus.com.config.js b/sites/canalplus.com/canalplus.com.config.js new file mode 100644 index 00000000..9ea5388d --- /dev/null +++ b/sites/canalplus.com/canalplus.com.config.js @@ -0,0 +1,83 @@ +const dayjs = require('dayjs') +const axios = require('axios') + +module.exports = { + site: 'canalplus.com', + url: function ({ channel, date }) { + const diff = date.diff(dayjs.utc().startOf('d'), 'd') + + return `https://hodor.canalplus.pro/api/v2/mycanal/channels/f55e5c7ddf0afba59d1c64581358910d/${channel.site_id}/broadcasts/day/${diff}` + }, + async parser({ content }) { + let programs = [] + const items = parseItems(content) + for (let item of items) { + const prev = programs[programs.length - 1] + const details = await loadProgramDetails(item) + const info = parseInfo(details) + const start = parseStart(item) + if (prev) prev.stop = start + const stop = start.add(1, 'h') + programs.push({ + title: item.title, + description: parseDescription(info), + icon: parseIcon(info), + start, + stop + }) + } + + return programs + }, + async channels() { + const data = await axios + .get(`https://secure-webtv-static.canal-plus.com/metadata/cpfra/all/v2.2/globalchannels.json`) + .then(r => r.data) + .catch(console.log) + + return data.channels.map(item => { + return { + lang: 'fr', + site_id: item.id, + name: item.name + } + }) + } +} + +function parseStart(item) { + return item && item.startTime ? dayjs(item.startTime) : null +} + +function parseIcon(info) { + return info ? info.URLImage : null +} + +function parseDescription(info) { + return info ? info.summary : null +} + +function parseInfo(data) { + if (!data || !data.detail || !data.detail.informations) return null + + return data.detail.informations +} + +async function loadProgramDetails(item) { + if (!item.onClick || !item.onClick.URLPage) return {} + + return await axios + .get(item.onClick.URLPage) + .then(r => r.data) + .catch(console.error) +} + +function parseItems(content) { + const data = JSON.parse(content) + if (!data || !Array.isArray(data.timeSlices)) return [] + + return data.timeSlices.reduce((acc, curr) => { + acc = acc.concat(curr.contents) + return acc + }, []) +} From a246613328ac792c748c625ac595e1a0ba1f26ce Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Mon, 7 Mar 2022 17:01:03 +0300 Subject: [PATCH 3/5] Create canalplus.com_fr.channels.xml --- .../canalplus.com_fr.channels.xml | 222 ++++++++++++++++++ 1 file changed, 222 insertions(+) create mode 100644 sites/canalplus.com/canalplus.com_fr.channels.xml diff --git a/sites/canalplus.com/canalplus.com_fr.channels.xml b/sites/canalplus.com/canalplus.com_fr.channels.xml new file mode 100644 index 00000000..2970c117 --- /dev/null +++ b/sites/canalplus.com/canalplus.com_fr.channels.xml @@ -0,0 +1,222 @@ + + + + 3 SAT + 6TER + AB1 + ACTION + AL JAZEERA ENG + ALTICE STUDIO + ANIMAUX + ARIRANG TV + ARTE + ASTROCENTER TV + AUTOMOTO LA CHAINE + BBC WORLD NEWS + BEIN SPORTS 1 + BEIN SPORTS 2 + BEIN SPORTS 3 + BEIN SPORTS MAX 10 + BEIN SPORTS MAX 4 + BEIN SPORTS MAX 5 + BEIN SPORTS MAX 6 + BEIN SPORTS MAX 7 + BEIN SPORTS MAX 8 + BEIN SPORTS MAX 9 + BET + BFM BUSINESS + BFM TV + BLOOMBERG TV + BLUE ZOOM + BOING + BOOMERANG + BSMART TV + C8 + CANAL ALPHA NE + CANAL J + CANAL+CINEMA + CANAL+DECALE + CANAL+DOCS + CANAL+FORMULA1 + CANAL+ + CANAL+GRAND ECRAN + CANAL+KIDS + CANAL+MOTOGP + CANAL+PREMIER LEAGUE + CANAL+SERIES + CANAL+ SPORT 2 (CH) + CANAL+SPORT + CANAL+TOP14 + CARTOON NETWORK + CHASSE ET PECHE + CHERIE 25 + CINE+ CLASSIC + CINE+ CLUB + CINE+ EMOTION + CINE+ FAMIZ + CINE+ FRISSON + CINE+ PREMIER + CLIQUE TV + CNBC + CNEWS + CNN INT. + COLMAX TV + COMEDIE+ + COMEDY CENTRAL + CSTAR + CSTAR HITS FRANCE + ARD DAS ERSTE + DISNEY CHANNEL + DISNEY CHANNEL+1 + DISNEY CINEMA + DISNEY JUNIOR + DORCEL TV + DORCEL XXX + EQUIDIA + EURONEWS + EUROSPORT 1 + EUROSPORT 2 + EUROSPORT 3 + EUROSPORT 360 1 + EUROSPORT 360 2 + EUROSPORT 360 3 + EUROSPORT 360 4 + EUROSPORT 360 5 + EUROSPORT 360 6 + EUROSPORT 360 7 + EUROSPORT 360 8 + EUROSPORT 4 + EUROSPORT 5 + FOOT+ 24/24 + FRANCE 2 + FRANCE 24 ENG + FRANCE 24 + FRANCE 3 + F3 ALPES + F3 ALSACE + F3 AQUITAINE + F3 AUVERGNE + F3 BNORMANDIE + F3 BOURGOGNE + F3 BRETAGNE + F3 CENTRE + F3 CHAMP ARDENNE + F3 CORSEVIASTELLA + F3 COTE D'AZUR + F3 FRANCHE COMTE + F3 HNORMANDIE + F3 LANGUEDOCROU + F3 LIMOUSIN + F3 LORRAINE + F3 MIDI PYRENEES + F3 NORD PDC + F3 NOUVELLE AQUITAINE + F3 PARIS IDF + F3 PAYS DE LA LOIRE + F3 PICARDIE + F3 POITOUCHAR + F3 PROV ALPES + F3 RHONE ALPES + FRANCE 4 + FRANCE 5 + FRANCEINFO: + GAME ONE + GOLF+ + GULLI + HISTOIRE TV + I24 NEWS + INFOSPORT+ + JACQUIE & MICHEL TV + J-ONE + LA CHAINE METEO + LCI + LCP + L'EQUIPE + LFM TV + M6 + M6 MUSIC + MANGAS + MAN X + MCM + MELODY + MEZZO + MEZZO LIVE + MGG TV + MTV + MTV HITS + MULTISPORTS 1 + MULTISPORTS 2 + MULTISPORTS 3 + MULTISPORTS 4 + MULTISPORTS 5 + MULTISPORTS 6 + MUSEUM + MY ZEN TV + NATIONAL GEO + NATIONAL GEOGRAPHIC WILD + NHK WORLD-JAPAN + NICKELODEON + NICKELODEON JUNIOR + NICKELODEON TEEN + NOLLYWOOD TV + NON STOP PEOPLE + NOVELAS TV + NRJ 12 + NRJ HITS + OCS CHOC + OCS CITY + OCS GEANTS + OCS MAX + OLYMPIA TV + ONE TV + ORF 1 + PARAMOUNT CHANNEL + PARIS PREMIERE + PENTHOUSE BLACK + PENTHOUSE + PINK X + PIWI+ + PLANETE+ + PLANETE+AVENTURE + PLANETE+CRIME + POLAR+ + RAI UNO + RFM TV + RMC DECOUVERTE + RMC SPORT 1 + RMC SPORT 2 + RMC STORY + ROUGE TV + RT FRANCE + RTL9 + SCIENCE ET VIE TV + SEASONS + SERIE CLUB + SRF 1 + CLASSICA + DJAZZ + TCM CINEMA + TELEBIELINGUE + TELETOON+ + TELETOON+1 + TEVA + TF1 + TF1 SERIES FILMS + TFX + TIJI + TMC + TOONAMI + TOUTE L'HISTOIRE + TRACE AFRICA + TRACE LATINA + TRACE URBAN + TV5 MONDE + TV BREIZH + USHUAIA TV + VICE TV + VIXEN + W9 + WARNER TV + XXL + + From 8280a3a442b56b586dc666311ad296f5673cb5bd Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Mon, 7 Mar 2022 17:01:06 +0300 Subject: [PATCH 4/5] Create canalplus.com.yml --- .github/workflows/canalplus.com.yml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 .github/workflows/canalplus.com.yml diff --git a/.github/workflows/canalplus.com.yml b/.github/workflows/canalplus.com.yml new file mode 100644 index 00000000..3beee9ab --- /dev/null +++ b/.github/workflows/canalplus.com.yml @@ -0,0 +1,17 @@ +name: canalplus.com +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 }} From cd09dd5be2ee8a2714d07272b3d6b427fe771514 Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Mon, 7 Mar 2022 18:16:41 +0300 Subject: [PATCH 5/5] Update canalplus.com_fr.channels.xml --- sites/canalplus.com/canalplus.com_fr.channels.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sites/canalplus.com/canalplus.com_fr.channels.xml b/sites/canalplus.com/canalplus.com_fr.channels.xml index 2970c117..5e67ad2a 100644 --- a/sites/canalplus.com/canalplus.com_fr.channels.xml +++ b/sites/canalplus.com/canalplus.com_fr.channels.xml @@ -73,7 +73,7 @@ DORCEL TV DORCEL XXX EQUIDIA - EURONEWS + EURONEWS EUROSPORT 1 EUROSPORT 2 EUROSPORT 3