npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

m3u-parser-generator

v2.0.0

Published

Library to parse and generate m3u or m3u8 IPTV playlist files

Downloads

992

Readme

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