2025-09-28 17:55:05 +03:00
|
|
|
const axios = require('axios')
|
|
|
|
|
const dayjs = require('dayjs')
|
|
|
|
|
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')
|
2025-10-22 05:42:25 +03:00
|
|
|
const FRENCH_CHANNELS = require('./__data__/frenchChannels.js')
|
2025-09-28 17:55:05 +03:00
|
|
|
|
|
|
|
|
dayjs.extend(utc)
|
|
|
|
|
dayjs.extend(timezone)
|
|
|
|
|
dayjs.extend(customParseFormat)
|
|
|
|
|
|
2026-05-30 11:30:35 +07:00
|
|
|
const headers = {}
|
|
|
|
|
|
2025-09-28 17:55:05 +03:00
|
|
|
module.exports = {
|
|
|
|
|
site: 'tvpassport.com',
|
|
|
|
|
days: 3,
|
2026-05-30 11:30:35 +07:00
|
|
|
async url({ channel, date }) {
|
|
|
|
|
return await getSiteUrl(channel, date.format('YYYY-MM-DD'))
|
2025-09-28 17:55:05 +03:00
|
|
|
},
|
2026-05-30 11:30:35 +07:00
|
|
|
request: {
|
|
|
|
|
timeout: 30000,
|
|
|
|
|
headers
|
2025-09-28 17:55:05 +03:00
|
|
|
},
|
2026-05-30 11:30:35 +07:00
|
|
|
parser({ content }) {
|
|
|
|
|
const programs = []
|
|
|
|
|
const [$, tz, items] = parseItems(content)
|
|
|
|
|
for (const item of items) {
|
|
|
|
|
const $item = $(item)
|
|
|
|
|
const start = parseStart($item, tz)
|
2025-09-28 17:55:05 +03:00
|
|
|
const duration = parseDuration($item)
|
|
|
|
|
const stop = start.add(duration, 'm')
|
|
|
|
|
let title = parseTitle($item)
|
|
|
|
|
let subtitle = parseSubTitle($item)
|
2025-10-11 14:42:08 -04:00
|
|
|
if (title === 'Movie' || title === 'Cinéma') {
|
2025-09-28 17:55:05 +03:00
|
|
|
title = subtitle
|
|
|
|
|
subtitle = null
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
programs.push({
|
|
|
|
|
title,
|
|
|
|
|
subtitle,
|
|
|
|
|
description: parseDescription($item),
|
|
|
|
|
image: parseImage($item),
|
|
|
|
|
category: parseCategory($item),
|
|
|
|
|
rating: parseRating($item),
|
|
|
|
|
actors: parseActors($item),
|
|
|
|
|
guest: parseGuest($item),
|
|
|
|
|
director: parseDirector($item),
|
|
|
|
|
year: parseYear($item),
|
|
|
|
|
start,
|
|
|
|
|
stop
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
|
|
const $ = cheerio.load(xml)
|
|
|
|
|
|
|
|
|
|
const elements = $('loc').toArray()
|
|
|
|
|
const queue = elements.map(el => $(el).text())
|
|
|
|
|
const total = queue.length
|
|
|
|
|
|
|
|
|
|
let i = 1
|
|
|
|
|
const channels = []
|
|
|
|
|
|
|
|
|
|
await doFetch(queue, async (url, res) => {
|
|
|
|
|
if (!res) return
|
|
|
|
|
|
2026-05-30 11:30:35 +07:00
|
|
|
const site_id = getSiteId(url)
|
2025-09-28 17:55:05 +03:00
|
|
|
|
|
|
|
|
console.log(`[${i}/${total}]`, url)
|
|
|
|
|
|
|
|
|
|
await wait(1000)
|
|
|
|
|
|
|
|
|
|
const $channelPage = cheerio.load(res)
|
|
|
|
|
const title = $channelPage('meta[property="og:title"]').attr('content')
|
|
|
|
|
const name = title.replace('TV Schedule for ', '')
|
2025-10-04 11:41:03 -04:00
|
|
|
const lang = FRENCH_CHANNELS.has(site_id) ? 'fr' : 'en'
|
2025-09-28 17:55:05 +03:00
|
|
|
|
|
|
|
|
channels.push({
|
2025-10-04 11:41:03 -04:00
|
|
|
lang,
|
2025-09-28 17:55:05 +03:00
|
|
|
site_id,
|
|
|
|
|
name
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
i++
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
return channels
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-30 11:30:35 +07:00
|
|
|
async function getSiteUrl(channel, date) {
|
|
|
|
|
const f = () =>
|
|
|
|
|
`https://www.tvpassport.com/tv-listings/stations/${channel.site_id}/${date}`
|
|
|
|
|
let url = f()
|
|
|
|
|
const res = await axios.head(url, { headers })
|
|
|
|
|
.then(res => saveCookies(res))
|
|
|
|
|
.then(res => res?.request?.res?.responseUrl)
|
|
|
|
|
.catch(console.error)
|
|
|
|
|
if (res && res !== url) {
|
|
|
|
|
channel.site_id = getSiteId(res)
|
|
|
|
|
url = f()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return url
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getSiteId(url) {
|
|
|
|
|
const [, site_id] = url.match(/\/tv-listings\/stations\/(.*)$/)
|
|
|
|
|
|
|
|
|
|
return site_id
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function saveCookies(res) {
|
|
|
|
|
if (res.headers && Array.isArray(res.headers['set-cookie'])) {
|
|
|
|
|
const cookies = []
|
|
|
|
|
cookies.push(...res.headers['set-cookie']
|
|
|
|
|
.map(cookie => cookie.split(';')[0].trim()))
|
|
|
|
|
headers.Cookie = cookies.length ? cookies.join('; ') : null
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return res
|
2025-10-26 11:40:54 -04:00
|
|
|
}
|
|
|
|
|
|
2025-09-28 17:55:05 +03:00
|
|
|
function parseDescription($item) {
|
2026-05-30 11:30:35 +07:00
|
|
|
return $item.data('description')
|
2025-09-28 17:55:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function parseImage($item) {
|
2026-05-30 11:30:35 +07:00
|
|
|
const showpicture = $item.data('showpicture')
|
2025-09-28 17:55:05 +03:00
|
|
|
const url = new URL(showpicture, 'https://cdn.tvpassport.com/image/show/960x540/')
|
|
|
|
|
|
|
|
|
|
return url.href
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function parseTitle($item) {
|
2026-05-30 11:30:35 +07:00
|
|
|
return $item.data('showname').toString()
|
2025-09-28 17:55:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function parseSubTitle($item) {
|
2026-05-30 11:30:35 +07:00
|
|
|
return $item.data('episodetitle')?.toString() || null
|
2025-09-28 17:55:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function parseYear($item) {
|
2026-05-30 11:30:35 +07:00
|
|
|
return $item.data('year')?.toString() || null
|
2025-09-28 17:55:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function parseCategory($item) {
|
2026-05-30 11:30:35 +07:00
|
|
|
const showtype = $item.data('showtype')
|
2025-09-28 17:55:05 +03:00
|
|
|
|
|
|
|
|
return showtype ? showtype.split(', ') : []
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function parseActors($item) {
|
2026-05-30 11:30:35 +07:00
|
|
|
const cast = $item.data('cast')
|
2025-09-28 17:55:05 +03:00
|
|
|
|
|
|
|
|
return cast ? cast.split(', ') : []
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function parseDirector($item) {
|
2026-05-30 11:30:35 +07:00
|
|
|
const director = $item.data('director')
|
2025-09-28 17:55:05 +03:00
|
|
|
|
|
|
|
|
return director ? director.split(', ') : []
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function parseGuest($item) {
|
2026-05-30 11:30:35 +07:00
|
|
|
const guest = $item.data('guest')
|
2025-09-28 17:55:05 +03:00
|
|
|
|
|
|
|
|
return guest ? guest.split(', ') : []
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function parseRating($item) {
|
2026-05-30 11:30:35 +07:00
|
|
|
const rating = $item.data('rating')
|
2025-09-28 17:55:05 +03:00
|
|
|
|
|
|
|
|
return rating
|
|
|
|
|
? {
|
|
|
|
|
system: 'MPA',
|
|
|
|
|
value: rating.replace(/^TV/, 'TV-')
|
|
|
|
|
}
|
|
|
|
|
: null
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-24 16:09:43 -06:00
|
|
|
function parseStart($item, currentTimezone) {
|
2026-05-30 11:30:35 +07:00
|
|
|
const time = $item.data('st')
|
2025-09-28 17:55:05 +03:00
|
|
|
|
2026-02-24 16:09:43 -06:00
|
|
|
return dayjs.tz(time, 'YYYY-MM-DD HH:mm:ss', currentTimezone)
|
2025-09-28 17:55:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function parseDuration($item) {
|
2026-05-30 11:30:35 +07:00
|
|
|
const duration = $item.data('duration')
|
2025-09-28 17:55:05 +03:00
|
|
|
|
|
|
|
|
return parseInt(duration)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function parseItems(content) {
|
2026-05-30 11:30:35 +07:00
|
|
|
if (!content) return [null, null, []]
|
2025-09-28 17:55:05 +03:00
|
|
|
const $ = cheerio.load(content)
|
|
|
|
|
|
2026-05-30 11:30:35 +07:00
|
|
|
return [
|
|
|
|
|
$,
|
|
|
|
|
$('#timezone_selector').val() || 'America/New_York',
|
|
|
|
|
$('.station-listings .list-group-item').toArray()
|
|
|
|
|
]
|
2025-09-28 17:55:05 +03:00
|
|
|
}
|