forked from iptv-org/epg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nhkworldpremium.com.config.js
56 lines (47 loc) · 1.34 KB
/
nhkworldpremium.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
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: 'nhkworldpremium.com',
days: 7,
request: {
cache: {
ttl: 60 * 60 * 1000 // 1 hour
}
},
url({ channel }) {
return `https://nhkworldpremium.com/backend/api/v1/front/episodes?lang=${channel.lang}`
},
parser({ content, date }) {
let programs = []
const items = parseItems(content, date)
items.forEach(item => {
const start = dayjs.tz(item.schedule, 'Asia/Seoul')
const duration = parseDuration(item)
const stop = start.add(duration, 's')
programs.push({
title: item.programTitle,
sub_title: item.episodeTitle,
start,
stop
})
})
return programs
}
}
function parseDuration(item) {
const [h, m, s] = item.period.split(':')
if (!h || !m || !s) return 0
return parseInt(h) * 3600 + parseInt(m) * 60 + parseInt(s)
}
function parseItems(content, date) {
try {
const data = JSON.parse(content)
if (!data || !data.item || !Array.isArray(data.item.episodes)) return []
return data.item.episodes.filter(ep => ep.schedule.startsWith(date.format('YYYY-MM-DD')))
} catch (err) {
return []
}
}