-
-
Notifications
You must be signed in to change notification settings - Fork 263
/
Copy pathclickthecity.com.config.js
100 lines (87 loc) · 2.72 KB
/
clickthecity.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
const cheerio = require('cheerio')
const axios = require('axios')
const { DateTime } = require('luxon')
module.exports = {
site: 'clickthecity.com',
days: 2,
url({ channel }) {
return `https://www.clickthecity.com/tv/channels/?netid=${channel.site_id}`
},
request: {
method: 'POST',
headers: {
'content-type': 'application/x-www-form-urlencoded'
},
data({ date }) {
const params = new URLSearchParams()
params.append(
'optDate',
DateTime.fromMillis(date.valueOf()).setZone('Asia/Manila').toFormat('yyyy-MM-dd')
)
params.append('optTime', '00:00:00')
return params
}
},
parser({ content, date }) {
const programs = []
const items = parseItems(content)
items.forEach(item => {
const $item = cheerio.load(item)
let start = parseStart($item, date)
let stop = parseStop($item, date)
if (!start || !stop) return
if (start > stop) {
stop = stop.plus({ days: 1 })
}
programs.push({
title: parseTitle($item),
start,
stop
})
})
return programs
},
async channels() {
const html = await axios
.get('https://www.clickthecity.com/tv/channels/')
.then(r => r.data)
.catch(console.log)
const $ = cheerio.load(html)
const items = $('#channels .col').toArray()
return items.map(item => {
const name = $(item).find('.card-body').text().trim()
const url = $(item).find('a').attr('href')
const [, site_id] = url.match(/netid=(\d+)/) || [null, null]
return {
lang: 'en',
site_id,
name
}
})
}
}
function parseTitle($item) {
return $item('td > a').text().trim()
}
function parseStart($item, date) {
const url = $item('td.cPrg > a').attr('href') || ''
let [, time] = url.match(/starttime=(\d{1,2}%3A\d{2}\+(AM|PM))/) || [null, null]
if (!time) return null
time = `${date.format('YYYY-MM-DD')} ${time.replace('%3A', ':').replace('+', ' ')}`
return DateTime.fromFormat(time, 'yyyy-MM-dd h:mm a', { zone: 'Asia/Manila' }).toUTC()
}
function parseStop($item, date) {
const url = $item('td.cPrg > a').attr('href') || ''
let [, time] = url.match(/endtime=(\d{1,2}%3A\d{2}\+(AM|PM))/) || [null, null]
if (!time) return null
time = `${date.format('YYYY-MM-DD')} ${time.replace('%3A', ':').replace('+', ' ')}`
return DateTime.fromFormat(time, 'yyyy-MM-dd h:mm a', { zone: 'Asia/Manila' }).toUTC()
}
function parseItems(content) {
const $ = cheerio.load(content)
return $('#tvlistings > tbody > tr')
.filter(function () {
return $(this).find('td.cPrg').length
})
.toArray()
}