-
-
Notifications
You must be signed in to change notification settings - Fork 233
/
playtv.unifi.com.my.config.js
85 lines (79 loc) · 2.16 KB
/
playtv.unifi.com.my.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
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: 'playtv.unifi.com.my',
days: 2,
url: 'https://unifi.com.my/tv/api/tv',
request: {
cache: {
ttl: 60 * 60 * 1000 // 1 hour
},
method: 'POST',
headers: {
'x-requested-with': 'XMLHttpRequest'
},
data({ date }) {
const params = new URLSearchParams()
params.append('date', date.format('YYYY-MM-DD'))
return params
}
},
parser({ content, channel, date }) {
let programs = []
const items = parseItems(content, channel)
items.forEach(item => {
const start = parseStart(item, date)
const stop = start.add(item.minute, 'minute')
programs.push({
title: item.name,
start,
stop
})
})
return programs
},
async channels() {
const axios = require('axios')
const data = await axios
.post(
`https://playtv.unifi.com.my:7053/VSP/V3/QueryAllChannel`,
{ isReturnAllMedia: '0' },
{
params: {
userFilter: '-1880777955',
from: 'inMSAAccess'
}
}
)
.then(r => r.data)
.catch(console.log)
return data.channelDetails.map(item => {
return {
lang: 'en',
site_id: item.ID,
name: item.name
}
})
}
}
function parseItems(content, channel) {
try {
const [, string] = content.match(/initializeClient(.*)$/)
const data = JSON.parse(string)
if (!data) return []
if (!Array.isArray(data)) return []
const channelData = data.find(i => i.id == channel.site_id)
return channelData.items && Array.isArray(channelData.items) ? channelData.items : []
} catch (err) {
return []
}
}
function parseStart(item, date) {
const time = `${date.format('YYYY-MM-DD')} ${item.start_time}`
return dayjs.tz(time, 'YYYY-MM-DD H:mma', 'Asia/Kuala_Lumpur')
}