mirror of
https://github.com/iptv-org/epg
synced 2026-04-30 06:26:59 -04:00
Update visionplus.id guide.
This site now can serve id and en language. Signed-off-by: Toha <tohenk@yahoo.com>
This commit is contained in:
@@ -9,84 +9,54 @@ dayjs.extend(utc)
|
||||
dayjs.extend(timezone)
|
||||
dayjs.extend(customParseFormat)
|
||||
|
||||
const languages = { en: 'ENG', id: 'IND' }
|
||||
const tz = 'Asia/Jakarta'
|
||||
|
||||
module.exports = {
|
||||
site: 'visionplus.id',
|
||||
days: 2,
|
||||
request: {
|
||||
headers: {
|
||||
Authorization:
|
||||
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE5NDY0NTE4OTcsInVpZCI6MCwicGwiOiJ3ZWIiLCJndWVzdF90b2tlbiI6ImNhNGNjMjdiNzc3MjBjODEwNzQ2YzY3MTY4NzNjMDI3NGU4NWYxMWQifQ.tt08jLZ3HiNadUeSgc9O-nhIzEi7WMYRjxMb05lEZ74'
|
||||
}
|
||||
},
|
||||
url({ date, channel }) {
|
||||
return `https://epg-api.visionplus.id/api/v1/epg?isLive=false&start_time_from=${date.format(
|
||||
return `https://www.visionplus.id/managetv/tvinfo/events/schedule?language=${languages[channel.lang]}&serviceId=${channel.site_id}&start=${date.format(
|
||||
'YYYY-MM-DD'
|
||||
)}&channel_ids=${channel.site_id}`
|
||||
)}T00%3A00%3A00Z&end=${date.add(1, 'd').format(
|
||||
'YYYY-MM-DD'
|
||||
)}T00%3A00%3A00Z&view=cd-events-grid-view`
|
||||
},
|
||||
parser({ content, channel, date }) {
|
||||
const programs = []
|
||||
const items = parseItems(content, channel, date)
|
||||
items.forEach(item => {
|
||||
let prev = programs[programs.length - 1]
|
||||
let start = parseStart(item, date)
|
||||
let stop = parseStop(item, date)
|
||||
if (prev) {
|
||||
if (start.isBefore(prev.start)) {
|
||||
start = start.add(1, 'd')
|
||||
}
|
||||
if (stop.isBefore(prev.stop)) {
|
||||
stop = stop.add(1, 'd')
|
||||
const json = JSON.parse(content)
|
||||
if (Array.isArray(json.evs)) {
|
||||
for (const ev of json.evs) {
|
||||
if (ev.sid === channel.site_id) {
|
||||
programs.push({
|
||||
title: ev.con && ev.con.loc ? ev.con.loc[0].tit : ev.con.oti,
|
||||
description: ev.con && ev.con.loc ? ev.con.loc[0].syn : null,
|
||||
categories: ev.con ? ev.con.categories : null,
|
||||
start: dayjs(ev.sta),
|
||||
stop: dayjs(ev.end)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
programs.push({
|
||||
title: item.t,
|
||||
description: item.synopsis,
|
||||
start,
|
||||
stop
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
return programs
|
||||
},
|
||||
async channels() {
|
||||
const xml = await axios
|
||||
.get('https://www.visionplus.id/sitemap-channels.xml')
|
||||
.then(r => r.data)
|
||||
.catch(console.log)
|
||||
async channels({ lang = 'id' }) {
|
||||
const result = []
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const channelFile = path.join(__dirname, 'channels.json')
|
||||
if (fs.existsSync(channelFile)) {
|
||||
const items = JSON.parse(fs.readFileSync(channelFile))
|
||||
Object.values(items).forEach(item => {
|
||||
result.push({
|
||||
lang,
|
||||
site_id: item.serviceId,
|
||||
name: item.name
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
const $ = cheerio.load(xml)
|
||||
const items = $('url').toArray()
|
||||
|
||||
return items.map(item => {
|
||||
const $item = cheerio.load(item)
|
||||
const loc = $item('loc').text()
|
||||
const [, site_id] = loc.match(/channel\/(\d+)\//) || [null, null]
|
||||
|
||||
return {
|
||||
lang: 'en',
|
||||
site_id,
|
||||
name: $item('video\\:title').text().trim()
|
||||
}
|
||||
})
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
function parseStart(item, date) {
|
||||
return dayjs.tz(`${date.format('YYYY-MM-DD')} ${item.s}`, 'YYYY-MM-DD HH:mm', 'Asia/Jakarta')
|
||||
}
|
||||
|
||||
function parseStop(item, date) {
|
||||
return dayjs.tz(`${date.format('YYYY-MM-DD')} ${item.e}`, 'YYYY-MM-DD HH:mm', 'Asia/Jakarta')
|
||||
}
|
||||
|
||||
function parseItems(content, channel, date) {
|
||||
const data = JSON.parse(content)
|
||||
if (!data || !Array.isArray(data.data)) return []
|
||||
const channelData = data.data.find(c => c.id === channel.site_id)
|
||||
if (!channelData || !Array.isArray(channelData.schedules)) return []
|
||||
const daySchedule = channelData.schedules.find(d => d.date === date.format('YYYY-MM-DD'))
|
||||
if (!daySchedule || !Array.isArray(daySchedule.items)) return []
|
||||
|
||||
return daySchedule.items
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user