Files
epg/sites/tivie.id/tivie.id.test.js
Toha d7b281304b Add site tivie.id.
Test:

```sh
npm test --- tivie.id

> test
> run-script-os tivie.id

> test:win32
> SET "TZ=Pacific/Nauru" && npx jest --runInBand tivie.id

 PASS  sites/tivie.id/tivie.id.test.js
  √ can generate valid url (4 ms)
  √ can parse response (767 ms)
  √ can handle empty guide (1 ms)

Test Suites: 1 passed, 1 total
Tests:       3 passed, 3 total
Snapshots:   0 total
Time:        5.273 s, estimated 6 s
Ran all test suites matching /tivie.id/i.
```

Grab:

```sh
npm run grab --- --site=tivie.id

> grab
> npx tsx scripts/commands/epg/grab.ts --site=tivie.id

starting...
config:
  output: guide.xml
  maxConnections: 1
  gzip: false
  site: tivie.id
loading channels...
  found 50 channel(s)
run #1:
Unable to fetch https://tivie.id/film/as%cc%85oka-nwzDnwvClgf4: Request failed with status code 404!
  [1/100] tivie.id (id) - ANTV.id - Dec 31, 2024 (15 programs)
  [2/100] tivie.id (id) - ANTV.id - Jan 1, 2025 (13 programs)
  ...
  [99/100] tivie.id (id) - SindoNewsTV.id - Dec 31, 2024 (22 programs)
  [100/100] tivie.id (id) - SEAToday.id - Jan 1, 2025 (37 programs)
  saving to "guide.xml"...
  done in 00h 08m 58s
```

Signed-off-by: Toha <tohenk@yahoo.com>
2025-01-01 00:19:15 +07:00

78 lines
2.4 KiB
JavaScript

const { parser, url } = require('./tivie.id.config')
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('2024-12-31').startOf('d')
const channel = {
site_id: 'axn',
xmltv_id: 'AXN.id',
lang: 'id'
}
axios.get.mockImplementation(url => {
const urls = {
'https://tivie.id/film/white-house-down-nwzDnwz9nAv6':
'program01.html',
'https://tivie.id/program/hudson-rex-s6-e14-nwzDnwvBmQr9':
'program02.html',
}
let data = ''
if (urls[url] !== undefined) {
data = fs.readFileSync(path.join(__dirname, '__data__', urls[url])).toString()
}
return Promise.resolve({ data })
})
it('can generate valid url', () => {
expect(url({ channel, date })).toBe('https://tivie.id/channel/axn/20241231')
})
it('can parse response', async () => {
const content = fs.readFileSync(path.join(__dirname, '__data__', 'content.html'))
const results = (
await parser({ date, content, channel })
).map(p => {
p.start = p.start.toJSON()
p.stop = p.stop.toJSON()
return p
})
expect(results.length).toBe(27)
expect(results[0]).toMatchObject({
start: '2024-12-30T17:00:00.000Z',
stop: '2024-12-30T17:05:00.000Z',
title: 'White House Down',
description:
'Saat melakukan tur di Gedung Putih bersama putrinya yang masih kecil, seorang perwira polisi beraksi untuk melindungi anaknya dan presiden dari sekelompok penjajah paramiliter bersenjata lengkap.',
image: 'https://i0.wp.com/is3.cloudhost.id/tivie/poster/2023/09/65116c78791c2-1695640694.jpg?resize=480,270',
})
expect(results[2]).toMatchObject({
start: '2024-12-30T18:00:00.000Z',
stop: '2024-12-30T18:55:00.000Z',
title: 'Hudson & Rex S6, Ep. 14',
description:
'Saat guru musik Jesse terbunuh di studio rekamannya, Charlie dan Rex menghubungkan kejahatan tersebut dengan pembunuhan yang tampaknya tak ada hubungannya.',
image: 'https://i0.wp.com/is3.cloudhost.id/tivie/poster/2024/07/668b7ced47b25-1720417517.jpg?resize=480,270',
season: 6,
episode: 14,
})
})
it('can handle empty guide', async () => {
const results = await parser({
date,
channel,
content: '',
})
expect(results).toMatchObject([])
})