GithubHelp home page GithubHelp logo

navezjt / m3u-parser-generator Goto Github PK

View Code? Open in Web Editor NEW

This project forked from raiper34/m3u-parser-generator

0.0 0.0 0.0 722 KB

Library to parse and generate m3u or m3u8 IPTV playlist files

Home Page: https://m3u-parser-generator.netlify.app

License: MIT License

JavaScript 0.73% TypeScript 99.27%

m3u-parser-generator's Introduction

npm version npm GitHub Repo stars CircleCI Coverage Status npm bundle size NPM docs

M3U Parser Generator

Library to parse and generate m3u or m3u8 IPTV playlist files.

Instalation

npm install m3u-parser-generator --save

Usage

You can parse your loaded m3u string:

import {M3uParser} from 'm3u-parser-generator';

const playlist = M3uParser.parse(m3uString);
playlist.medias.forEach(media => media.location);

and you get object with following structure

{
  "title": "Test TV",
  "medias": [
    {
      "location": "http://iptv.test1.com/playlist.m3u8",
      "duration": -1,
      "attributes": {
        "tvg-id": "Test tv 1",
        "tvg-country": "CZ",
        "tvg-language": "CS",
        "tvg-logo": "logo1.png",
        "group-title": "Test1",
        "unknown": "0"
      },
      "name": "Test tv 1 [CZ]",
      "group": "Test TV group 1"
    },
    {
      "location": "http://iptv.test2.com/playlist.m3u8",
      "duration": 100,
      "attributes": {
        "tvg-id": "Test tv 2",
        "tvg-country": "SK",
        "tvg-language": "SK",
        "tvg-logo": "logo2.png",
        "group-title": "Test2"
      },
      "name": "Test tv 2 [SK]",
      "group": "Test TV group 2"
    },
    {
      "location": "http://iptv.test3.com/playlist.m3u8",
      "duration": 120,
      "attributes": {
        "tvg-id": "Test tv 3",
        "tvg-country": "EN",
        "tvg-language": "EN",
        "tvg-logo": "logo3.png",
        "group-title": "Test3"
      },
      "name": "Test tv 3 [EN]"
    },
    {
      "location": "http://iptv.test4.com/playlist.m3u8",
      "duration": -1,
      "attributes": {}
    }
  ]
}

Or you can generate new playlist by your own:

import {M3uPlaylist, M3uMedia} from 'm3u-parser-generator';

const playlist = new M3uPlaylist();
playlist.title = 'Test playlist';

const media1 = new M3uMedia('http://my-stream-ulr.com/playlist.m3u8');
media1.attributes = {'tvg-id': '5', 'tvg-language': 'EN', 'unknown': 'my custom attribute'};
media1.duration = 500;
media1.name = 'Test Channel';
media1.group = 'Test Group';

playlist.medias.push(media1);
const m3uString = playlist.getM3uString();

you get

#EXTM3U
#PLAYLIST:Test playlist
#EXTINF:500 tvg-id="5" tvg-language="EN" unknown="my custom attribute",Test Channel
#EXTGRP:Test Group
http://my-stream-ulr.com/playlist.m3u8

Usage in browser

You can also use this library in the browser without compiling using jsDelivr. Import script into HTML file, and you can access classes through the global m3uParserGenerator object.

<script src="https://cdn.jsdelivr.net/npm/m3u-parser-generator@1/dist/browser-bundle.min.js"></script>
<script>
    const playlist = new m3uParserGenerator.M3uPlaylist();
    const media1 = new m3uParserGenerator.M3uMedia('http://my-stream-ulr.com/playlist.m3u8');
    playlist.medias.push(media1);
    
    const parsedPlaylist = m3uParserGenerator.M3uParser.parse(m3uString);
</script>

License

MIT

m3u-parser-generator's People

Contributors

raiper34 avatar freddy36 avatar experibass avatar israperez98 avatar ducktrshessami 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.