Merge pull request #2743 from iptv-org/patch-2025.03.1

Patch 2025.03.1
This commit is contained in:
PopeyeTheSai10r 2025-04-02 19:01:26 -07:00 committed by GitHub
commit 4df25c92bc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 2512 additions and 114 deletions

View file

@ -39,13 +39,15 @@ npm install
## Usage ## Usage
To start the download of the guide, select one of the [supported sites](SITES.md) and paste its name into the command below: To start the download of the guide, select one of the supported sites from [SITES.md](SITES.md) file and paste its name into the command below:
```sh ```sh
npm run grab --- --site=example.com npm run grab --- --site=example.com
``` ```
And once the download is complete, the guide will be saved to the `guide.xml` file. Then run it and wait for the guide to finish downloading. When finished, a new `guide.xml` file will appear in the current directory.
You can also customize the behavior of the script using this options:
```sh ```sh
Usage: npm run grab --- [options] Usage: npm run grab --- [options]
@ -55,35 +57,13 @@ Options:
-c, --channels <path> Path to *.channels.xml file (required if the "--site" attribute is -c, --channels <path> Path to *.channels.xml file (required if the "--site" attribute is
not specified) not specified)
-o, --output <path> Path to output file (default: "guide.xml") -o, --output <path> Path to output file (default: "guide.xml")
-l, --lang <code> Filter channels by language (ISO 639-2 code) -l, --lang <code> Allows to limit the download to channels in the specified language only (ISO 639-1 code)
-t, --timeout <milliseconds> Override the default timeout for each request -t, --timeout <milliseconds> Timeout for each request in milliseconds (default: 0)
-d, --delay <milliseconds> Override the default delay between request -d, --delay <milliseconds> Delay between request in milliseconds (default: 0)
-x, --proxy <url> Use the specified proxy (example: "socks5://username:password@127.0.0.1:1234") -x, --proxy <url> Use the specified proxy (example: "socks5://username:password@127.0.0.1:1234")
--days <days> Override the number of days for which the program will be loaded --days <days> Number of days for which the program will be loaded (defaults to the value from the site config)
(defaults to the value from the site config) --maxConnections <number> Number of concurrent requests (default: 1)
--maxConnections <number> Limit on the number of concurrent requests (default: 1) --gzip Specifies whether or not to create a compressed version of the guide (default: false)
--cron <expression> Schedule a script run (example: "0 0 * * *")
--gzip Create a compressed version of the guide as well (default: false)
```
### Access the guide by URL
You can make the guide available via URL by running your own server:
```sh
npm run serve
```
After that, the guide will be available at the link:
```
http://localhost:3000/guide.xml
```
In addition it will be available to other devices on the same local network at the address:
```
http://<your_local_ip_address>:3000/guide.xml
``` ```
### Parallel downloading ### Parallel downloading
@ -116,12 +96,42 @@ npm run grab --- --channels=path/to/custom.channels.xml
### Run on schedule ### Run on schedule
If you want to download the guide automatically on a schedule, you need to pass a valid [cron expression](https://crontab.guru/) to the script using the `--cron` attribute: To download the guide on a schedule, you can use the included process manager. Just run it with desire [cron expression](https://crontab.guru/) and the `grab` options:
```sh ```sh
npm run grab --- --site=example.com --cron="0 0 * * *" npx pm2 start npm --no-autorestart --cron-restart="0 0,12 * * *" -- run grab --- --site=example.com
``` ```
To track the process, you can use the command:
```sh
npx pm2 logs
```
For more info go to [pm2](https://pm2.keymetrics.io/docs/usage/quick-start/) documentation.
### Access the guide by URL
You can make the guide available via URL by running your own server. The easiest way to do this is to run this command:
```sh
npx serve
```
After that, the guide will be available at the link:
```
http://localhost:3000/guide.xml
```
In addition it will be available to other devices on the same local network at the address:
```
http://<your_local_ip_address>:3000/guide.xml
```
For more info go to [serve](https://github.com/vercel/serve) documentation.
## Update ## Update
If you have downloaded the repository code according to the instructions above, then to update it will be enough to run the command: If you have downloaded the repository code according to the instructions above, then to update it will be enough to run the command:

1785
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -12,7 +12,6 @@
"sites:init": "npx tsx scripts/commands/sites/init.ts", "sites:init": "npx tsx scripts/commands/sites/init.ts",
"sites:update": "npx tsx scripts/commands/sites/update.ts", "sites:update": "npx tsx scripts/commands/sites/update.ts",
"grab": "npx tsx scripts/commands/epg/grab.ts", "grab": "npx tsx scripts/commands/epg/grab.ts",
"serve": "npx serve",
"lint": "npx eslint \"{scripts,tests,sites}/**/*.{ts,mts,js}\"", "lint": "npx eslint \"{scripts,tests,sites}/**/*.{ts,mts,js}\"",
"test": "run-script-os", "test": "run-script-os",
"test:win32": "SET \"TZ=Pacific/Nauru\" && npx jest --runInBand", "test:win32": "SET \"TZ=Pacific/Nauru\" && npx jest --runInBand",
@ -63,7 +62,6 @@
"cli-progress": "^3.12.0", "cli-progress": "^3.12.0",
"commander": "^8.2.0", "commander": "^8.2.0",
"consola": "^3.2.3", "consola": "^3.2.3",
"cron": "^2.4.3",
"csv-parser": "^3.0.0", "csv-parser": "^3.0.0",
"cwait": "^1.1.2", "cwait": "^1.1.2",
"dayjs": "^1.11.10", "dayjs": "^1.11.10",
@ -93,6 +91,7 @@
"pako": "^2.1.0", "pako": "^2.1.0",
"parse-duration": "^1.0.0", "parse-duration": "^1.0.0",
"pdf-parse": "^1.1.1", "pdf-parse": "^1.1.1",
"pm2": "^5.4.3",
"readline": "^1.3.0", "readline": "^1.3.0",
"run-script-os": "^1.1.6", "run-script-os": "^1.1.6",
"serve": "^14.2.4", "serve": "^14.2.4",

23
pm2.config.js Normal file
View file

@ -0,0 +1,23 @@
module.exports = {
apps: [
{
name: 'serve',
script: 'npx serve -- public',
instances: 1,
watch: false,
autorestart: true
},
{
name: 'grab',
script: process.env.SITE
? `npm run grab -- --site=${process.env.SITE} ${
process.env.CLANG ? `--lang=${process.env.CLANG}` : ''
} --output=public/guide.xml`
: 'npm run grab -- --channels=channels.xml --output=public/guide.xml',
cron_restart: process.env.CRON || null,
instances: 1,
watch: false,
autorestart: false
}
]
}

View file

@ -1,35 +1,49 @@
import { Logger, Timer, Storage, Collection } from '@freearhey/core' import { Logger, Timer, Storage, Collection } from '@freearhey/core'
import { program } from 'commander' import { Option, program } from 'commander'
import { CronJob } from 'cron'
import { QueueCreator, Job, ChannelsParser } from '../../core' import { QueueCreator, Job, ChannelsParser } from '../../core'
import { Channel } from 'epg-grabber' import { Channel } from 'epg-grabber'
import path from 'path' import path from 'path'
import { SITES_DIR } from '../../constants' import { SITES_DIR } from '../../constants'
program program
.option('-s, --site <name>', 'Name of the site to parse') .addOption(new Option('-s, --site <name>', 'Name of the site to parse'))
.option( .addOption(
new Option(
'-c, --channels <path>', '-c, --channels <path>',
'Path to *.channels.xml file (required if the "--site" attribute is not specified)' 'Path to *.channels.xml file (required if the "--site" attribute is not specified)'
) )
.option('-o, --output <path>', 'Path to output file', 'guide.xml') )
.option('-l, --lang <code>', 'Filter channels by language (ISO 639-2 code)') .addOption(new Option('-o, --output <path>', 'Path to output file').default('guide.xml'))
.option('-t, --timeout <milliseconds>', 'Override the default timeout for each request') .addOption(new Option('-l, --lang <code>', 'Filter channels by language (ISO 639-1 code)'))
.option('-d, --delay <milliseconds>', 'Override the default delay between request') .addOption(
.option('-x, --proxy <url>', 'Use the specified proxy') new Option('-t, --timeout <milliseconds>', 'Override the default timeout for each request').env(
.option( 'TIMEOUT'
)
)
.addOption(
new Option('-d, --delay <milliseconds>', 'Override the default delay between request').env(
'DELAY'
)
)
.addOption(new Option('-x, --proxy <url>', 'Use the specified proxy').env('PROXY'))
.addOption(
new Option(
'--days <days>', '--days <days>',
'Override the number of days for which the program will be loaded (defaults to the value from the site config)', 'Override the number of days for which the program will be loaded (defaults to the value from the site config)'
value => parseInt(value)
) )
.option( .argParser(value => parseInt(value))
'--maxConnections <number>', .env('DAYS')
'Limit on the number of concurrent requests', )
value => parseInt(value), .addOption(
1 new Option('--maxConnections <number>', 'Limit on the number of concurrent requests')
.default(1)
.env('MAX_CONNECTIONS')
)
.addOption(
new Option('--gzip', 'Create a compressed version of the guide as well')
.default(false)
.env('GZIP')
) )
.option('--cron <expression>', 'Schedule a script run (example: "0 0 * * *")')
.option('--gzip', 'Create a compressed version of the guide as well', false)
.parse(process.argv) .parse(process.argv)
export type GrabOptions = { export type GrabOptions = {
@ -42,7 +56,6 @@ export type GrabOptions = {
delay?: string delay?: string
lang?: string lang?: string
days?: number days?: number
cron?: string
proxy?: string proxy?: string
} }
@ -81,18 +94,8 @@ async function main() {
} }
logger.info(` found ${parsedChannels.count()} channel(s)`) logger.info(` found ${parsedChannels.count()} channel(s)`)
let runIndex = 1 logger.info('run:')
if (options.cron) {
const cronJob = new CronJob(options.cron, async () => {
logger.info(`run #${runIndex}:`)
await runJob({ logger, parsedChannels })
runIndex++
})
cronJob.start()
} else {
logger.info(`run #${runIndex}:`)
runJob({ logger, parsedChannels }) runJob({ logger, parsedChannels })
}
} }
main() main()

668
yarn.lock

File diff suppressed because it is too large Load diff