Registry / serialization / m3u8-parser

m3u8-parser

JSON →
library7.2.0jsnpmunverified

m3u8-parser is a JavaScript library designed for parsing M3U8 HLS (HTTP Live Streaming) manifests. It provides a robust, standalone mechanism to interpret the structure and metadata of HLS playlists, converting them into a structured JavaScript object. Currently at version 7.2.0, the package maintains an active development pace, regularly incorporating support for new HLS tags and specifications, as evidenced by recent feature additions in minor releases (e.g., #EXT-X-I-FRAME-STREAM-INF, #EXT-X-I-FRAMES-ONLY, #EXT-X-DEFINE). Originating from the Video.js ecosystem, it has since become an independent utility, removing its direct dependency on Video.js in version 1.0.1. Its key differentiators include comprehensive HLS tag support, extensibility through custom parsers, and the ability to handle constructor options for advanced features like variable replacement with #EXT-X-DEFINE, making it suitable for both simple manifest interpretation and complex HLS stream management.

npm install m3u8-parser
INSTALL
IMPORT
SIG · M3U8-PARSER
M
m3u8-parser
serializationjavascriptv7.2.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Parser
import { Parser } from 'm3u8-parser';
import m3u8Parser from 'm3u8-parser';
The primary class 'Parser' is exported as a named export in ESM modules.
m3u8Parser
const m3u8Parser = require('m3u8-parser');
const { Parser } = require('m3u8-parser');
In CommonJS, the module exports an object (m3u8Parser) containing the Parser class as a property (m3u8Parser.Parser).
m3u8Parser (global)
const parser = new m3u8Parser.Parser();
When included via a <script> tag, the library exposes a global variable named 'm3u8Parser' which contains the Parser class.

This quickstart demonstrates how to instantiate the m3u8-parser, feed it an HLS manifest string, and access the resulting structured JavaScript object containing parsed playlist information. It shows basic manifest creation, parsing, and logging of key properties like endList status, target duration, and segment details.

const manifest = [ '#EXTM3U', '#EXT-X-VERSION:3', '#EXT-X-TARGETDURATION:6', '#EXT-X-MEDIA-SEQUENCE:0', '#EXT-X-DISCONTINUITY-SEQUENCE:0', '#EXTINF:6,', '0.ts', '#EXTINF:6,', '1.ts', '#EXT-X-PROGRAM-DATE-TIME:2019-02-14T02:14:00.106Z', '#EXTINF:6,', '2.ts', '#EXT-X-ENDLIST' ].join('\n'); // Import the Parser class depending on your environment // CommonJS: const m3u8Parser = require('m3u8-parser'); const parser = new m3u8Parser.Parser(); // ESM: // import { Parser } from 'm3u8-parser'; // const parser = new Parser(); // Push the manifest string into the parser parser.push(manifest); parser.end(); // Signal that no more data will be pushed // Access the parsed manifest object const parsedManifest = parser.manifest; console.log('Manifest parsed successfully!'); console.log('Is end list:', parsedManifest.endList); console.log('Target duration:', parsedManifest.targetDuration); console.log('Number of segments:', parsedManifest.segments.length); if (parsedManifest.segments.length > 0) { console.log('First segment URI:', parsedManifest.segments[0].uri); console.log('First segment duration:', parsedManifest.segments[0].duration); }
Debug
Known issues
breakingMajor version increments (e.g., v2.0.0, v4.0.0) typically introduce breaking API changes. Users upgrading across these major versions should consult specific release notes not provided in this excerpt for migration details.
fix
Refer to the official release notes and changelogs for specific major versions when upgrading to understand breaking changes and necessary migration steps.
affects: >=2.0.0
gotchaParsing manifests that utilize the #EXT-X-DEFINE tag for variable replacement requires providing `url` and `mainDefinitions` in the `Parser` constructor options to ensure correct resolution of variables.
fix
Supply an options object to the `Parser` constructor, e.g., `new m3u8Parser.Parser({ url: 'https://example.com/manifest.m3u8', mainDefinitions: { key: 'value' } });` when dealing with manifests using #EXT-X-DEFINE.
affects: >=4.0.0
gotchaThe parser explicitly lists 'Not Yet Supported' HLS tags in its documentation. Relying on these tags will lead to incomplete or incorrect manifest parsing, and their properties will not be present in the output object.
fix
Always check the 'Not Yet Supported' section in the README or library source for current limitations if your manifests use advanced or experimental HLS tags. Consider contributing custom parsers for unsupported tags if necessary.
affects: All versions
gotchaIn version 1.0.1, the library removed its direct dependency on `video.js`, making it a standalone parser. Projects upgrading from very old versions (pre-1.0.1) that implicitly relied on `m3u8-parser` providing a transitive `video.js` dependency might encounter issues.
fix
Ensure `video.js` is explicitly included in your project's dependencies if your application still requires it and previously relied on `m3u8-parser` as a transitive dependency prior to version 1.0.1.
affects: <1.0.1
Errors
Common errors & fixes
TypeError: m3u8Parser.Parser is not a constructor
Incorrect module import method or accessing the Parser class directly without the namespace object in a CommonJS or global context.
fix
For CommonJS, ensure you use `const parser = new m3u8Parser.Parser();` after `const m3u8Parser = require('m3u8-parser');`. For ESM, use `import { Parser } from 'm3u8-parser'; const parser = new Parser();`.
Error: Malformed M3U8 manifest: ... (or similar parsing error message)
The input M3U8 string provided to `parser.push()` is syntactically incorrect or does not adhere to the HLS specification.
fix
Validate the M3U8 manifest string for correct syntax, missing required tags, or unexpected characters. Refer to the HLS specification for proper manifest formatting.
ReferenceError: m3u8Parser is not defined
The `m3u8-parser` library has not been successfully imported, required, or made available as a global variable in the current JavaScript scope.
fix
Verify that `require('m3u8-parser')` (CommonJS), `import { Parser } from 'm3u8-parser'` (ESM), or a `<script>` tag loading the UMD build is present and executed correctly before attempting to use `m3u8Parser`.
Upgrade
Version history
7.2.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
18 hits · last 30 days
node
18
Resources
m3u8-parser — npm install m3u8-parser · libregistry