-
-
Notifications
You must be signed in to change notification settings - Fork 233
/
walesi.com.fj.config.js
91 lines (81 loc) · 2.44 KB
/
walesi.com.fj.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
const axios = require('axios')
const cheerio = require('cheerio')
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)
module.exports = {
site: 'walesi.com.fj',
days: 2,
url: 'https://www.walesi.com.fj/wp-admin/admin-ajax.php',
request: {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
},
data({ channel, date }) {
const params = new URLSearchParams()
params.append('chanel', channel.site_id)
params.append('date', date.unix())
params.append('action', 'extvs_get_schedule_simple')
return params
}
},
parser({ content, date }) {
let programs = []
const items = parseItems(content)
items.forEach(item => {
const prev = programs[programs.length - 1]
const $item = cheerio.load(item)
const start = parseStart($item, date)
const stop = start.add(30, 'm')
if (prev) prev.stop = start
programs.push({
title: parseTitle($item),
start,
stop
})
})
return programs
},
async channels() {
const data = await axios
.get('https://www.walesi.com.fj/channel-guide/')
.then(r => r.data)
.catch(console.log)
const $ = cheerio.load(data)
const channels = $(
'div.ex-chanel-list > div.extvs-inline-chanel > ul > li.extvs-inline-select'
).toArray()
return channels.map(item => {
const $item = cheerio.load(item)
const [, name] = $item('span')
.text()
.trim()
.match(/\d+\. (.*)/) || [null, null]
return {
lang: 'fj',
site_id: $item('*').data('value'),
name
}
})
}
}
function parseTitle($item) {
return $item('td.extvs-table1-programme > div > div > figure > h3').text()
}
function parseStart($item, date) {
let time = $item('td.extvs-table1-time > span').text().trim()
if (!time) return null
time = `${date.format('YYYY-MM-DD')} ${time}`
return dayjs.tz(time, 'YYYY-MM-DD H:mm a', 'Pacific/Fiji')
}
function parseItems(content) {
const data = JSON.parse(content)
if (!data.html) return []
const $ = cheerio.load(data.html)
return $('table > tbody > tr').toArray()
}