forked from iptv-org/epg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
watchyour.tv.config.js
56 lines (50 loc) · 1.38 KB
/
watchyour.tv.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
const dayjs = require('dayjs')
const axios = require('axios')
module.exports = {
site: 'watchyour.tv',
days: 2,
url: 'https://www.watchyour.tv/guide.json',
request: {
cache: {
ttl: 60 * 60 * 1000 // 1 hour
}
},
parser: function ({ content, date, channel }) {
let programs = []
const items = parseItems(content, date, channel)
items.forEach(item => {
const start = parseStart(item)
const stop = start.add(parseInt(item.duration), 'm')
programs.push({
title: item.name,
icon: item.icon,
category: item.category,
start,
stop
})
})
return programs
},
async channels() {
const data = await axios
.get('https://www.watchyour.tv/guide.json')
.then(r => r.data)
.catch(console.log)
return data.map(item => ({
lang: 'en',
site_id: item.id,
name: item.name
}))
}
}
function parseStart(item) {
return dayjs.unix(parseInt(item.tms))
}
function parseItems(content, date, channel) {
if (!content) return []
const data = JSON.parse(content)
if (!Array.isArray(data)) return []
const channelData = data.find(i => i.id == channel.site_id)
if (!channelData || !Array.isArray(channelData.shows)) return []
return channelData.shows.filter(i => i.start_day === date.format('YYYY-MM-DD'))
}