forked from iptv-org/epg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rev.bs.config.js
68 lines (58 loc) · 1.78 KB
/
rev.bs.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 _ = require('lodash')
const axios = require('axios')
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: 'rev.bs',
days: 2,
url: function ({ date }) {
return `https://www.rev.bs/wp-content/uploads/tv-guide/${date.format('YYYY-MM-DD')}_0.json`
},
parser: async function ({ content, channel, date }) {
const programs = []
const items0 = parseItems(content, channel)
if (!items0.length) return programs
const items1 = parseItems(await loadNextItems(date, 1), channel)
const items2 = parseItems(await loadNextItems(date, 2), channel)
const items3 = parseItems(await loadNextItems(date, 3), channel)
const items = _.unionBy(items0, items1, items2, items3, 'sid')
items.forEach(item => {
const start = parseStart(item, date)
const stop = start.add(item.duration, 'm')
programs.push({
title: item.title,
start,
stop
})
})
return programs
}
}
async function loadNextItems(date, index) {
const url = `https://www.rev.bs/wp-content/uploads/tv-guide/${date.format(
'YYYY-MM-DD'
)}_${index}.json`
return axios
.get(url, {
responseType: 'arraybuffer'
})
.then(res => res.data.toString())
.catch(console.log)
}
function parseStart(item, date) {
const shift = parseInt(item.s)
return dayjs.tz(date.add(shift, 'm').toString(), 'America/New_York')
}
function parseItems(content, channel) {
let data
try {
data = JSON.parse(content)
} catch (error) {
return []
}
if (!data || data.status !== 'OK') return []
return data.data.schedule[channel.site_id] || []
}