forked from iptv-org/epg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
canalplus.com.config.js
188 lines (164 loc) · 4.88 KB
/
canalplus.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
const dayjs = require('dayjs')
const axios = require('axios')
const utc = require('dayjs/plugin/utc')
dayjs.extend(utc)
module.exports = {
site: 'canalplus.com',
days: 2,
url: async function ({ channel, date }) {
const [region, site_id] = channel.site_id.split('#')
const data = await axios
.get(`https://www.canalplus.com/${region}/programme-tv/`)
.then(r => r.data.toString())
.catch(err => console.log(err))
const token = parseToken(data)
const diff = date.diff(dayjs.utc().startOf('d'), 'd')
return `https://hodor.canalplus.pro/api/v2/mycanal/channels/${token}/${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),
actors: parseCast(info, 'Avec :'),
director: parseCast(info, 'De :'),
writer: parseCast(info, 'Scénario :'),
composer: parseCast(info, 'Musique :'),
presenter: parseCast(info, 'Présenté par :'),
date: parseDate(info),
rating: parseRating(info),
start,
stop
})
}
return programs
},
async channels({ country }) {
const paths = {
ad: 'cpafr/ad',
bf: 'cpafr/bf',
bi: 'cpafr/bi',
bj: 'cpafr/bj',
bl: 'cpant/bl',
cd: 'cpafr/cd',
cf: 'cpafr/cf',
cg: 'cpafr/cg',
ch: 'cpche',
ci: 'cpafr/ci',
cm: 'cpafr/cm',
cv: 'cpafr/cv',
dj: 'cpafr/dj',
fr: 'cpfra',
ga: 'cpafr/ga',
gf: 'cpant/gf',
gh: 'cpafr/gh',
gm: 'cpafr/gm',
gn: 'cpafr/gn',
gp: 'cpafr/gp',
gw: 'cpafr/gw',
mf: 'cpant/mf',
mg: 'cpafr/mg',
ml: 'cpafr/ml',
mq: 'cpant/mq',
mr: 'cpafr/mr',
mu: 'cpmus/mu',
nc: 'cpncl/nc',
ne: 'cpafr/ne',
pl: 'cppol',
re: 'cpreu/re',
rw: 'cpafr/rw',
sl: 'cpafr/sl',
sn: 'cpafr/sn',
td: 'cpafr/td',
tg: 'cpafr/tg',
wf: 'cpncl/wf',
yt: 'cpreu/yt'
}
let channels = []
const path = paths[country]
const url = `https://secure-webtv-static.canal-plus.com/metadata/${path}/all/v2.2/globalchannels.json`
const data = await axios
.get(url)
.then(r => r.data)
.catch(console.log)
data.channels.forEach(channel => {
const site_id = country === 'fr' ? `#${channel.id}` : `${country}#${channel.id}`
if (channel.name === '.') return
channels.push({
lang: 'fr',
site_id,
name: channel.name
})
})
return channels
}
}
function parseToken(data) {
const [, token] = data.match(/"token":"([^"]+)/) || [null, null]
return token
}
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
}, [])
}
function parseCast(info, type) {
let people = []
if (info && info.personnalities) {
const personnalities = info.personnalities.find(i => i.prefix == type)
if (!personnalities) return people
for (let person of personnalities.personnalitiesList) {
people.push(person.title)
}
}
return people
}
function parseDate(info) {
return info && info.productionYear ? info.productionYear : null
}
function parseRating(info) {
if (!info || !info.parentalRatings) return null
let rating = info.parentalRatings.find(i => i.authority === 'CSA')
if (!rating || Array.isArray(rating)) return null
if (rating.value === '1') return null
if (rating.value === '2') rating.value = '-10'
if (rating.value === '3') rating.value = '-12'
if (rating.value === '4') rating.value = '-16'
if (rating.value === '5') rating.value = '-18'
return {
system: rating.authority,
value: rating.value
}
}