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
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
+29 -19
View File
@@ -4,6 +4,7 @@ const cheerio = require('cheerio')
const utc = require('dayjs/plugin/utc')
const timezone = require('dayjs/plugin/timezone')
const customParseFormat = require('dayjs/plugin/customParseFormat')
const doFetch = require('@ntlab/sfetch')
dayjs.extend(utc)
dayjs.extend(timezone)
@@ -18,6 +19,7 @@ module.exports = {
)}`
},
request: {
timeout: 30000,
headers: {
Cookie: 'cisession=e49ff13191d6875887193cae9e324b44ef85768d;'
}
@@ -31,15 +33,15 @@ module.exports = {
const duration = parseDuration($item)
const stop = start.add(duration, 'm')
let title = parseTitle($item)
let sub_title = parseSubTitle($item)
let subtitle = parseSubTitle($item)
if (title === 'Movie') {
title = sub_title
sub_title = null
title = subtitle
subtitle = null
}
programs.push({
title,
sub_title,
subtitle,
description: parseDescription($item),
image: parseImage($item),
category: parseCategory($item),
@@ -47,6 +49,7 @@ module.exports = {
actors: parseActors($item),
guest: parseGuest($item),
director: parseDirector($item),
year: parseYear($item),
start,
stop
})
@@ -55,33 +58,36 @@ module.exports = {
return programs
},
async channels() {
function wait(ms) {
return new Promise(resolve => {
setTimeout(resolve, ms)
})
}
const xml = await axios
.get('https://www.tvpassport.com/sitemap.stations.xml')
.then(r => r.data)
.catch(console.error)
let channels = []
const $ = cheerio.load(xml)
const elements = $('loc').toArray()
const queue = elements.map(el => $(el).text())
const total = queue.length
let total = elements.length
let i = 1
for (let el of elements) {
const url = $(el).text()
const channels = []
await doFetch(queue, async (url, res) => {
if (!res) return
const [, site_id] = url.match(/\/tv-listings\/stations\/(.*)$/)
console.log(`[${i}/${total}]`, url)
const channelPage = await axios
.get(url)
.then(r => r.data)
.catch(err => console.error(err.message))
await wait(1000)
if (!channelPage) continue
const $channelPage = cheerio.load(channelPage)
const $channelPage = cheerio.load(res)
const title = $channelPage('meta[property="og:title"]').attr('content')
const name = title.replace('TV Schedule for ', '')
@@ -92,7 +98,7 @@ module.exports = {
})
i++
}
})
return channels
}
@@ -110,11 +116,15 @@ function parseImage($item) {
}
function parseTitle($item) {
return $item('*').data('showname')
return $item('*').data('showname').toString()
}
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) {
+18 -2
View File
@@ -39,7 +39,7 @@ it('can parse response', () => {
start: '2022-10-04T10:00:00.000Z',
stop: '2022-10-04T10:30:00.000Z',
title: 'Charlie Moore: No Offense',
sub_title: 'Under the Influencer',
subtitle: 'Under the Influencer',
category: ['Sports', 'Outdoors'],
image: 'https://cdn.tvpassport.com/image/show/960x540/69103.jpg',
rating: {
@@ -50,7 +50,23 @@ it('can parse response', () => {
director: ['Rob McElhenney'],
guest: ['Sean Penn'],
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'
})
})