-
-
Notifications
You must be signed in to change notification settings - Fork 263
/
Copy pathgatotv.com.config.js
102 lines (87 loc) · 2.87 KB
/
gatotv.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
const axios = require('axios')
const cheerio = require('cheerio')
const url = require('url')
const path = require('path')
const { DateTime } = require('luxon')
module.exports = {
site: 'gatotv.com',
days: 2,
url({ channel, date }) {
return `https://www.gatotv.com/canal/${channel.site_id}/${date.format('YYYY-MM-DD')}`
},
parser({ content, date }) {
let programs = []
const items = parseItems(content)
date = date.subtract(1, 'd')
items.forEach((item, i) => {
const $item = cheerio.load(item)
let start = parseStart($item, date)
if (i === 0 && start.hour >= 5) {
start = start.plus({ days: 1 })
date = date.add(1, 'd')
}
let stop = parseStop($item, date)
if (stop < start) {
stop = stop.plus({ days: 1 })
date = date.add(1, 'd')
}
programs.push({
title: parseTitle($item),
description: parseDescription($item),
image: parseImage($item),
start,
stop
})
})
return programs
},
async channels() {
const data = await axios
.get('https://www.gatotv.com/guia_tv/completa')
.then(response => response.data)
.catch(console.log)
const $ = cheerio.load(data)
const items = $('.tbl_EPG_row,.tbl_EPG_rowAlternate').toArray()
return items.map(item => {
const $item = cheerio.load(item)
const link = $item('td:nth-child(1) > div:nth-child(2) > a:nth-child(3)').attr('href')
const parsed = url.parse(link)
return {
lang: 'es',
site_id: path.basename(parsed.pathname),
name: $item('td:nth-child(1) > div:nth-child(2) > a:nth-child(3)').text()
}
})
}
}
function parseTitle($item) {
return $item(
'td:nth-child(4) > div > div > a > span,td:nth-child(3) > div > div > span,td:nth-child(3) > div > div > a > span'
).text()
}
function parseDescription($item) {
return $item('td:nth-child(4) > div').clone().children().remove().end().text().trim()
}
function parseImage($item) {
return $item('td:nth-child(3) > a > img').attr('src')
}
function parseStart($item, date) {
const time = $item('td:nth-child(1) > div > time').attr('datetime')
return DateTime.fromFormat(`${date.format('YYYY-MM-DD')} ${time}`, 'yyyy-MM-dd HH:mm', {
zone: 'EST'
}).toUTC()
}
function parseStop($item, date) {
const time = $item('td:nth-child(2) > div > time').attr('datetime')
return DateTime.fromFormat(`${date.format('YYYY-MM-DD')} ${time}`, 'yyyy-MM-dd HH:mm', {
zone: 'EST'
}).toUTC()
}
function parseItems(content) {
const $ = cheerio.load(content)
return $(
'body > div.div_content > table:nth-child(8) > tbody > tr:nth-child(2) > td:nth-child(1) > table.tbl_EPG'
)
.find('.tbl_EPG_row,.tbl_EPG_rowAlternate,.tbl_EPG_row_selected')
.toArray()
}