diff --git a/sites/canalplus-haiti.com/canalplus-haiti.com.config.js b/sites/canalplus-haiti.com/canalplus-haiti.com.config.js new file mode 100644 index 00000000..965a09de --- /dev/null +++ b/sites/canalplus-haiti.com/canalplus-haiti.com.config.js @@ -0,0 +1,73 @@ +const axios = require('axios') +const cheerio = require('cheerio') +const dayjs = require('dayjs') +const utc = require('dayjs/plugin/utc') + +dayjs.extend(utc) + +module.exports = { + site: 'canalplus-haiti.com', + url: function ({ channel, date }) { + const diff = date.diff(dayjs.utc().startOf('d'), 'd') + + return `https://service.canal-overseas.com/ott-frontend/vector/53101/channel/${channel.site_id}/events?filter.day=${diff}` + }, + logo({ channel }) { + return channel.logo + }, + parser: function ({ content }) { + let programs = [] + const items = parseItems(content) + items.forEach(item => { + if (item.title === 'Fin des programmes') return + programs.push({ + title: item.title, + icon: item.URLImageDefault, + start: parseStart(item).toJSON(), + stop: parseStop(item).toJSON() + }) + }) + + return programs + }, + async channels() { + const html = await axios + .get(`https://www.canalplus-haiti.com/guide-tv-ce-soir`) + .then(r => r.data) + .catch(console.log) + + const $ = cheerio.load(html) + const script = $('body > script:nth-child(2)').html() + const [_, json] = script.match(/window.APP_STATE=(.*);/) || [null, null] + const data = JSON.parse(json) + const items = data.tvGuide.channels.byZapNumber + + return Object.values(items).map(item => { + return { + lang: 'fr', + site_id: item.epgID, + name: item.name, + logo: item.LogoUrl + } + }) + } +} + +function parseStart(item) { + return dayjs.unix(item.startTime) +} + +function parseStop(item) { + return dayjs.unix(item.endTime) +} + +function parseItems(content) { + const data = JSON.parse(content) + if (!data || !data.timeSlices) return [] + const items = data.timeSlices.reduce((acc, curr) => { + acc = acc.concat(curr.contents) + return acc + }, []) + + return items +} diff --git a/sites/canalplus-haiti.com/canalplus-haiti.com.test.js b/sites/canalplus-haiti.com/canalplus-haiti.com.test.js new file mode 100644 index 00000000..33ec65a6 --- /dev/null +++ b/sites/canalplus-haiti.com/canalplus-haiti.com.test.js @@ -0,0 +1,56 @@ +// [Geo-blocked] node ./scripts/channels.js --config=./sites/canalplus-haiti.com/canalplus-haiti.com.config.js --output=./sites/canalplus-haiti.com/canalplus-haiti.com_ht.channels.xml +// npx epg-grabber --config=sites/canalplus-haiti.com/canalplus-haiti.com.config.js --channels=sites/canalplus-haiti.com/canalplus-haiti.com_ht.channels.xml --output=.gh-pages/guides/ht/canalplus-haiti.com.epg.xml --days=2 + +const { parser, url, logo } = require('./canalplus-haiti.com.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 channel = { + site_id: '60020', + xmltv_id: 'CanalPlusReunion.fr', + logo: 'https://service.canal-overseas.com/image-api/v1/image/702e588188caa19c38c438d14bfc8870' +} + +it('can generate valid url for today', () => { + const date = dayjs.utc().startOf('d') + expect(url({ channel, date })).toBe( + 'https://service.canal-overseas.com/ott-frontend/vector/53101/channel/60020/events?filter.day=0' + ) +}) + +it('can generate valid url for tomorrow', () => { + const date = dayjs.utc().startOf('d').add(1, 'd') + expect(url({ channel, date })).toBe( + 'https://service.canal-overseas.com/ott-frontend/vector/53101/channel/60020/events?filter.day=1' + ) +}) + +it('can get logo url', () => { + expect(logo({ channel })).toBe( + 'https://service.canal-overseas.com/image-api/v1/image/702e588188caa19c38c438d14bfc8870' + ) +}) + +it('can parse response', () => { + const content = `{"timeSlices":[{"contents":[{"title":"Fin des programmes","thirdTitle":"MA TV","startTime":1636768800,"endTime":1636855200,"onClick":{"displayTemplate":"miniDetail","displayName":"Fin des programmes","URLPage":"https://service.canal-overseas.com/ott-frontend/vector/63001/event/110427432","URLVitrine":"https://service.canal-overseas.com/ott-frontend/vector/63001/program/0/recommendations"},"programID":0,"diffusionID":"110427432","URLImageDefault":"https://service.canal-overseas.com/image-api/v1/image/generic","URLImage":"https://service.canal-overseas.com/image-api/v1/image/generic"}],"timeSlice":"0"},{"contents":[{"title":"Le cercle","subtitle":"5 Novembre 2021","thirdTitle":"CANAL+ HD","startTime":1636793201,"endTime":1636795901,"onClick":{"displayTemplate":"miniDetail","displayName":"Le cercle","URLPage":"https://service.canal-overseas.com/ott-frontend/vector/63001/event/110427540","URLVitrine":"https://service.canal-overseas.com/ott-frontend/vector/63001/program/193072081/recommendations"},"programID":193072081,"diffusionID":"110427540","URLImageDefault":"https://service.canal-overseas.com/image-api/v1/image/2a311987c642d97485d5f531e698dfb7","URLImage":"https://service.canal-overseas.com/image-api/v1/image/2de336e6a8c962921638c8aeee5f7e52"}],"timeSlice":"1"},{"contents":[],"timeSlice":"2"},{"contents":[],"timeSlice":"3"},{"contents":[],"timeSlice":"4"}]}` + const result = parser({ content }) + + expect(result).toMatchObject([ + { + start: '2021-11-13T08:46:41.000Z', + stop: '2021-11-13T09:31:41.000Z', + title: 'Le cercle', + icon: 'https://service.canal-overseas.com/image-api/v1/image/2a311987c642d97485d5f531e698dfb7' + } + ]) +}) + +it('can handle empty guide', () => { + const result = parser({ + content: `{"currentPage":{"displayTemplate":"error","BOName":"Page introuvable"},"title":"Page introuvable","text":"La page que vous demandez est introuvable. Si le problème persiste, vous pouvez contacter l'assistance de CANAL+/CANALSAT.","code":404}` + }) + expect(result).toMatchObject([]) +}) diff --git a/sites/canalplus-haiti.com/canalplus-haiti.com_ht.channels.xml b/sites/canalplus-haiti.com/canalplus-haiti.com_ht.channels.xml new file mode 100644 index 00000000..a921a46c --- /dev/null +++ b/sites/canalplus-haiti.com/canalplus-haiti.com_ht.channels.xml @@ -0,0 +1,117 @@ + + + + 6ter + 13ème Rue + Action + Alizés + A+ + Automoto la chaîne + BBC World News Americas + Bblack! Caribbean + C8 + Canal 10 + Canal + Cinéma France + Canal + Haïti + Canal + Kids + Canal + Sport France + Cine + Classic + Cine + Club + Cine + Émotion + Cine + Famiz + Cine + Frisson + Cine + Premier + C News + CNN International Latin America + Comédie + + C Star + Cuisines + Discovery Channel France + Discovery Science France + Disney Channel France + Disney Junior France + Dorcel TV Africa + E! France + English Club TV + ES1 + ESPN 2 Caribbean + ESPN Caribbean + ETV + Eurosport 1 + Eurosport 2 + France 2 + France 3 + France 5 + France 24 Français + Franceinfo: + Game One + Globo News + Graphé TV + Guadeloupe 1ère + Guyane 1ère + Haiti Sports TV 1 + Haiti Sports TV 2 + HBO Xtreme Latinoamérica + InfoSport + + IOTV + KMT + KTO + KTV Guyane + LCI + LCP Public Sénat + L'Équipe + Ludikids + M6 + Martinique 1ère + MCM France + Metropole + MTV France + MTV Hits France + Nathan TV + National Geographic France + National Geographic Wild France + Nickelodeon France + Nick Jr Africa + Nollywood TV + Novelas TV + NRJ 12 + Paramount Channel France + Paris Première + Penthouse Black + Piwi + + Planète + + Planète + A&E + Planète + CI + RTL 9 + Seasons + Sony Channel Centro + Studiocanal + STVS 8.1 + Syfy France + Télé 20 + Telemicro Internacional + Telemundo + Tele Pacific + Tele Soleil + TéléToon + + TF 1 + TF 1 Séries Films + TFX + TNH + Toute l'Histoire + Trace Ayiti + Trace Caribbean + Trace Gospel + Trace Latina + Trace Urban + TV5Monde Amérique Latine + TV Caraïbes + Ushuaïa TV + ViàATV + Vixen + Wataaa TV + XXL + Zitata TV + Zouk TV + + \ No newline at end of file