epg-grabber/README.md

169 lines
4.8 KiB
Markdown
Raw Normal View History

2021-03-13 15:37:55 +01:00
# EPG Grabber [![Build Status](https://travis-ci.com/freearhey/epg-grabber.svg?branch=master)](https://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
```
## Usage
```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-03-13 13:48:58 +01:00
2021-03-13 15:40:15 +01:00
#### example.com.config.js
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,
/**
* @param {object} date The 'dayjs' instance with the requested date
* @param {object} channel Data about the requested channel
*
* @return {string} The function should return headers for each request (optional)
*/
headers: function({ date, channel }) {
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
/**
* @param {object} date The 'dayjs' instance with the requested date
* @param {object} channel Data about the requested channel
*
* @return {string} The function should return data for each request (optional)
*/
data: function({ date, channel }) {
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
/**
* @param {object} date The 'dayjs' instance with the requested date
* @param {object} channel Data about the requested channel
*
* @return {string} The function should return URL of the program page for the channel
*/
url: function ({ date, channel }) {
return `https://example.com/${date.format('YYYY-MM-DD')}/channel/${channel.site_id}.html`
},
2021-03-20 12:00:04 +01:00
/**
* @param {object} channel Data about the requested channel
* @param {string} content The response received after the request at the above url
*
* @return {string} The function should return URL of the channel logo (optional)
*/
logo: function ({ channel, content }) {
return `https://example.com/logos/${channel.site_id}.png`
},
2021-03-13 15:29:54 +01:00
/**
2021-08-23 13:17:24 +02:00
* @param {object} date The 'dayjs' instance with the requested date
2021-03-13 15:29:54 +01:00
* @param {string} content The response received after the request at the above url
*
* @return {array} The function should return an array of programs with their descriptions
*/
2021-08-23 13:17:24 +02:00
parser: function ({ date, content }) {
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)
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-08-23 13:17:24 +02:00
Also each function can be asynchronous.
```js
module.exports = {
site: 'example.com',
output: 'example.com.guide.xml',
channels: 'example.com.channels.xml',
request: {
async headers() {
return { ... }
},
async data() {
return { ... }
}
},
async url() {
return '...'
},
async logo() {
return '...'
},
async parser() {
return [ ... ]
}
}
```
2021-03-13 15:40:15 +01:00
#### example.com.channels.xml
2021-03-13 15:29:54 +01:00
```xml
<?xml version="1.0"?>
<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
<channel site_id="france-24" xmltv_id="France24.fr" lang="fr" logo="https://example.com/france24.png">France 24</channel>
```
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)