-
-
Notifications
You must be signed in to change notification settings - Fork 245
/
Copy pathcanalplus-haiti.com.config.js
94 lines (81 loc) · 2.42 KB
/
canalplus-haiti.com.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
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',
days: 2,
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}`
},
async parser({ content }) {
let programs = []
const items = parseItems(content)
for (let item of items) {
if (item.title === 'Fin des programmes') return
const detail = await loadProgramDetails(item)
programs.push({
title: item.title,
description: parseDescription(detail),
category: parseCategory(detail),
image: parseImage(item),
start: parseStart(item),
stop: parseStop(item)
})
}
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
}
})
}
}
async function loadProgramDetails(item) {
if (!item.onClick.URLPage) return {}
const url = item.onClick.URLPage
const data = await axios
.get(url)
.then(r => r.data)
.catch(console.log)
return data || {}
}
function parseDescription(detail) {
return detail.detail.informations.summary || null
}
function parseCategory(detail) {
return detail.detail.informations.subGenre || null
}
function parseImage(item) {
return item.URLImage || item.URLImageDefault
}
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
}