Files
epg/sites/starhubtvplus.com/starhubtvplus.com.config.js
T

93 lines
2.5 KiB
JavaScript
Raw Normal View History

2023-10-15 14:08:23 +03:00
const axios = require('axios')
const dayjs = require('dayjs')
2024-12-04 20:56:00 +07:00
const languages = { en: 'en_US', zh: 'zh' }
2023-10-15 14:08:23 +03:00
module.exports = {
site: 'starhubtvplus.com',
days: 2,
2024-12-04 20:56:00 +07:00
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
}&gt_end=${
date.unix()
}&lt_start=${
date.add(1, 'd').unix()
}&limit=100&page=1`
2023-10-15 14:08:23 +03:00
},
2024-12-04 20:56:00 +07:00
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)
}
}
}
2023-10-15 14:08:23 +03:00
2024-12-04 20:56:00 +07:00
return programs.map(item => {
return {
2023-10-15 14:08:23 +03:00
title: item.title,
2024-12-04 20:56:00 +07:00
subTitle: item.serie_title,
2023-10-15 14:08:23 +03:00
description: item.description,
2024-12-04 20:56:00 +07:00
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)
}
2023-10-15 14:08:23 +03:00
})
},
2024-12-04 20:56:00 +07:00
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
}
}
2023-10-15 14:08:23 +03:00
2024-12-04 20:56:00 +07:00
return resources.map(ch => ({
lang,
site_id: ch.id,
name: ch.title
2023-10-15 14:08:23 +03:00
}))
}
}