mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-09 08:30:06 -04:00
Create scripts/templates
This commit is contained in:
parent
6285025a53
commit
3e6fb2b1d3
3 changed files with 79 additions and 0 deletions
16
scripts/templates/_config.js
Normal file
16
scripts/templates/_config.js
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
module.exports = {
|
||||||
|
site: '<DOMAIN>',
|
||||||
|
url({ channel, date }) {
|
||||||
|
return `https://example.com/api/${channel.site_id}/${date.format('YYYY-MM-DD')}`
|
||||||
|
},
|
||||||
|
parser({ content }) {
|
||||||
|
try {
|
||||||
|
return JSON.parse(content)
|
||||||
|
} catch {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
},
|
||||||
|
channels() {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
}
|
21
scripts/templates/_readme.md
Normal file
21
scripts/templates/_readme.md
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
# <DOMAIN>
|
||||||
|
|
||||||
|
https://example.com
|
||||||
|
|
||||||
|
### Download the guide
|
||||||
|
|
||||||
|
```sh
|
||||||
|
npm run grab --- --site=<DOMAIN>
|
||||||
|
```
|
||||||
|
|
||||||
|
### Update channel list
|
||||||
|
|
||||||
|
```sh
|
||||||
|
npm run channels:parse --- --config=./sites/<DOMAIN>/<DOMAIN>.config.js --output=./sites/<DOMAIN>/<DOMAIN>.channels.xml
|
||||||
|
```
|
||||||
|
|
||||||
|
### Test
|
||||||
|
|
||||||
|
```sh
|
||||||
|
npm test --- <DOMAIN>
|
||||||
|
```
|
42
scripts/templates/_test.js
Normal file
42
scripts/templates/_test.js
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
const { parser, url } = require('./<DOMAIN>.config.js')
|
||||||
|
const dayjs = require('dayjs')
|
||||||
|
const utc = require('dayjs/plugin/utc')
|
||||||
|
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||||
|
dayjs.extend(customParseFormat)
|
||||||
|
dayjs.extend(utc)
|
||||||
|
|
||||||
|
const date = dayjs.utc('2025-01-12', 'YYYY-MM-DD').startOf('d')
|
||||||
|
const channel = { site_id: 'bbc1', xmltv_id: 'BBCOne.uk' }
|
||||||
|
|
||||||
|
it('can generate valid url', () => {
|
||||||
|
expect(url({ channel, date })).toBe('https://example.com/api/bbc1/2025-01-12')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('can parse response', () => {
|
||||||
|
const content =
|
||||||
|
'[{"title":"Program 1","start":"2025-01-12T00:00:00.000Z","stop":"2025-01-12T00:30:00.000Z"},{"title":"Program 2","start":"2025-01-12T00:30:00.000Z","stop":"2025-01-12T01:00:00.000Z"}]'
|
||||||
|
|
||||||
|
const results = parser({ content })
|
||||||
|
|
||||||
|
expect(results.length).toBe(2)
|
||||||
|
expect(results[0]).toMatchObject({
|
||||||
|
title: 'Program 1',
|
||||||
|
start: '2025-01-12T00:00:00.000Z',
|
||||||
|
stop: '2025-01-12T00:30:00.000Z'
|
||||||
|
})
|
||||||
|
expect(results[1]).toMatchObject({
|
||||||
|
title: 'Program 2',
|
||||||
|
start: '2025-01-12T00:30:00.000Z',
|
||||||
|
stop: '2025-01-12T01:00:00.000Z'
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('can handle empty guide', () => {
|
||||||
|
const result = parser({
|
||||||
|
date,
|
||||||
|
channel,
|
||||||
|
content: ''
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(result).toMatchObject([])
|
||||||
|
})
|
Loading…
Add table
Add a link
Reference in a new issue