Go to file
Aleksandr Statciuk d8831ed46c Create .gitignore 2021-09-15 11:19:56 +03:00
src Update utils.js 2021-09-15 11:19:50 +03:00
tests Create .gitignore 2021-09-15 11:19:56 +03:00
.eslintrc.js Added linter 2021-03-13 15:48:46 +03:00
.gitignore Init 2021-03-13 15:11:33 +03:00
.travis.yml Added tests 2021-03-19 22:17:07 +03:00
README.md Merge branch 'async-functions' 2021-08-23 14:19:05 +03:00
babel.config.js Added support for custom request options 2021-04-02 20:12:27 +03:00
package-lock.json Update package-lock.json 2021-09-15 11:19:35 +03:00
package.json Bump to v0.7.0 2021-08-23 14:18:25 +03:00

README.md

EPG Grabber Build Status

Node.js CLI tool for grabbing EPG from different websites.

Installation

npm install -g epg-grabber

Usage

epg-grabber --config=example.com.config.js

Arguments:

  • -c, --config: path to config file
  • -d, --debug: enable debug mode

example.com.config.js

module.exports = {
  lang: 'fr', // default language for all programs (default: 'en')
  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)
  days: 3, // number of days for which to grab the program (default: 1)

  request: { // request options (details: https://github.com/axios/axios#request-config)

    method: 'GET',
    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'
      }
    },

    /**
     * @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')
      }
    }
  },

  /**
   * @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`
  },

  /**
   * @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`
  },

  /**
   * @param {object} date The 'dayjs' instance with the requested date
   * @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
   */
  parser: function ({ date, content }) {

    // content parsing...

    return [
      {
        title, // program title (required)
        start, // program start time (required)
        stop, // program end time (optional)
        description, // program description (optional)
        category, // program category (optional)
        icon, // program icon (optional)
        lang // program language (default: 'en')
      },
      ...
    ]
  }
}

Also each function can be asynchronous.

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 [ ... ]
  }
}

example.com.channels.xml

<?xml version="1.0"?>
<site site="example.com">
  <channels>
    <channel site_id="cnn-23" xmltv_id="CNN.us">CNN</channel>
    ...
  </channels>
</site>

You can also specify the language and logo for each channel individually, like so:

<channel site_id="france-24" xmltv_id="France24.fr" lang="fr" logo="https://example.com/france24.png">France 24</channel>

Contribution

If you find a bug or want to contribute to the code or documentation, you can help by submitting an issue or a pull request.

License

MIT