-
-
Notifications
You must be signed in to change notification settings - Fork 233
/
singtel.com.config.js
68 lines (61 loc) · 1.69 KB
/
singtel.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
const dayjs = require('dayjs')
const utc = require('dayjs/plugin/utc')
const timezone = require('dayjs/plugin/timezone')
dayjs.extend(utc)
dayjs.extend(timezone)
module.exports = {
site: 'singtel.com',
days: 3,
request: {
cache: {
ttl: 60 * 60 * 1000 // 1 hour
}
},
url({ date }) {
return `https://www.singtel.com/etc/singtel/public/tv/epg-parsed-data/${date.format(
'DDMMYYYY'
)}.json`
},
parser({ content, channel }) {
let programs = []
const items = parseItems(content, channel)
items.forEach(item => {
const start = dayjs.tz(item.startDateTime, 'Asia/Singapore')
const stop = start.add(item.duration, 's')
programs.push({
title: item.program.title,
category: item.program.subCategory,
description: item.program.description,
start,
stop
})
})
return programs
},
async channels() {
const axios = require('axios')
const cheerio = require('cheerio')
const data = await axios
.get(`https://www.singtel.com/personal/products-services/tv/tv-programme-guide`)
.then(r => r.data)
.catch(console.log)
const $ = cheerio.load(data)
let datamodel = $('ux-tv-channel-epg').attr('datamodel')
datamodel = JSON.parse(datamodel)
return datamodel.tvChannelLists.map(item => {
return {
lang: 'en',
site_id: item.epgChannelId,
name: item.title.trim()
}
})
}
}
function parseItems(content, channel) {
try {
const data = JSON.parse(content)
return data && data[channel.site_id] ? data[channel.site_id] : []
} catch (err) {
return []
}
}