forked from iptv-org/epg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cableplus.com.uy.config.js
133 lines (117 loc) · 3.56 KB
/
cableplus.com.uy.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
const cheerio = require('cheerio')
const axios = require('axios')
const dayjs = require('dayjs')
const utc = require('dayjs/plugin/utc')
const timezone = require('dayjs/plugin/timezone')
const customParseFormat = require('dayjs/plugin/customParseFormat')
dayjs.extend(utc)
dayjs.extend(timezone)
dayjs.extend(customParseFormat)
const API_ENDPOINT = 'https://www.reportv.com.ar/finder'
module.exports = {
site: 'cableplus.com.uy',
days: 2,
url: `${API_ENDPOINT}/channel`,
request: {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
},
data({ date, channel }) {
const params = new URLSearchParams()
params.append('idAlineacion', '3017')
params.append('idSenial', channel.site_id)
params.append('fecha', date.format('YYYY-MM-DD'))
params.append('hora', '00:00')
return params
}
},
parser({ content, date }) {
const programs = []
const items = parseItems(content, date)
items.forEach(item => {
const $item = cheerio.load(item)
const prev = programs[programs.length - 1]
let start = parseStart($item, date)
if (prev) {
if (start.isBefore(prev.start)) {
start = start.add(1, 'd')
date = date.add(1, 'd')
}
prev.stop = start
}
const stop = start.add(30, 'm')
programs.push({
title: parseTitle($item),
categories: parseCategories($item),
icon: parseIcon($item),
start,
stop
})
})
return programs
},
async channels() {
const params = new URLSearchParams({ idAlineacion: '3017' })
const data = await axios
.post(`${API_ENDPOINT}/channelGrid`, params, {
headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' }
})
.then(r => r.data)
.catch(console.error)
const $ = cheerio.load(data)
return $('.senial')
.map(function () {
return {
lang: 'es',
site_id: $(this).attr('id'),
name: $(this).find('img').attr('alt')
}
})
.get()
}
}
function parseTitle($item) {
return $item('p.evento_titulo.texto_a_continuacion.dotdotdot,.programa-titulo > span:first-child')
.text()
.trim()
}
function parseIcon($item) {
return $item('img').data('src') || $item('img').attr('src') || null
}
function parseCategories($item) {
return $item('p.evento_genero')
.map(function () {
return $item(this).text().trim()
})
.toArray()
}
function parseStart($item, date) {
let time = $item('.grid_fecha_hora').text().trim()
if (time) {
return dayjs.tz(`${date.format('YYYY')} ${time}`, 'YYYY DD-MM HH:mm[hs.]', 'America/Montevideo')
}
time = $item('.fechaHora').text().trim()
return time
? dayjs.tz(`${date.format('YYYY')} ${time}`, 'YYYY DD/MM HH:mm[hs.]', 'America/Montevideo')
: null
}
function parseItems(content, date) {
const $ = cheerio.load(content)
let featuredItems = $('.vista-pc > .programacion-fila > .channel-programa')
.filter(function () {
return $(this).find('.grid_fecha_hora').text().indexOf(date.format('DD-MM')) > -1
})
.toArray()
let otherItems = $('#owl-pc > .item-program')
.filter(function () {
return (
$(this)
.find('.evento_titulo > .horario > p.fechaHora')
.text()
.indexOf(date.format('DD/MM')) > -1
)
})
.toArray()
return featuredItems.concat(otherItems)
}