-
-
Notifications
You must be signed in to change notification settings - Fork 239
/
sat.tv.config.js
173 lines (152 loc) · 5.25 KB
/
sat.tv.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
const axios = require('axios')
const dayjs = require('dayjs')
const cheerio = require('cheerio')
const utc = require('dayjs/plugin/utc')
const customParseFormat = require('dayjs/plugin/customParseFormat')
dayjs.extend(utc)
dayjs.extend(customParseFormat)
const API_ENDPOINT = 'https://sat.tv/wp-content/themes/twentytwenty-child/ajax_chaines.php'
module.exports = {
site: 'sat.tv',
days: 2,
url: API_ENDPOINT,
request: {
method: 'POST',
headers({ channel }) {
return {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
Cookie: `pll_language=${channel.lang}`
}
},
data({ channel, date }) {
const [satSatellite, satLineup] = channel.site_id.split('#')
const params = new URLSearchParams()
params.append('dateFiltre', date.format('YYYY-MM-DD'))
params.append('hoursFiltre', '0')
params.append('satLineup', satLineup)
params.append('satSatellite', satSatellite)
params.append('userDateTime', date.valueOf())
params.append('userTimezone', 'Europe/London')
return params
},
cache: {
ttl: 60 * 60 * 1000 // 1h
}
},
parser: function ({ content, date, channel }) {
let programs = []
const items = parseItems(content, channel)
items.forEach(item => {
let $item = cheerio.load(item)
let start = parseStart($item, date)
let duration = parseDuration($item)
let stop = start.add(duration, 'm')
programs.push({
title: parseTitle($item),
description: parseDescription($item),
image: parseImage($item),
start,
stop
})
})
return programs
},
async channels({ lang }) {
const satellites = [
{ satellite: 2, lineup: 55 },
{ satellite: 2, lineup: 58 },
{ satellite: 2, lineup: 53 },
{ satellite: 2, lineup: 57 },
{ satellite: 2, lineup: 54 },
{ satellite: 2, lineup: 56 },
{ satellite: 1, lineup: 48 },
{ satellite: 1, lineup: 44 },
{ satellite: 1, lineup: 42 },
{ satellite: 1, lineup: 39 },
{ satellite: 1, lineup: 37 },
{ satellite: 1, lineup: 38 },
{ satellite: 1, lineup: 68 },
{ satellite: 1, lineup: 47 },
{ satellite: 1, lineup: 41 },
{ satellite: 1, lineup: 49 },
{ satellite: 1, lineup: 46 },
{ satellite: 1, lineup: 35 },
{ satellite: 1, lineup: 43 },
{ satellite: 1, lineup: 45 },
{ satellite: 1, lineup: 50 },
{ satellite: 1, lineup: 71 },
{ satellite: 1, lineup: 40 },
{ satellite: 1, lineup: 72 },
{ satellite: 1, lineup: 33 },
{ satellite: 8, lineup: 62 },
{ satellite: 8, lineup: 63 },
{ satellite: 8, lineup: 64 },
{ satellite: 8, lineup: 65 },
{ satellite: 8, lineup: 66 },
{ satellite: 8, lineup: 67 }
]
let channels = []
for (let sat of satellites) {
const params = new URLSearchParams()
params.append('dateFiltre', dayjs().format('YYYY-MM-DD'))
params.append('hoursFiltre', '0')
params.append('satLineup', sat.lineup)
params.append('satSatellite', sat.satellite)
params.append('userDateTime', dayjs().valueOf())
params.append('userTimezone', 'Europe/London')
const data = await axios
.post(API_ENDPOINT, params, {
headers: {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
Cookie: `pll_language=${lang}`
}
})
.then(r => r.data)
.catch(console.log)
const $ = cheerio.load(data)
$('.main-container-channels-events > .container-channel-events').each((i, el) => {
const name = $(el).find('.channel-title').text().trim()
const channelId = name.replace(/\s&\s/gi, ' & ')
if (!name) return
channels.push({
lang,
site_id: `${sat.satellite}#${sat.lineup}#${channelId}`,
name
})
})
}
return channels
}
}
function parseImage($item) {
const src = $item('.event-logo img:not(.no-img)').attr('src')
return src ? `https://sat.tv${src}` : null
}
function parseTitle($item) {
return $item('.event-data-title').text()
}
function parseDescription($item) {
return $item('.event-data-desc').text()
}
function parseStart($item, date) {
let eventDataDate = $item('.event-data-date').text().trim()
let [, time] = eventDataDate.match(/(\d{2}:\d{2})/) || [null, null]
if (!time) return null
return dayjs.utc(`${date.format('YYYY-MM-DD')} ${time}`, 'YYYY-MM-DD HH:mm')
}
function parseDuration($item) {
let eventDataInfo = $item('.event-data-info').text().trim()
let [, h, m] = eventDataInfo.match(/(\d{2})h(\d{2})/) || [null, 0, 0]
return parseInt(h) * 60 + parseInt(m)
}
function parseItems(content, channel) {
const [, , site_id] = channel.site_id.split('#')
const $ = cheerio.load(content)
const channelData = $('.main-container-channels-events > .container-channel-events')
.filter((index, el) => {
return $(el).find('.channel-title').text().trim() === site_id
})
.first()
if (!channelData) return []
return $(channelData).find('.container-event').toArray()
}