forked from iptv-org/epg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
disneystar.com.config.js
88 lines (79 loc) · 2.4 KB
/
disneystar.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
const axios = require('axios')
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)
const API_ENDPOINT = 'https://www.disneystar.com/umbraco/api/startvguideproxy'
module.exports = {
site: 'disneystar.com',
days: 2,
url: `${API_ENDPOINT}/GetTvGuideSchedule`,
request: {
method: 'POST',
headers: {
'Content-Type': 'application/json; charset=UTF-8'
},
data({ channel, date }) {
return {
Channels: channel.site_id,
Start: date.format('YYYYMMDDHHmm'),
Stop: date.add(1, 'd').format('YYYYMMDDHHmm')
}
}
},
parser: function ({ content, channel }) {
let programs = []
const items = parseItems(content, channel)
items.forEach(item => {
programs.push({
title: item.title,
description: item.desc,
icon: item.programmeurl,
category: item.subgenre,
start: parseStart(item),
stop: parseStop(item)
})
})
return programs
},
async channels() {
const data = await axios
.post(
`${API_ENDPOINT}/GetChannelResult`,
{ Genre: 'All Channels' },
{
headers: {
'Content-Type': 'application/json; charset=UTF-8'
}
}
)
.then(r => JSON.parse(r.data))
.catch(console.log)
const channels = data.channelsbygenreandlanguage.channellist.channelnames.split(',')
return channels.map(item => {
return {
lang: 'hi',
site_id: item,
name: item
}
})
}
}
function parseStart(item) {
return dayjs.tz(item.start, 'YYYYMMDDHHmm', 'Asia/Kolkata')
}
function parseStop(item) {
return dayjs.tz(item.stop, 'YYYYMMDDHHmm', 'Asia/Kolkata')
}
function parseItems(content, channel) {
if (!content.length) return []
const json = JSON.parse(content)
if (!json.length) return []
const data = JSON.parse(json)
if (!data || !data.ScheduleGrid || !Array.isArray(data.ScheduleGrid.channel)) return []
const channelData = data.ScheduleGrid.channel.find(c => c.channeldisplayname === channel.site_id)
return channelData && Array.isArray(channelData.programme) ? channelData.programme : []
}