-
-
Notifications
You must be signed in to change notification settings - Fork 236
/
starhubtvplus.com.config.js
92 lines (88 loc) · 2.45 KB
/
starhubtvplus.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
89
90
91
92
const axios = require('axios')
const dayjs = require('dayjs')
const languages = { en: 'en_US', zh: 'zh' }
module.exports = {
site: 'starhubtvplus.com',
days: 2,
url({ date, channel }) {
return `https://waf-starhub-metadata-api-p001.ifs.vubiquity.com/v3.1/epg/schedules?locale=${
languages[channel.lang]
}&locale_default=${
languages[channel.lang]
}&device=1&in_channel_id=${
channel.site_id
}>_end=${
date.unix()
}<_start=${
date.add(1, 'd').unix()
}&limit=100&page=1`
},
async parser({ content, date, channel }) {
const programs = []
if (content) {
let res = JSON.parse(content)
while (res) {
if (res.resources) {
programs.push(...res.resources)
}
if (res.page && res.page.current < res.page.total) {
res = await axios
.get(module.exports.url({ date, channel }).replace(/page=(\d+)/, `page=${res.page.current + 1}`))
.then(r => r.data)
.catch(console.error)
} else {
res = null
}
}
}
const season = s => {
if (s) {
const [ , , n ] = s.match(/(S|Season )(\d+)/) || [null, null, null]
if (n) {
return parseInt(n)
}
}
}
return programs.map(item => {
return {
title: item.title,
subTitle: item.serie_title,
description: item.description,
category: item.genres,
image: item.pictures?.map(img => img.url),
season: season(item.serie_title),
episode: item.episode_number,
rating: item.rating,
start: dayjs(item.start * 1000),
stop: dayjs(item.end * 1000)
}
})
},
async channels({ lang = 'en' }) {
const resources = []
let page = 1
while (true) {
const items = await axios
.get(`https://waf-starhub-metadata-api-p001.ifs.vubiquity.com/v3.1/epg/channels?locale=${
languages[lang]
}&locale_default=${
languages[lang]
}&device=1&limit=50&page=${page}`)
.then(r => r.data)
.catch(console.error)
if (items.resources) {
resources.push(...items.resources)
}
if (items.page && page < items.page.total) {
page++
} else {
break
}
}
return resources.map(ch => ({
lang,
site_id: ch.id,
name: ch.title
}))
}
}