mirror of
https://github.com/iptv-org/epg
synced 2025-12-16 10:26:41 -05:00
Test: ```sh npm test -- programme.tvb.com > test > run-script-os programme.tvb.com > test:win32 > SET "TZ=Pacific/Nauru" && npx jest --runInBand programme.tvb.com PASS sites/programme.tvb.com/programme.tvb.com.test.js (5.14 s) √ can generate valid url (4 ms) √ can parse response (en) (41 ms) √ can parse response (zh) (2 ms) √ can handle empty guide (1 ms) Test Suites: 1 passed, 1 total Tests: 4 passed, 4 total Snapshots: 0 total Time: 5.391 s Ran all test suites matching /programme.tvb.com/i. ``` Grab: ```sh npm run grab -- --site=programme.tvb.com --lang=en > grab > npx tsx scripts/commands/epg/grab.ts --site=programme.tvb.com --lang=en starting... config: output: guide.xml maxConnections: 1 gzip: false site: programme.tvb.com lang: en loading channels... found 4 channel(s) run #1: [1/8] programme.tvb.com (en) - B - Dec 6, 2024 (37 programs) [2/8] programme.tvb.com (en) - B - Dec 7, 2024 (33 programs) [3/8] programme.tvb.com (en) - TVBNewsChannel.hk - Dec 7, 2024 (48 programs) [4/8] programme.tvb.com (en) - TVBNewsChannel.hk - Dec 6, 2024 (50 programs) [5/8] programme.tvb.com (en) - Pearl.hk - Dec 7, 2024 (32 programs) [6/8] programme.tvb.com (en) - Pearl.hk - Dec 6, 2024 (37 programs) [7/8] programme.tvb.com (en) - Jade.hk - Dec 7, 2024 (36 programs) [8/8] programme.tvb.com (en) - Jade.hk - Dec 6, 2024 (48 programs) saving to "guide.xml"... done in 00h 00m 03s ``` Signed-off-by: Toha <tohenk@yahoo.com>
65 lines
2.3 KiB
JavaScript
65 lines
2.3 KiB
JavaScript
const { parser, url } = require('./programme.tvb.com.config.js')
|
|
const fs = require('fs')
|
|
const path = require('path')
|
|
const dayjs = require('dayjs')
|
|
const utc = require('dayjs/plugin/utc')
|
|
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
|
|
|
dayjs.extend(customParseFormat)
|
|
dayjs.extend(utc)
|
|
|
|
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.json'))
|
|
const date = dayjs.utc('2024-12-06', 'YYYY-MM-DD').startOf('d')
|
|
const channel = {
|
|
site_id: 'J',
|
|
xmltv_id: 'Jade.hk',
|
|
lang: 'en'
|
|
}
|
|
|
|
it('can generate valid url', () => {
|
|
const time = 1733491000
|
|
expect(url({ channel, date, time })).toBe(
|
|
'https://programme.tvb.com/api/schedule?input_date=20241206&network_code=J&_t=1733491000'
|
|
)
|
|
})
|
|
|
|
it('can parse response (en)', () => {
|
|
const results = parser({ content, channel, date }).map(p => {
|
|
p.start = p.start.toJSON()
|
|
p.stop = p.stop.toJSON()
|
|
return p
|
|
})
|
|
|
|
expect(results.length).toBe(3)
|
|
expect(results[1]).toMatchObject({
|
|
start: '2024-12-06T15:55:00.000Z',
|
|
stop: '2024-12-06T16:55:00.000Z',
|
|
title: 'Line Walker: Bull Fight#16[Can][PG]',
|
|
})
|
|
})
|
|
|
|
it('can parse response (zh)', () => {
|
|
const results = parser({ content, channel: { ...channel, lang: 'zh' }, date }).map(p => {
|
|
p.start = p.start.toJSON()
|
|
p.stop = p.stop.toJSON()
|
|
return p
|
|
})
|
|
|
|
expect(results.length).toBe(3)
|
|
expect(results[1]).toMatchObject({
|
|
start: '2024-12-06T15:55:00.000Z',
|
|
stop: '2024-12-06T16:55:00.000Z',
|
|
title: '使徒行者3#16[粵][PG]',
|
|
description:
|
|
'文鼎從淑梅手上救走大聖爺兒子,大聖爺還恩於歡喜,答允支持九指強。崇聯社定下選舉日子,恰巧是韋傑出獄之日,頭目們顧念舊日恩義,紛紛轉投浩洋。浩洋帶亞希逛傢俬店,憧憬二人未來。亞希向家強承認愛上浩洋,要求退出臥底任務。作榮與歡喜暗中會面,將國際犯罪組織「永恆幫」情報交給他。阿火遭家強出賣,到沐足店搶錢。家強逮住阿火,惟被合星誤會而受拘捕。家強把正植遺下的頸鏈和學生證交還,合星意識到家強已知悉正植身世。',
|
|
})
|
|
})
|
|
|
|
it('can handle empty guide', () => {
|
|
const result = parser({
|
|
content: '',
|
|
date
|
|
})
|
|
expect(result).toMatchObject([])
|
|
})
|