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

@iptv/playlist

v1.1.0

Published

An extremely fast M3U playlist parser and generator for Node and the browser.

Downloads

515

Readme

@iptv/playlist

An extremely fast M3U playlist parser and generator for Node and the browser. Lightweight, dependency-free, and easy to use.


npm GitHub Workflow Status Coverage GitHub


✨ Features

  • Extremely fast M3U parser and generator
  • Lightweight (1.34 kB gzipped)
  • No dependencies
  • ESM and CommonJS support
  • Supports Node and the browser
  • Supports any M3U #EXTINF & #EXTM3U attribute
  • Did I mention it's fast?

📥 Installation

To install this library, use the following command:

# pnpm
pnpm add @iptv/playlist

# npm
npm install @iptv/playlist

# yarn
yarn add @iptv/playlist

🔧 Usage

To use this library in your project, first import the functions you need:

import { parseM3U, writeM3U } from "@iptv/playlist";

Then, you can parse an M3U file and receive back an M3uPlaylist object:

Examples will be based on this M3U file, it can be found in the tests/fixtures directory.

#EXTM3U
#EXTINF:-1 tvg-id="Channel1" tvg-name="Channel 1" tvg-language="English" group-title="News",Channel 1
http://server:port/channel1
const m3u = `...`; // M3U file contents
const playlist: M3uPlaylist = parseM3U(m3u);
const channels: M3uChannel[] = playlist.channels;
{
  channels: [
    {
      tvgId: 'Channel1',
      tvgName: 'Channel 1',
      tvgLanguage: 'English',
      groupTitle: 'News',
      duration: -1,
      name: 'Channel 1',
      url: 'http://server:port/channel1',
      extras: {
        'your-custom-attribute': 'your-custom-value'
      }
    },
  ],
  headers: {}
}

You can also generate an M3U file from a M3uPlaylist object:

const playlistObject: M3uPlaylist = {
  channels: [
    {
      tvgId: "Channel1",
      tvgName: "Channel 1",
      tvgLanguage: "English",
      groupTitle: "News",
      duration: -1,
      name: "Channel 1",
      url: "http://server:port/channel1",
      extras: {
        "your-custom-attribute": "your-custom-value",
      },
    },
  ],
  headers: {},
};
const m3u = writeM3U(playlistObject);
console.log(m3u); // #EXTM3U ...

Standard Attributes

This library supports all standard attributes for the #EXTINF and #EXTM3U tags. They will be parsed, camelCased and added as properties on the M3uChannel object.

Custom Attributes

This library supports any custom attributes you may have in your M3U file. They will be parsed and generated as an object under the extras property of the M3uChannel object.

#EXTM3U
#EXTINF:-1 tvg-id="Channel1" tvg-name="Channel 1" tvg-language="English" group-title="News" custom-attribute="hello",Channel 1
http://server:port/channel1
const m3u = `...`; // M3U file contents
const playlist: M3uPlaylist = parseM3U(m3u);
const channel: M3uChannel = playlist.channels[0];
console.log(channel.extras); // { 'custom-attribute': 'hello' }

⚡ Performance

This library has been optimized for parsing and generating M3U files quickly and efficiently. In my benchmarks, it performs better than iptv-playlist-parser, iptv-playlist-generator and m3u-parser-generator.

Benchmarks

Parsing M3U file (small.m3u8)

Writing M3U file (small.m3u8)

Time spent parsing different M3U files


🎯 Future Goals

Worker Support

Even though it's fast and it won't block for long, this will block your main thread whilst it runs. I'd like to add support for running the parser in a worker so it doesn't block at all.

🚫 Non-Goals

HLS Parsing

This library is designed to parse and generate media player playlist files only. It is not designed to be a generic m3u parser or generator. It will not parse or generate HLS playlists.


🤝 Contributing

Contributions are welcome! Even better if they align with the future goals.

You'll need to be able to run the tests and benchmarks. To do so, you will need to run the ./create-fixtures.sh script in the tests/fixtures directory to generate the necessary fixture files.

To be accepted your PR must pass all tests and not negatively impact the benchmarks. Some commands to help you:

  • pnpm run test - Run the vitest suite
  • pnpm run benny - Run benchmarks with benny
  • pnpm run benchmark - Run benchmarks with vitest
  • pnpm run nanobench - Run additional timing benchmarks

This project uses Changesets to manage releases. For you, this just means your PR must come with an appropriate changeset file. If you're not sure how to do this, just ask and I'll be happy to help, or read the changesets documentation on adding a changeset.

📄 License & Credit

This library is licensed under the MIT License and is free to use in both open source and commercial projects.