forked from iptv-org/epg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
toonamiaftermath.com.config.js
60 lines (49 loc) · 1.52 KB
/
toonamiaftermath.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
process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = '0'
const dayjs = require('dayjs')
const axios = require('axios')
const API_ENDPOINT = 'https://api.toonamiaftermath.com'
module.exports = {
site: 'toonamiaftermath.com',
days: 3,
async url({ channel, date }) {
const playlists = await axios
.get(
`${API_ENDPOINT}/playlists?scheduleName=${channel.site_id}&startDate=${date
.add(1, 'd')
.toJSON()}&thisWeek=true&weekStartDay=monday`
)
.then(r => r.data)
.catch(console.error)
const playlist = playlists.find(p => date.isSame(p.startDate, 'day'))
return `${API_ENDPOINT}/playlist?id=${playlist._id}&addInfo=true`
},
parser({ content }) {
let programs = []
const items = parseItems(content)
items.forEach(item => {
programs.push({
title: item.name,
sub_title: parseEpisode(item),
icon: parseIcon(item),
start: dayjs(item.startDate),
stop: dayjs(item.endDate)
})
})
return programs
}
}
function parseItems(content) {
if (!content) return []
const data = JSON.parse(content)
if (!data || !data.playlist) return []
return data.playlist.blocks.reduce((acc, curr) => {
acc = acc.concat(curr.mediaList)
return acc
}, [])
}
function parseEpisode(item) {
return item && item.info && item.info.episode ? item.info.episode : null
}
function parseIcon(item) {
return item && item.info && item.info.image ? item.info.image : null
}