mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-10 00:50:09 -04:00
Update tvtv.us.config.js
This commit is contained in:
parent
b8285b1970
commit
51827d1bff
1 changed files with 40 additions and 12 deletions
|
@ -1,5 +1,4 @@
|
||||||
const dayjs = require('dayjs')
|
const dayjs = require('dayjs')
|
||||||
const doFetch = require('@ntlab/sfetch')
|
|
||||||
|
|
||||||
let cachedPrograms = {}
|
let cachedPrograms = {}
|
||||||
|
|
||||||
|
@ -11,12 +10,23 @@ module.exports = {
|
||||||
.add(1, 'day')
|
.add(1, 'day')
|
||||||
.toJSON()}/${channel.site_id}`
|
.toJSON()}/${channel.site_id}`
|
||||||
},
|
},
|
||||||
async parser({ content }) {
|
request: {
|
||||||
|
headers: {
|
||||||
|
Accept: '*/*',
|
||||||
|
Connection: 'keep-alive',
|
||||||
|
'User-Agent':
|
||||||
|
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36',
|
||||||
|
'sec-ch-ua': '"Not.A/Brand";v="8", "Chromium";v="114", "Google Chrome";v="114"',
|
||||||
|
'sec-ch-ua-mobile': '?0',
|
||||||
|
'sec-ch-ua-platform': '"Windows"'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
async parser({ content, request }) {
|
||||||
let programs = []
|
let programs = []
|
||||||
let queue = []
|
let queue = []
|
||||||
|
|
||||||
const items = parseItems(content)
|
const items = parseItems(content)
|
||||||
items.forEach(item => {
|
for (const item of items) {
|
||||||
const start = dayjs(item.startTime)
|
const start = dayjs(item.startTime)
|
||||||
const stop = start.add(item.duration, 'minute')
|
const stop = start.add(item.duration, 'minute')
|
||||||
|
|
||||||
|
@ -31,16 +41,26 @@ module.exports = {
|
||||||
if (item.programId && !cachedPrograms[item.programId]) {
|
if (item.programId && !cachedPrograms[item.programId]) {
|
||||||
queue.push({
|
queue.push({
|
||||||
programId: item.programId,
|
programId: item.programId,
|
||||||
url: `https://tvtv.us/api/v1/programs/${item.programId}`
|
url: `https://tvtv.us/api/v1/programs/${item.programId}`,
|
||||||
|
httpAgent: request.agent,
|
||||||
|
httpsAgent: request.agent,
|
||||||
|
headers: module.exports.request.headers
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
|
||||||
await doFetch(queue, (req, data) => {
|
const axios = require('axios')
|
||||||
if (!data || !data.title) return
|
for (const req of queue) {
|
||||||
|
await wait(5000)
|
||||||
|
|
||||||
|
const data = await axios(req)
|
||||||
|
.then(r => r.data)
|
||||||
|
.catch(console.error)
|
||||||
|
|
||||||
|
if (!data || !data.title) continue
|
||||||
|
|
||||||
cachedPrograms[req.programId] = data
|
cachedPrograms[req.programId] = data
|
||||||
})
|
}
|
||||||
|
|
||||||
programs.forEach(program => {
|
programs.forEach(program => {
|
||||||
const data = cachedPrograms[program.id]
|
const data = cachedPrograms[program.id]
|
||||||
|
@ -81,10 +101,12 @@ function parseSeason(data) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseRatings(data) {
|
function parseRatings(data) {
|
||||||
return data.ratings.map(rating => ({
|
return Array.isArray(data.ratings)
|
||||||
value: rating.code,
|
? data.ratings.map(rating => ({
|
||||||
system: rating.body
|
value: rating.code,
|
||||||
}))
|
system: rating.body
|
||||||
|
}))
|
||||||
|
: []
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseWriters(data) {
|
function parseWriters(data) {
|
||||||
|
@ -118,3 +140,9 @@ function parseItems(content) {
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function wait(ms) {
|
||||||
|
return new Promise(resolve => {
|
||||||
|
setTimeout(resolve, ms)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue