Coder Social home page Coder Social logo

am11178 / iptv-checker-module Goto Github PK

View Code? Open in Web Editor NEW

This project forked from detroitenglish/iptv-checker-module

0.0 0.0 0.0 289 KB

Check connectivity of the IPTV channels in an .m3u playlist file

Home Page: https://www.npmjs.com/package/iptv-checker-module

JavaScript 100.00%

iptv-checker-module's Introduction

IPTV Checker Module

A module for validating IPTV channel links in .m3u playlists.

Requirements

This tool requires the ffmpeg library, so you need to have it installed on your device.

You can find the right installer for your system here.

Example

const { readFileSync } = require('fs')
const iptvChecker = require('iptv-checker-module')

const opts = {
  timeout: 5000,
  parallel: 2,
}

// Example with path to local playlist file
iptvChecker('/home/foo/playlist.m3u', opts)

// Example with playlist URL
iptvChecker('http://127.0.0.1/example/playlist.m3u', opts)

// Example with playlist data Buffer
const playlistBuffer = readFileSync('/home/foo/playlist.m3u')
iptvChecker(playlistBuffer, opts)

Usage

iptvChecker(input, [(options = {})])

This module exports a single asyncronous function for parsing one of the following inputs:

  1. Path to a local .m3u playlist file (String)
  2. URL of an .m3u playlist (String)
  3. .m3u file data (String or Buffer)

...using the iptv-playlist-parser package.

It will attempt to connect to each item's (i.e. channel's) URL, and adds a status object to the item with the results of said attempt.

Options (Object)

  • timeout: Time (in ms) to wait for connection to an IPTV channel stream before considering the channel offline (default: 10000 )
  • parallel: Number of channels to check concurrently (default: Available CPUs - 1)
  • userAgent: User-Agent string to use when connecting to IPTV channel URLs (default: undefined)
  • debug: Print additional progress and result information to the console (default: false)
  • omitMetadata: Omit the metadata field from the status object of successful connections (default: false)
  • useItemHttpHeaders: If defined, use a channel's custom Referer and/or User-Agent headers. Note that channel-specific user-agents will override the userAgent option (default: true)
  • preCheckAction: Function to run after parsing the playlist and before checking channels, with the list's iptv-playlist-parser object as parameter (default: (parsedPlaylist) => {} )
  • itemCallback: Function to run after checking a channel, with the channel's item object as parameter (default: (item) => {} )
const iptvChecker = require('iptv-checker-module')

const options = {
  timeout: 5e3,
  parallel: 2,
  userAgent: 'Mozilla/5.0 (compatible; Silly-Fetcher like kek) ROFLcopters',
  debug: true,
  omitMetadata: true,
  useItemHttpHeaders: true,
  preCheckAction: playlist => {
    console.log('Total channels to check:', playlist.items.length)
  },
  itemCallback: item => {
    console.log(item.url, item.status.ok)
  },
}

iptvChecker('./local/playlist.m3u', options).then(checkedPlaylist => {
  /*  results Object */
})

Output

The function returns the iptv-playlist-parser object, with each item having an additional status object with its connection attempt result.

All status objects include an ok: <Boolean> property indicating if connection was successful or not.

Item Success

Unless omitted in options, items' status with successful connection attempts will include a metadata object containing streams and format data returned by ffprobe

{
  header: {
    attrs: {
      'x-tvg-url': 'http://example.com/epg.xml.gz'
    },
    raw: '#EXTM3U x-tvg-url="http://example.com/epg.xml.gz"'
  },
  items: [
    {
      name: 'CGTN Documentary',
      tvg: {
        id: '',
        name: '',
        language: 'Chinese',
        country: 'CN',
        logo: 'https://i.imgur.com/TSG6WBy.png',
        url: '',
      },
      group: { title: 'Documentary' },
      url: 'https://news.cgtn.com/resource/live/document/cgtn-doc.m3u8',
      raw:
        '#EXTINF:-1 tvg-id="" tvg-name="" tvg-language="Chinese" tvg-logo="https://i.imgur.com/TSG6WBy.png" tvg-country="CN" tvg-url="" group-title="Documentary",CGTN Documentary\n' +
        'https://news.cgtn.com/resource/live/document/cgtn-doc.m3u8',
      status: {
        ok: true,
        metadata: {
          streams: [Array],
          format: [Object],
        }
      }
    }
  ]
}

Item Failure

Items' status with a failed connection attempt will include a reason property string detailing the cause of failure.

{
  header: {
    attrs: {
      'x-tvg-url': 'http://example.com/epg.xml.gz'
    },
    raw: '#EXTM3U x-tvg-url="http://example.com/epg.xml.gz"'
  },
  items: [
    {
      name: 'CGTN Documentary',
      tvg: {
        id: '',
        name: '',
        language: 'Chinese',
        country: 'CN',
        logo: 'https://i.imgur.com/TSG6WBy.png',
        url: '',
      },
      group: { title: 'Documentary' },
      url: 'https://news.cgtn.com/resource/live/document/cgtn-doc.m3u8',
      raw:
        '#EXTINF:-1 tvg-id="" tvg-name="" tvg-language="Chinese" tvg-logo="https://i.imgur.com/TSG6WBy.png" tvg-country="CN" tvg-url="" group-title="Documentary",CGTN Documentary\n' +
        'https://news.cgtn.com/resource/live/document/cgtn-doc.m3u8',
      status: {
        ok: false,
        reason: 'Timed out'
      }
    }
  ]
}

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

iptv-checker-module's People

Contributors

detroitenglish avatar freearhey avatar dependabot[bot] avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.