mirror of
https://github.com/iptv-org/epg
synced 2026-04-28 13:37:01 -04:00
Replace LF endings with CRLF
This commit is contained in:
@@ -1,114 +1,114 @@
|
||||
const axios = require('axios')
|
||||
const dayjs = require('dayjs')
|
||||
const utc = require('dayjs/plugin/utc')
|
||||
const timezone = require('dayjs/plugin/timezone')
|
||||
const doFetch = require('@ntlab/sfetch')
|
||||
const debug = require('debug')('site:tvguide.com')
|
||||
|
||||
dayjs.extend(utc)
|
||||
dayjs.extend(timezone)
|
||||
|
||||
doFetch.setDebugger(debug).setCheckResult(false)
|
||||
|
||||
const providerId = '9100001138'
|
||||
const maxDuration = 240
|
||||
const segments = 1440 / maxDuration
|
||||
|
||||
module.exports = {
|
||||
site: 'tvguide.com',
|
||||
days: 2,
|
||||
request: {
|
||||
cache: {
|
||||
ttl: 24 * 60 * 60 * 1000 // 1 day
|
||||
}
|
||||
},
|
||||
async url({ date, segment = 1 }) {
|
||||
const params = []
|
||||
if (module.exports.apiKey === undefined) {
|
||||
module.exports.apiKey = await module.exports.fetchApiKey()
|
||||
debug('Got api key', module.exports.apiKey)
|
||||
}
|
||||
if (date) {
|
||||
if (segment > 1) {
|
||||
date = date.add((segment - 1) * maxDuration, 'm')
|
||||
}
|
||||
params.push(`start=${date.unix()}`, `duration=${maxDuration}`)
|
||||
}
|
||||
params.push(`apiKey=${module.exports.apiKey}`)
|
||||
|
||||
return date ?
|
||||
`https://backend.tvguide.com/tvschedules/tvguide/${providerId}/web?${params.join('&')}` :
|
||||
`https://backend.tvguide.com/tvschedules/tvguide/serviceprovider/${providerId}/sources/web?${params.join('&')}`
|
||||
},
|
||||
async parser({ content, date, channel }) {
|
||||
const programs = []
|
||||
const f = data => {
|
||||
const result = []
|
||||
if (typeof data === 'string') {
|
||||
data = JSON.parse(data)
|
||||
}
|
||||
if (data && Array.isArray(data?.data?.items)) {
|
||||
data.data.items
|
||||
.filter(i => i.channel.sourceId.toString() === channel.site_id)
|
||||
.forEach(i => {
|
||||
result.push(...i.programSchedules.map(p => {
|
||||
return { i: p, url: p.programDetails }
|
||||
}))
|
||||
})
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
const queues = f(content)
|
||||
if (queues.length) {
|
||||
const parts = []
|
||||
for (let i = 2; i <= segments; i++) {
|
||||
parts.push(await module.exports.url({ date, segment: i }))
|
||||
}
|
||||
await doFetch(parts, (url, res) => {
|
||||
queues.push(...f(res))
|
||||
})
|
||||
await doFetch(queues, (queue, res) => {
|
||||
const item = res?.data?.item ? res.data.item : queue.i
|
||||
programs.push({
|
||||
title: item.title ? item.title : queue.i.title,
|
||||
sub_title: item.episodeNumber ? item.episodeTitle : null,
|
||||
description: item.description,
|
||||
season: item.seasonNumber,
|
||||
episode: item.episodeNumber,
|
||||
rating: item.rating ? { system: 'MPA', value: item.rating } : null,
|
||||
categories: Array.isArray(item.genres) ? item.genres.map(g => g.name) : null,
|
||||
start: dayjs.unix(item.startTime ? item.startTime : queue.i.startTime),
|
||||
stop: dayjs.unix(item.endTime ? item.endTime : queue.i.endTime)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
return programs
|
||||
},
|
||||
async channels() {
|
||||
const channels = []
|
||||
const data = await axios
|
||||
.get(await this.url({}))
|
||||
.then(r => r.data)
|
||||
.catch(console.error)
|
||||
|
||||
data.data.items.forEach(item => {
|
||||
channels.push({
|
||||
lang: 'en',
|
||||
site_id: item.sourceId,
|
||||
name: item.fullName.replace(/Channel|Schedule/g, '').trim()
|
||||
})
|
||||
})
|
||||
|
||||
return channels
|
||||
},
|
||||
async fetchApiKey() {
|
||||
const data = await axios
|
||||
.get('https://www.tvguide.com/listings/')
|
||||
.then(r => r.data)
|
||||
.catch(console.error)
|
||||
|
||||
return data ? data.match(/apiKey=([a-zA-Z0-9]+)&/)[1] : null
|
||||
}
|
||||
}
|
||||
const axios = require('axios')
|
||||
const dayjs = require('dayjs')
|
||||
const utc = require('dayjs/plugin/utc')
|
||||
const timezone = require('dayjs/plugin/timezone')
|
||||
const doFetch = require('@ntlab/sfetch')
|
||||
const debug = require('debug')('site:tvguide.com')
|
||||
|
||||
dayjs.extend(utc)
|
||||
dayjs.extend(timezone)
|
||||
|
||||
doFetch.setDebugger(debug).setCheckResult(false)
|
||||
|
||||
const providerId = '9100001138'
|
||||
const maxDuration = 240
|
||||
const segments = 1440 / maxDuration
|
||||
|
||||
module.exports = {
|
||||
site: 'tvguide.com',
|
||||
days: 2,
|
||||
request: {
|
||||
cache: {
|
||||
ttl: 24 * 60 * 60 * 1000 // 1 day
|
||||
}
|
||||
},
|
||||
async url({ date, segment = 1 }) {
|
||||
const params = []
|
||||
if (module.exports.apiKey === undefined) {
|
||||
module.exports.apiKey = await module.exports.fetchApiKey()
|
||||
debug('Got api key', module.exports.apiKey)
|
||||
}
|
||||
if (date) {
|
||||
if (segment > 1) {
|
||||
date = date.add((segment - 1) * maxDuration, 'm')
|
||||
}
|
||||
params.push(`start=${date.unix()}`, `duration=${maxDuration}`)
|
||||
}
|
||||
params.push(`apiKey=${module.exports.apiKey}`)
|
||||
|
||||
return date ?
|
||||
`https://backend.tvguide.com/tvschedules/tvguide/${providerId}/web?${params.join('&')}` :
|
||||
`https://backend.tvguide.com/tvschedules/tvguide/serviceprovider/${providerId}/sources/web?${params.join('&')}`
|
||||
},
|
||||
async parser({ content, date, channel }) {
|
||||
const programs = []
|
||||
const f = data => {
|
||||
const result = []
|
||||
if (typeof data === 'string') {
|
||||
data = JSON.parse(data)
|
||||
}
|
||||
if (data && Array.isArray(data?.data?.items)) {
|
||||
data.data.items
|
||||
.filter(i => i.channel.sourceId.toString() === channel.site_id)
|
||||
.forEach(i => {
|
||||
result.push(...i.programSchedules.map(p => {
|
||||
return { i: p, url: p.programDetails }
|
||||
}))
|
||||
})
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
const queues = f(content)
|
||||
if (queues.length) {
|
||||
const parts = []
|
||||
for (let i = 2; i <= segments; i++) {
|
||||
parts.push(await module.exports.url({ date, segment: i }))
|
||||
}
|
||||
await doFetch(parts, (url, res) => {
|
||||
queues.push(...f(res))
|
||||
})
|
||||
await doFetch(queues, (queue, res) => {
|
||||
const item = res?.data?.item ? res.data.item : queue.i
|
||||
programs.push({
|
||||
title: item.title ? item.title : queue.i.title,
|
||||
sub_title: item.episodeNumber ? item.episodeTitle : null,
|
||||
description: item.description,
|
||||
season: item.seasonNumber,
|
||||
episode: item.episodeNumber,
|
||||
rating: item.rating ? { system: 'MPA', value: item.rating } : null,
|
||||
categories: Array.isArray(item.genres) ? item.genres.map(g => g.name) : null,
|
||||
start: dayjs.unix(item.startTime ? item.startTime : queue.i.startTime),
|
||||
stop: dayjs.unix(item.endTime ? item.endTime : queue.i.endTime)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
return programs
|
||||
},
|
||||
async channels() {
|
||||
const channels = []
|
||||
const data = await axios
|
||||
.get(await this.url({}))
|
||||
.then(r => r.data)
|
||||
.catch(console.error)
|
||||
|
||||
data.data.items.forEach(item => {
|
||||
channels.push({
|
||||
lang: 'en',
|
||||
site_id: item.sourceId,
|
||||
name: item.fullName.replace(/Channel|Schedule/g, '').trim()
|
||||
})
|
||||
})
|
||||
|
||||
return channels
|
||||
},
|
||||
async fetchApiKey() {
|
||||
const data = await axios
|
||||
.get('https://www.tvguide.com/listings/')
|
||||
.then(r => r.data)
|
||||
.catch(console.error)
|
||||
|
||||
return data ? data.match(/apiKey=([a-zA-Z0-9]+)&/)[1] : null
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,95 +1,95 @@
|
||||
const { parser, url } = require('./tvguide.com.config.js')
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const axios = require('axios')
|
||||
const dayjs = require('dayjs')
|
||||
const utc = require('dayjs/plugin/utc')
|
||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||
|
||||
dayjs.extend(customParseFormat)
|
||||
dayjs.extend(utc)
|
||||
|
||||
jest.mock('axios')
|
||||
|
||||
const date = dayjs.utc('2025-01-12', 'YYYY-MM-DD').startOf('d')
|
||||
const channel = {
|
||||
site_id: '9200018514',
|
||||
xmltv_id: 'CBSEast.us'
|
||||
}
|
||||
|
||||
axios.get.mockImplementation(url => {
|
||||
const result = {}
|
||||
const urls = {
|
||||
'https://www.tvguide.com/listings/':
|
||||
'content.html',
|
||||
'https://backend.tvguide.com/tvschedules/tvguide/9100001138/web?start=1736640000&duration=240&apiKey=DI9elXhZ3bU6ujsA2gXEKOANyncXGUGc':
|
||||
'content1.json',
|
||||
'https://backend.tvguide.com/tvschedules/tvguide/9100001138/web?start=1736654400&duration=240&apiKey=DI9elXhZ3bU6ujsA2gXEKOANyncXGUGc':
|
||||
'content2.json',
|
||||
'https://backend.tvguide.com/tvschedules/tvguide/programdetails/9000351140/web':
|
||||
'program1.json',
|
||||
'https://backend.tvguide.com/tvschedules/tvguide/programdetails/9000000408/web':
|
||||
'program2.json',
|
||||
}
|
||||
if (urls[url] !== undefined) {
|
||||
result.data = fs.readFileSync(path.join(__dirname, '__data__', urls[url])).toString()
|
||||
if (!urls[url].startsWith('content1') && !urls[url].endsWith('.html')) {
|
||||
result.data = JSON.parse(result.data)
|
||||
}
|
||||
}
|
||||
|
||||
return Promise.resolve(result)
|
||||
})
|
||||
|
||||
it('can generate valid url', async () => {
|
||||
expect(await url({ date })).toBe(
|
||||
'https://backend.tvguide.com/tvschedules/tvguide/9100001138/web?start=1736640000&duration=240&apiKey=DI9elXhZ3bU6ujsA2gXEKOANyncXGUGc'
|
||||
)
|
||||
})
|
||||
|
||||
it('can parse response', async () => {
|
||||
const content = fs.readFileSync(path.join(__dirname, '__data__', 'content1.json')).toString()
|
||||
const results = (await parser({ content, channel, date })).map(p => {
|
||||
p.start = p.start.toJSON()
|
||||
p.stop = p.stop.toJSON()
|
||||
return p
|
||||
})
|
||||
|
||||
expect(results.length).toBe(5)
|
||||
expect(results[0]).toMatchObject({
|
||||
start: '2025-01-12T01:00:00.000Z',
|
||||
stop: '2025-01-12T02:00:00.000Z',
|
||||
title: 'FBI: International',
|
||||
sub_title: 'Gift',
|
||||
description:
|
||||
'The owner of a prominent cyber security company is murdered in Copenhagen just before a massive data leak surfaces online, leading the NSA to ask the team for assistance in catching the killer and leaker before more data is revealed.',
|
||||
categories: ['Action & Adventure', 'Suspense', 'Drama'],
|
||||
season: 3,
|
||||
episode: 12,
|
||||
rating: {
|
||||
system: 'MPA',
|
||||
value: 'L'
|
||||
}
|
||||
})
|
||||
expect(results[4]).toMatchObject({
|
||||
start: '2025-01-12T06:00:00.000Z',
|
||||
stop: '2025-01-12T08:00:00.000Z',
|
||||
title: 'Local Programs',
|
||||
description:
|
||||
'Local programming information.',
|
||||
categories: [],
|
||||
rating: {
|
||||
system: 'MPA',
|
||||
value: 'L'
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
it('can handle empty guide', async () => {
|
||||
const results = await parser({
|
||||
date,
|
||||
channel,
|
||||
content: fs.readFileSync(path.join(__dirname, '__data__', 'no-content.json')).toString()
|
||||
})
|
||||
expect(results).toMatchObject([])
|
||||
})
|
||||
const { parser, url } = require('./tvguide.com.config.js')
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const axios = require('axios')
|
||||
const dayjs = require('dayjs')
|
||||
const utc = require('dayjs/plugin/utc')
|
||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||
|
||||
dayjs.extend(customParseFormat)
|
||||
dayjs.extend(utc)
|
||||
|
||||
jest.mock('axios')
|
||||
|
||||
const date = dayjs.utc('2025-01-12', 'YYYY-MM-DD').startOf('d')
|
||||
const channel = {
|
||||
site_id: '9200018514',
|
||||
xmltv_id: 'CBSEast.us'
|
||||
}
|
||||
|
||||
axios.get.mockImplementation(url => {
|
||||
const result = {}
|
||||
const urls = {
|
||||
'https://www.tvguide.com/listings/':
|
||||
'content.html',
|
||||
'https://backend.tvguide.com/tvschedules/tvguide/9100001138/web?start=1736640000&duration=240&apiKey=DI9elXhZ3bU6ujsA2gXEKOANyncXGUGc':
|
||||
'content1.json',
|
||||
'https://backend.tvguide.com/tvschedules/tvguide/9100001138/web?start=1736654400&duration=240&apiKey=DI9elXhZ3bU6ujsA2gXEKOANyncXGUGc':
|
||||
'content2.json',
|
||||
'https://backend.tvguide.com/tvschedules/tvguide/programdetails/9000351140/web':
|
||||
'program1.json',
|
||||
'https://backend.tvguide.com/tvschedules/tvguide/programdetails/9000000408/web':
|
||||
'program2.json',
|
||||
}
|
||||
if (urls[url] !== undefined) {
|
||||
result.data = fs.readFileSync(path.join(__dirname, '__data__', urls[url])).toString()
|
||||
if (!urls[url].startsWith('content1') && !urls[url].endsWith('.html')) {
|
||||
result.data = JSON.parse(result.data)
|
||||
}
|
||||
}
|
||||
|
||||
return Promise.resolve(result)
|
||||
})
|
||||
|
||||
it('can generate valid url', async () => {
|
||||
expect(await url({ date })).toBe(
|
||||
'https://backend.tvguide.com/tvschedules/tvguide/9100001138/web?start=1736640000&duration=240&apiKey=DI9elXhZ3bU6ujsA2gXEKOANyncXGUGc'
|
||||
)
|
||||
})
|
||||
|
||||
it('can parse response', async () => {
|
||||
const content = fs.readFileSync(path.join(__dirname, '__data__', 'content1.json')).toString()
|
||||
const results = (await parser({ content, channel, date })).map(p => {
|
||||
p.start = p.start.toJSON()
|
||||
p.stop = p.stop.toJSON()
|
||||
return p
|
||||
})
|
||||
|
||||
expect(results.length).toBe(5)
|
||||
expect(results[0]).toMatchObject({
|
||||
start: '2025-01-12T01:00:00.000Z',
|
||||
stop: '2025-01-12T02:00:00.000Z',
|
||||
title: 'FBI: International',
|
||||
sub_title: 'Gift',
|
||||
description:
|
||||
'The owner of a prominent cyber security company is murdered in Copenhagen just before a massive data leak surfaces online, leading the NSA to ask the team for assistance in catching the killer and leaker before more data is revealed.',
|
||||
categories: ['Action & Adventure', 'Suspense', 'Drama'],
|
||||
season: 3,
|
||||
episode: 12,
|
||||
rating: {
|
||||
system: 'MPA',
|
||||
value: 'L'
|
||||
}
|
||||
})
|
||||
expect(results[4]).toMatchObject({
|
||||
start: '2025-01-12T06:00:00.000Z',
|
||||
stop: '2025-01-12T08:00:00.000Z',
|
||||
title: 'Local Programs',
|
||||
description:
|
||||
'Local programming information.',
|
||||
categories: [],
|
||||
rating: {
|
||||
system: 'MPA',
|
||||
value: 'L'
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
it('can handle empty guide', async () => {
|
||||
const results = await parser({
|
||||
date,
|
||||
channel,
|
||||
content: fs.readFileSync(path.join(__dirname, '__data__', 'no-content.json')).toString()
|
||||
})
|
||||
expect(results).toMatchObject([])
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user