mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-10 00:50:09 -04:00
Update tv.trueid.net.config.js
This commit is contained in:
parent
fbf2617fa0
commit
ad700f009f
1 changed files with 20 additions and 19 deletions
|
@ -1,4 +1,4 @@
|
||||||
const jsdom = require('jsdom')
|
const cheerio = require('cheerio')
|
||||||
const dayjs = require('dayjs')
|
const dayjs = require('dayjs')
|
||||||
const utc = require('dayjs/plugin/utc')
|
const utc = require('dayjs/plugin/utc')
|
||||||
|
|
||||||
|
@ -20,17 +20,13 @@ module.exports = {
|
||||||
},
|
},
|
||||||
parser: function ({ content, channel }) {
|
parser: function ({ content, channel }) {
|
||||||
let programs = []
|
let programs = []
|
||||||
const data = parseContent(content, channel)
|
const items = parseItems(content, channel)
|
||||||
const items = parseItems(data)
|
|
||||||
items.forEach(item => {
|
items.forEach(item => {
|
||||||
const start = parseStart(item)
|
|
||||||
const stop = parseStop(item)
|
|
||||||
|
|
||||||
programs.push({
|
programs.push({
|
||||||
title: item.title,
|
title: item.title,
|
||||||
icon: parseIcon(item),
|
icon: parseIcon(item),
|
||||||
start,
|
start: parseStart(item),
|
||||||
stop
|
stop: parseStop(item)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -51,19 +47,24 @@ function parseStop(item) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseContent(content, channel) {
|
function parseContent(content, channel) {
|
||||||
const virtualConsole = new jsdom.VirtualConsole()
|
const $ = cheerio.load(content)
|
||||||
virtualConsole.sendTo(console, { omitJSDOMErrors: true })
|
const nextData = $('#__NEXT_DATA__').html()
|
||||||
const dom = new jsdom.JSDOM(content, { virtualConsole })
|
const data = JSON.parse(nextData)
|
||||||
const elem = dom.window.document.getElementById('__NEXT_DATA__') || { textContent: '' }
|
if (
|
||||||
if (!elem.textContent) return null
|
!data ||
|
||||||
const data = JSON.parse(elem.textContent)
|
!data.props ||
|
||||||
const channels = data.props?.pageProps?.listEPG?.data || []
|
!data.props.pageProps ||
|
||||||
|
!data.props.pageProps.listEPG ||
|
||||||
|
!Array.isArray(data.props.pageProps.listEPG.data)
|
||||||
|
)
|
||||||
|
return null
|
||||||
|
|
||||||
return channels.find(ch => ch.slug === channel.site_id)
|
return data.props.pageProps.listEPG.data.find(ch => ch.slug === channel.site_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseItems(data) {
|
function parseItems(content, channel) {
|
||||||
if (!data) return []
|
const data = parseContent(content, channel)
|
||||||
|
if (!data || !Array.isArray(data.programList)) return []
|
||||||
|
|
||||||
return data.programList || []
|
return data.programList
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue