2021-10-13 22:11:45 +02:00
# EPG Grabber [![Build Status](https://app.travis-ci.com/freearhey/epg-grabber.svg?branch=master)](https://app.travis-ci.com/freearhey/epg-grabber)
2021-03-13 13:48:58 +01:00
2021-03-13 15:31:16 +01:00
Node.js CLI tool for grabbing EPG from different websites.
2021-03-13 13:48:58 +01:00
## Installation
```sh
npm install -g epg-grabber
```
2021-11-16 15:59:29 +01:00
## Quick Start
```sh
epg-grabber --config=example.com.config.js
```
#### example.com.config.js
```js
module.exports = {
site: 'example.com',
channels: 'example.com.channels.xml',
url: function (context) {
const { date, channel } = context
return `https://api.example.com/${date.format('YYYY-MM-DD')}/channel/${channel.site_id}`
},
parser: function (context) {
const programs = JSON.parse(context.content)
return programs.map(program => {
return {
title: program.title,
start: program.start,
stop: program.stop
}
})
}
}
```
#### example.com.channels.xml
```xml
<?xml version="1.0" ?>
< site site = "example.com" >
< channels >
< channel site_id = "cnn-23" xmltv_id = "CNN.us" > CNN< / channel >
< / channels >
< / site >
```
## Example Output
```xml
< tv >
< channel id = "CNN.us" >
< display-name > CNN< / display-name >
< / channel >
< programme start = "20211116040000 +0000" stop = "20211116050000 +0000" channel = "CNN.us" >
< title lang = "en" > News at 10PM< / title >
< / programme >
// ...
< / tv >
```
## CLI
2021-03-13 13:48:58 +01:00
```sh
epg-grabber --config=example.com.config.js
```
Arguments:
- `-c, --config` : path to config file
2021-09-15 10:20:08 +02:00
- `-o, --output` : path to output file (default: 'guide.xml')
- `--channels` : path to list of channels (can be specified via config file)
- `--lang` : set default language for all programs (default: 'en')
- `--days` : number of days for which to grab the program (default: 1)
- `--delay` : delay between requests (default: 3000)
- `--debug` : enable debug mode (default: false)
2021-11-16 15:59:29 +01:00
- `--log` : path to log file (optional)
- `--log-level` : set the log level (default: 'info')
2021-03-13 13:48:58 +01:00
2021-11-16 15:59:29 +01:00
## Site Config
2021-03-13 15:29:54 +01:00
```js
module.exports = {
site: 'example.com', // site domain name (required)
output: 'example.com.guide.xml', // path to output file (default: 'guide.xml')
channels: 'example.com.channels.xml', // path to channels.xml file (required)
2021-09-15 10:20:08 +02:00
lang: 'fr', // default language for all programs (default: 'en')
2021-08-21 15:27:51 +02:00
days: 3, // number of days for which to grab the program (default: 1)
2021-09-15 10:20:08 +02:00
delay: 5000, // delay between requests (default: 3000)
2021-03-13 15:29:54 +01:00
2021-04-02 19:30:41 +02:00
request: { // request options (details: https://github.com/axios/axios#request-config)
method: 'GET',
2021-08-23 13:17:24 +02:00
timeout: 5000,
/**
2021-11-16 15:59:29 +01:00
* @param {object} context
2021-08-23 13:17:24 +02:00
*
* @return {string} The function should return headers for each request (optional)
*/
2021-11-16 15:59:29 +01:00
headers: function(context) {
2021-08-23 13:17:24 +02:00
return {
'User-Agent':
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36 Edg/79.0.309.71'
}
2021-04-02 19:30:41 +02:00
},
2021-08-23 13:17:24 +02:00
/**
2021-11-16 15:59:29 +01:00
* @param {object} context
2021-08-23 13:17:24 +02:00
*
* @return {string} The function should return data for each request (optional)
*/
2021-11-16 15:59:29 +01:00
data: function(context) {
const { channel, date } = context
2021-08-23 13:17:24 +02:00
return {
channels: [channel.site_id],
dateStart: date.format('YYYY-MM-DDT00:00:00-00:00'),
dateEnd: date.add(1, 'd').format('YYYY-MM-DDT00:00:00-00:00')
}
}
2021-04-02 19:30:41 +02:00
},
2021-03-13 15:29:54 +01:00
/**
2021-11-16 15:59:29 +01:00
* @param {object} context
2021-03-13 15:29:54 +01:00
*
* @return {string} The function should return URL of the program page for the channel
*/
2021-11-16 15:59:29 +01:00
url: function (context) {
return `https://example.com/${context.date.format('YYYY-MM-DD')}/channel/${context.channel.site_id}.html`
2021-03-13 15:29:54 +01:00
},
2021-03-20 12:00:04 +01:00
/**
2021-11-16 15:59:29 +01:00
* @param {object} context
2021-03-20 12:00:04 +01:00
*
* @return {string} The function should return URL of the channel logo (optional)
*/
2021-11-16 15:59:29 +01:00
logo: function (context) {
return `https://example.com/logos/${context.channel.site_id}.png`
2021-03-20 12:00:04 +01:00
},
2021-03-13 15:29:54 +01:00
/**
2021-11-16 15:59:29 +01:00
* @param {object} context
2021-03-13 15:29:54 +01:00
*
* @return {array} The function should return an array of programs with their descriptions
*/
2021-11-16 15:59:29 +01:00
parser: function (context) {
2021-03-13 15:29:54 +01:00
// content parsing...
return [
{
title, // program title (required)
start, // program start time (required)
stop, // program end time (optional)
description, // program description (optional)
2021-04-01 04:05:53 +02:00
category, // program category (optional)
2021-04-13 22:28:09 +02:00
icon, // program icon (optional)
2021-04-01 04:05:53 +02:00
lang // program language (default: 'en')
2021-03-13 15:29:54 +01:00
},
...
]
}
}
```
2021-11-16 15:59:29 +01:00
## Context Object
From each function in `config.js` you can access a `context` object containing the following data:
- `channel` : The object describing the current channel (xmltv_id, site_id, name, lang)
- `date` : The 'dayjs' instance with the requested date
- `content` : The response data as a String
- `buffer` : The response data as an ArrayBuffer
## Channels List
2021-03-13 15:29:54 +01:00
```xml
2021-10-13 22:11:45 +02:00
<?xml version="1.0" ?>
2021-03-13 15:29:54 +01:00
< site site = "example.com" >
< channels >
< channel site_id = "cnn-23" xmltv_id = "CNN.us" > CNN< / channel >
...
< / channels >
< / site >
```
2021-04-01 04:05:53 +02:00
You can also specify the language and logo for each channel individually, like so:
```xml
2021-10-13 22:11:45 +02:00
< channel
site_id="france-24"
xmltv_id="France24.fr"
lang="fr"
logo="https://example.com/france24.png"
>France 24< / channel >
2021-04-01 04:05:53 +02:00
```
2021-03-13 13:48:58 +01:00
## Contribution
If you find a bug or want to contribute to the code or documentation, you can help by submitting an [issue ](https://github.com/freearhey/epg-grabber/issues ) or a [pull request ](https://github.com/freearhey/epg-grabber/pulls ).
## License
[MIT ](http://opensource.org/licenses/MIT )