Update tvpassport.com.config.js

This commit is contained in:
freearhey 2025-01-17 16:50:07 +03:00
parent 7445c4c27a
commit c8085e6b3f

View file

@ -4,6 +4,7 @@ const cheerio = require('cheerio')
const utc = require('dayjs/plugin/utc') const utc = require('dayjs/plugin/utc')
const timezone = require('dayjs/plugin/timezone') const timezone = require('dayjs/plugin/timezone')
const customParseFormat = require('dayjs/plugin/customParseFormat') const customParseFormat = require('dayjs/plugin/customParseFormat')
const doFetch = require('@ntlab/sfetch')
dayjs.extend(utc) dayjs.extend(utc)
dayjs.extend(timezone) dayjs.extend(timezone)
@ -56,33 +57,36 @@ module.exports = {
return programs return programs
}, },
async channels() { async channels() {
function wait(ms) {
return new Promise(resolve => {
setTimeout(resolve, ms)
})
}
const xml = await axios const xml = await axios
.get('https://www.tvpassport.com/sitemap.stations.xml') .get('https://www.tvpassport.com/sitemap.stations.xml')
.then(r => r.data) .then(r => r.data)
.catch(console.error) .catch(console.error)
let channels = []
const $ = cheerio.load(xml) const $ = cheerio.load(xml)
const elements = $('loc').toArray() const elements = $('loc').toArray()
const queue = elements.map(el => $(el).text())
const total = queue.length
let total = elements.length
let i = 1 let i = 1
for (let el of elements) { const channels = []
const url = $(el).text()
await doFetch(queue, async (url, res) => {
if (!res) return
const [, site_id] = url.match(/\/tv-listings\/stations\/(.*)$/) const [, site_id] = url.match(/\/tv-listings\/stations\/(.*)$/)
console.log(`[${i}/${total}]`, url) console.log(`[${i}/${total}]`, url)
const channelPage = await axios await wait(1000)
.get(url)
.then(r => r.data)
.catch(err => console.error(err.message))
if (!channelPage) continue const $channelPage = cheerio.load(res)
const $channelPage = cheerio.load(channelPage)
const title = $channelPage('meta[property="og:title"]').attr('content') const title = $channelPage('meta[property="og:title"]').attr('content')
const name = title.replace('TV Schedule for ', '') const name = title.replace('TV Schedule for ', '')
@ -93,7 +97,7 @@ module.exports = {
}) })
i++ i++
} })
return channels return channels
} }