mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-10 09:00:07 -04:00
commit
6fb526311a
6 changed files with 23 additions and 7 deletions
|
@ -51,6 +51,12 @@ To download a guide in a specific language pass its [ISO 639-1](https://en.wikip
|
||||||
npm run grab -- --site=example.com --lang=fr
|
npm run grab -- --site=example.com --lang=fr
|
||||||
```
|
```
|
||||||
|
|
||||||
|
To override the number of days for which the program will be loaded use the `--days` argument (the default is the value specified in the site config):
|
||||||
|
|
||||||
|
```sh
|
||||||
|
npm run grab -- --site=example.com --days=3
|
||||||
|
```
|
||||||
|
|
||||||
To also create a compressed version of the guide, add the `--gzip` flag:
|
To also create a compressed version of the guide, add the `--gzip` flag:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
|
|
|
@ -11,8 +11,9 @@
|
||||||
"test:commands": "npx jest --runInBand -- commands",
|
"test:commands": "npx jest --runInBand -- commands",
|
||||||
"test:sites": "TZ=Pacific/Nauru npx jest --runInBand -- sites",
|
"test:sites": "TZ=Pacific/Nauru npx jest --runInBand -- sites",
|
||||||
"check": "npm run api:load && npm run channels:lint sites/**/*.js && npm run channels:validate sites/**/*.xml",
|
"check": "npm run api:load && npm run channels:lint sites/**/*.js && npm run channels:validate sites/**/*.xml",
|
||||||
"grab": "npm run api:load && node scripts/commands/epg/grab.js",
|
"grab": "node scripts/commands/epg/grab.js",
|
||||||
"serve": "npx serve"
|
"serve": "npx serve",
|
||||||
|
"postinstall": "npm run api:load"
|
||||||
},
|
},
|
||||||
"private": true,
|
"private": true,
|
||||||
"author": "Arhey",
|
"author": "Arhey",
|
||||||
|
|
|
@ -16,6 +16,7 @@ program
|
||||||
.requiredOption('-s, --site <name>', 'Name of the site to parse')
|
.requiredOption('-s, --site <name>', 'Name of the site to parse')
|
||||||
.option('-l, --lang <code>', 'Filter channels by language (ISO 639-2 code)')
|
.option('-l, --lang <code>', 'Filter channels by language (ISO 639-2 code)')
|
||||||
.option('-o, --output <path>', 'Path to output file')
|
.option('-o, --output <path>', 'Path to output file')
|
||||||
|
.option('--days <days>', 'Override the number of days for which the program will be loaded')
|
||||||
.option('--cron <expression>', 'Schedule a script run')
|
.option('--cron <expression>', 'Schedule a script run')
|
||||||
.option('--gzip', 'Create a compressed version of the guide as well', false)
|
.option('--gzip', 'Create a compressed version of the guide as well', false)
|
||||||
.parse(process.argv)
|
.parse(process.argv)
|
||||||
|
@ -123,13 +124,14 @@ async function createQueue(channelsPath, config) {
|
||||||
await api.channels.load().catch(logger.error)
|
await api.channels.load().catch(logger.error)
|
||||||
const files = await file.list(channelsPath).catch(logger.error)
|
const files = await file.list(channelsPath).catch(logger.error)
|
||||||
const utcDate = date.getUTC(CURR_DATE)
|
const utcDate = date.getUTC(CURR_DATE)
|
||||||
|
const days = options.days ? parseInt(options.days) : config.days
|
||||||
for (const filepath of files) {
|
for (const filepath of files) {
|
||||||
logger.info(` loading "${filepath}"...`)
|
logger.info(` loading "${filepath}"...`)
|
||||||
try {
|
try {
|
||||||
const dir = file.dirname(filepath)
|
const dir = file.dirname(filepath)
|
||||||
const { channels } = await parser.parseChannels(filepath)
|
const { channels } = await parser.parseChannels(filepath)
|
||||||
const filename = file.basename(filepath)
|
const filename = file.basename(filepath)
|
||||||
const dates = Array.from({ length: config.days }, (_, i) => utcDate.add(i, 'd'))
|
const dates = Array.from({ length: days }, (_, i) => utcDate.add(i, 'd'))
|
||||||
for (const channel of channels) {
|
for (const channel of channels) {
|
||||||
if (!channel.site || !channel.xmltv_id) continue
|
if (!channel.site || !channel.xmltv_id) continue
|
||||||
if (options.lang && channel.lang !== options.lang) continue
|
if (options.lang && channel.lang !== options.lang) continue
|
||||||
|
@ -194,8 +196,8 @@ async function save(template, parsedChannels, programs = []) {
|
||||||
output.programs.push(new Program(program, channel))
|
output.programs.push(new Program(program, channel))
|
||||||
}
|
}
|
||||||
|
|
||||||
output.channels = _.sortBy(output.channels, 'id')
|
output.channels = _.sortBy(output.channels, 'xmltv_id')
|
||||||
output.channels = _.uniqBy(output.channels, 'id')
|
output.channels = _.uniqBy(output.channels, 'xmltv_id')
|
||||||
|
|
||||||
output.programs = _.sortBy(output.programs, ['channel', 'start'])
|
output.programs = _.sortBy(output.programs, ['channel', 'start'])
|
||||||
output.programs = _.uniqBy(output.programs, p => p.channel + p.start)
|
output.programs = _.uniqBy(output.programs, p => p.channel + p.start)
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?xml version="1.0" encoding="UTF-8" ?><tv date="20221020">
|
<?xml version="1.0" encoding="UTF-8" ?><tv date="20221020">
|
||||||
<channel id="Channel1.us"><display-name>Channel 1</display-name><url>https://example.com</url></channel>
|
<channel id="Channel1.us"><display-name>Channel 1</display-name><url>https://example.com</url></channel>
|
||||||
|
<channel id="Channel2.us"><display-name>Channel 2</display-name><url>https://example.com</url></channel>
|
||||||
<programme start="20220306043000 +0000" stop="20220306071000 +0000" channel="Channel1.us"><title lang="en">Program1</title></programme>
|
<programme start="20220306043000 +0000" stop="20220306071000 +0000" channel="Channel1.us"><title lang="en">Program1</title></programme>
|
||||||
</tv>
|
</tv>
|
|
@ -2,6 +2,7 @@
|
||||||
<site site="example.com">
|
<site site="example.com">
|
||||||
<channels>
|
<channels>
|
||||||
<channel lang="en" xmltv_id="Channel1.us" site_id="140">Channel 1</channel>
|
<channel lang="en" xmltv_id="Channel1.us" site_id="140">Channel 1</channel>
|
||||||
|
<channel lang="en" xmltv_id="Channel2.us" site_id="142">Channel 2</channel>
|
||||||
<channel lang="fr" xmltv_id="Channel1.us" site_id="140">Channel 1</channel>
|
<channel lang="fr" xmltv_id="Channel1.us" site_id="140">Channel 1</channel>
|
||||||
</channels>
|
</channels>
|
||||||
</site>
|
</site>
|
|
@ -1,10 +1,15 @@
|
||||||
module.exports = {
|
module.exports = {
|
||||||
site: 'example.com',
|
site: 'example.com',
|
||||||
days: 2,
|
days: 1,
|
||||||
|
request: {
|
||||||
|
timeout: 1000
|
||||||
|
},
|
||||||
url() {
|
url() {
|
||||||
return `https://example.com`
|
return `https://example.com`
|
||||||
},
|
},
|
||||||
parser() {
|
parser({ channel }) {
|
||||||
|
if (channel.xmltv_id === 'Channel2.us') return []
|
||||||
|
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
title: 'Program1',
|
title: 'Program1',
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue