mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-10 09:00:07 -04:00
Update tvpassport.com.config.js
This commit is contained in:
parent
7445c4c27a
commit
c8085e6b3f
1 changed files with 17 additions and 13 deletions
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue