Merge pull request #2618 from iptv-org/update-tvpassport.com

Update tvpassport.com
This commit is contained in:
PopeyeTheSai10r 2025-01-20 10:31:16 -08:00 committed by GitHub
commit 276210609a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 17364 additions and 7937 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load diff

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)
@ -18,6 +19,7 @@ module.exports = {
)}` )}`
}, },
request: { request: {
timeout: 30000,
headers: { headers: {
Cookie: 'cisession=e49ff13191d6875887193cae9e324b44ef85768d;' Cookie: 'cisession=e49ff13191d6875887193cae9e324b44ef85768d;'
} }
@ -31,15 +33,15 @@ module.exports = {
const duration = parseDuration($item) const duration = parseDuration($item)
const stop = start.add(duration, 'm') const stop = start.add(duration, 'm')
let title = parseTitle($item) let title = parseTitle($item)
let sub_title = parseSubTitle($item) let subtitle = parseSubTitle($item)
if (title === 'Movie') { if (title === 'Movie') {
title = sub_title title = subtitle
sub_title = null subtitle = null
} }
programs.push({ programs.push({
title, title,
sub_title, subtitle,
description: parseDescription($item), description: parseDescription($item),
image: parseImage($item), image: parseImage($item),
category: parseCategory($item), category: parseCategory($item),
@ -47,6 +49,7 @@ module.exports = {
actors: parseActors($item), actors: parseActors($item),
guest: parseGuest($item), guest: parseGuest($item),
director: parseDirector($item), director: parseDirector($item),
year: parseYear($item),
start, start,
stop stop
}) })
@ -55,33 +58,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 ', '')
@ -92,7 +98,7 @@ module.exports = {
}) })
i++ i++
} })
return channels return channels
} }
@ -110,11 +116,15 @@ function parseImage($item) {
} }
function parseTitle($item) { function parseTitle($item) {
return $item('*').data('showname') return $item('*').data('showname').toString()
} }
function parseSubTitle($item) { function parseSubTitle($item) {
return $item('*').data('episodetitle') return $item('*').data('episodetitle').toString() || null
}
function parseYear($item) {
return $item('*').data('year').toString() || null
} }
function parseCategory($item) { function parseCategory($item) {

View file

@ -39,7 +39,7 @@ it('can parse response', () => {
start: '2022-10-04T10:00:00.000Z', start: '2022-10-04T10:00:00.000Z',
stop: '2022-10-04T10:30:00.000Z', stop: '2022-10-04T10:30:00.000Z',
title: 'Charlie Moore: No Offense', title: 'Charlie Moore: No Offense',
sub_title: 'Under the Influencer', subtitle: 'Under the Influencer',
category: ['Sports', 'Outdoors'], category: ['Sports', 'Outdoors'],
image: 'https://cdn.tvpassport.com/image/show/960x540/69103.jpg', image: 'https://cdn.tvpassport.com/image/show/960x540/69103.jpg',
rating: { rating: {
@ -50,7 +50,23 @@ it('can parse response', () => {
director: ['Rob McElhenney'], director: ['Rob McElhenney'],
guest: ['Sean Penn'], guest: ['Sean Penn'],
description: description:
'Celebrity interviews while fishing in various locations throughout the United States.' 'Celebrity interviews while fishing in various locations throughout the United States.',
year: null
})
expect(results[1]).toMatchObject({
start: '2022-10-04T10:30:00.000Z',
stop: '2022-10-04T11:00:00.000Z',
title: '1900',
year: null
})
expect(results[2]).toMatchObject({
start: '2022-10-04T11:00:00.000Z',
stop: '2022-10-04T12:00:00.000Z',
title: 'The Mark of Zorro',
subtitle: null,
year: '1940'
}) })
}) })