mirror of
https://github.com/iptv-org/epg
synced 2026-04-22 10:37:02 -04:00
Update tvguide.com guide.
Test: ```sh npm test --- tvguide.com > test > run-script-os tvguide.com > test:win32 > SET "TZ=Pacific/Nauru" && npx jest --runInBand tvguide.com PASS sites/tvguide.com/tvguide.com.test.js √ can generate valid url (4 ms) √ can parse response (5 ms) √ can handle empty guide (1 ms) Test Suites: 1 passed, 1 total Tests: 3 passed, 3 total Snapshots: 0 total Time: 0.567 s, estimated 1 s Ran all test suites matching /tvguide.com/i. ``` Grab: ```sh npm run grab --- --site=tvguide.com > grab > npx tsx scripts/commands/epg/grab.ts --site=tvguide.com starting... config: output: guide.xml maxConnections: 1 gzip: false site: tvguide.com loading channels... found 1 channel(s) run #1: [1/2] tvguide.com (es) - UnivisionEast.us - Jan 12, 2025 (33 programs) [2/2] tvguide.com (es) - UnivisionEast.us - Jan 13, 2025 (25 programs) saving to "guide.xml"... done in 00h 00m 05s ``` Signed-off-by: Toha <tohenk@yahoo.com>
This commit is contained in:
@@ -5,59 +5,82 @@ 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('2022-10-30', 'YYYY-MM-DD').startOf('d')
|
||||
const date = dayjs.utc('2025-01-12', 'YYYY-MM-DD').startOf('d')
|
||||
const channel = {
|
||||
site_id: '9100001138#9200018514',
|
||||
site_id: '9200018514',
|
||||
xmltv_id: 'CBSEast.us'
|
||||
}
|
||||
|
||||
it('can generate valid url', () => {
|
||||
expect(url({ date, channel })).toBe(
|
||||
'https://internal-prod.apigee.fandom.net/v1/xapi/tvschedules/tvguide/9100001138/web?start=1667088000&duration=1440&channelSourceIds=9200018514'
|
||||
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.resolve(__dirname, '__data__/content.json'))
|
||||
|
||||
axios.get.mockImplementation(url => {
|
||||
if (
|
||||
url ===
|
||||
'https://fandom-prod.apigee.net/v1/xapi/tvschedules/tvguide/programdetails/6060613824/web'
|
||||
) {
|
||||
return Promise.resolve({
|
||||
data: JSON.parse(fs.readFileSync(path.resolve(__dirname, '__data__/program.json')))
|
||||
})
|
||||
} else {
|
||||
return Promise.resolve({ data: '' })
|
||||
}
|
||||
})
|
||||
|
||||
let results = await parser({ content, channel, date })
|
||||
results = results.map(p => {
|
||||
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[5]).toMatchObject({
|
||||
start: '2022-10-30T13:00:00.000Z',
|
||||
stop: '2022-10-30T14:30:00.000Z',
|
||||
title: 'CBS Sunday Morning',
|
||||
sub_title: '10-30-2022',
|
||||
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 Backseat Lovers perform on the "Saturday Sessions"; and Daisy Ryan guests on "The Dish." Also: comedian Fortune Feimster.',
|
||||
categories: ['Talk & Interview', 'Other'],
|
||||
season: 40,
|
||||
episode: 248,
|
||||
'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: 'TV-PG'
|
||||
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'
|
||||
}
|
||||
})
|
||||
})
|
||||
@@ -66,7 +89,7 @@ it('can handle empty guide', async () => {
|
||||
const results = await parser({
|
||||
date,
|
||||
channel,
|
||||
content: fs.readFileSync(path.resolve(__dirname, '__data__/no-content.json'))
|
||||
content: fs.readFileSync(path.join(__dirname, '__data__', 'no-content.json')).toString()
|
||||
})
|
||||
expect(results).toMatchObject([])
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user