Gathering detailed insights and metrics for @transmitlive/m3u8-parser
Gathering detailed insights and metrics for @transmitlive/m3u8-parser
Gathering detailed insights and metrics for @transmitlive/m3u8-parser
Gathering detailed insights and metrics for @transmitlive/m3u8-parser
npm install @transmitlive/m3u8-parser
Typescript
Module System
Node Version
NPM Version
77.1
Supply Chain
97.7
Quality
78.7
Maintenance
100
Vulnerability
100
License
JavaScript (99.73%)
HTML (0.27%)
Total Downloads
5,770
Last Day
4
Last Week
35
Last Month
437
Last Year
5,770
124 Commits
1 Watching
8 Branches
Latest Version
7.1.0-3
Package Id
@transmitlive/m3u8-parser@7.1.0-3
Unpacked Size
445.27 kB
Size
76.61 kB
File Count
134
NPM Version
10.2.4
Node Version
20.11.1
Publised On
23 Apr 2024
Cumulative downloads
Total Downloads
Last day
-63.6%
4
Compared to previous day
Last week
-40.7%
35
Compared to previous week
Last month
-43%
437
Compared to previous month
Last year
0%
5,770
Compared to previous year
m3u8 parser
1npm install --save m3u8-parser
The npm installation is preferred, but Bower works, too.
1bower install --save m3u8-parser
1var manifest = [ 2 '#EXTM3U', 3 '#EXT-X-VERSION:3', 4 '#EXT-X-TARGETDURATION:6', 5 '#EXT-X-MEDIA-SEQUENCE:0', 6 '#EXT-X-DISCONTINUITY-SEQUENCE:0', 7 '#EXTINF:6,', 8 '0.ts', 9 '#EXTINF:6,', 10 '1.ts', 11 '#EXT-X-PROGRAM-DATE-TIME:2019-02-14T02:14:00.106Z' 12 '#EXTINF:6,', 13 '2.ts', 14 '#EXT-X-ENDLIST' 15].join('\n'); 16 17var parser = new m3u8Parser.Parser(); 18 19parser.push(manifest); 20parser.end(); 21 22var parsedManifest = parser.manifest;
The parser ouputs a plain javascript object with the following structure:
1Manifest { 2 allowCache: boolean, 3 endList: boolean, 4 mediaSequence: number, 5 dateRanges: [], 6 discontinuitySequence: number, 7 playlistType: string, 8 custom: {}, 9 playlists: [ 10 { 11 attributes: {}, 12 Manifest 13 } 14 ], 15 mediaGroups: { 16 AUDIO: { 17 'GROUP-ID': { 18 NAME: { 19 default: boolean, 20 autoselect: boolean, 21 language: string, 22 uri: string, 23 instreamId: string, 24 characteristics: string, 25 forced: boolean 26 } 27 } 28 }, 29 VIDEO: {}, 30 'CLOSED-CAPTIONS': {}, 31 SUBTITLES: {} 32 }, 33 dateTimeString: string, 34 dateTimeObject: Date, 35 targetDuration: number, 36 totalDuration: number, 37 discontinuityStarts: [number], 38 segments: [ 39 { 40 title: string, 41 byterange: { 42 length: number, 43 offset: number 44 }, 45 duration: number, 46 programDateTime: number, 47 attributes: {}, 48 discontinuity: number, 49 uri: string, 50 timeline: number, 51 key: { 52 method: string, 53 uri: string, 54 iv: string 55 }, 56 map: { 57 uri: string, 58 byterange: { 59 length: number, 60 offset: number 61 } 62 }, 63 'cue-out': string, 64 'cue-out-cont': string, 65 'cue-in': string, 66 custom: {} 67 } 68 ] 69}
m3u8-parser supports 3 additional Media Segment Tags not present in the HLS specification.
The EXT-X-CUE-OUT
indicates that the following media segment is a break in main content and the start of interstitial content. Its format is:
#EXT-X-CUE-OUT:<duration>
where duration
is a decimal-floating-point or decimal-integer number that specifies the total duration of the interstitial in seconds.
The EXT-X-CUE-OUT-CONT
indicates that the following media segment is a part of interstitial content and not the main content. Every media segment following a media segment with an EXT-X-CUE-OUT
tag SHOULD have an EXT-X-CUE-OUT-CONT
applied to it until there is an EXT-X-CUE-IN
tag. A media segment between a EXT-X-CUE-OUT
and EXT-X-CUE-IN
segment without a EXT-X-CUE-OUT-CONT
is assumed to be part of the interstitial. Its format is:
#EXT-X-CUE-OUT-CONT:<n>/<duration>
where n
is a decimal-floating-point or decimal-integer number that specifies the time in seconds the first sample of the media segment lies within the interstitial content and duration
is a decimal-floating-point or decimal-integer number that specifies the total duration of the interstitial in seconds. n
SHOULD be the sum of EXTINF
durations for all preceding media segments up to the EXT-X-CUE-OUT
tag for the current interstitial. duration
SHOULD match the duration
specified in the EXT-X-CUE-OUT
tag for the current interstitial.'
The EXT-X-CUE-IN
indicates the end of the interstitial and the return of the main content. Its format is:
#EXT-X-CUE-IN
There SHOULD be a closing EXT-X-CUE-IN
tag for every EXT-X-CUE-OUT
tag. If a second EXT-X-CUE-OUT
tag is encountered before an EXT-X-CUE-IN
tag, the client MAY choose to ignore the EXT-X-CUE-OUT
and treat it as part of the interstitial, or reject the playlist.
Example media playlist using EXT-X-CUE-
tags.
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-TARGETDURATION:10
#EXTINF:10,
0.ts
#EXTINF:10,
1.ts
#EXT-X-CUE-OUT:30
#EXTINF:10,
2.ts
#EXT-X-CUE-OUT-CONT:10/30
#EXTINF:10,
3.ts
#EXT-X-CUE-OUT-CONT:20/30
#EXTINF:10,
4.ts
#EXT-X-CUE-IN
#EXTINF:10,
5.ts
#EXTINF:10,
6.ts
#EXT-X-ENDLIST
To add a parser for a non-standard tag the parser object allows for the specification of custom tags using regular expressions. If a custom parser is specified, a custom
object is appended to the manifest object.
1const manifest = [ 2 '#EXTM3U', 3 '#EXT-X-VERSION:3', 4 '#VOD-FRAMERATE:29.97', 5 '' 6].join('\n'); 7 8const parser = new m3u8Parser.Parser(); 9parser.addParser({ 10 expression: /^#VOD-FRAMERATE/, 11 customType: 'framerate' 12}); 13 14parser.push(manifest); 15parser.end(); 16parser.manifest.custom.framerate // "#VOD-FRAMERATE:29.97"
Custom parsers may additionally be provided a data parsing function that take a line and return a value.
1const manifest = [ 2 '#EXTM3U', 3 '#EXT-X-VERSION:3', 4 '#VOD-FRAMERATE:29.97', 5 '' 6].join('\n'); 7 8const parser = new m3u8Parser.Parser(); 9parser.addParser({ 10 expression: /^#VOD-FRAMERATE/, 11 customType: 'framerate', 12 dataParser: function(line) { 13 return parseFloat(line.split(':')[1]); 14 } 15}); 16 17parser.push(manifest); 18parser.end(); 19parser.manifest.custom.framerate // 29.97
Custom parsers may also extract data at a segment level by passing segment: true
to the options object. Having a segment level custom parser will add a custom
object to the segment data.
1const manifest = [ 2 '#EXTM3U', 3 '#VOD-TIMING:1511816599485', 4 '#EXTINF:8.0,', 5 'ex1.ts', 6 '' 7 ].join('\n'); 8 9const parser = new m3u8Parser.Parser(); 10parser.addParser({ 11 expression: /#VOD-TIMING/, 12 customType: 'vodTiming', 13 segment: true 14}); 15 16parser.push(manifest); 17parser.end(); 18parser.manifest.segments[0].custom.vodTiming // #VOD-TIMING:1511816599485
Custom parsers may also map a tag to another tag. The old tag will not be replaced and all matching registered mappers and parsers will be executed.
1const manifest = [ 2 '#EXTM3U', 3 '#EXAMPLE', 4 '#EXTINF:8.0,', 5 'ex1.ts', 6 '' 7 ].join('\n'); 8 9const parser = new m3u8Parser.Parser(); 10parser.addTagMapper({ 11 expression: /#EXAMPLE/, 12 map(line) { 13 return `#NEW-TAG:123`; 14 } 15}); 16parser.addParser({ 17 expression: /#NEW-TAG/, 18 customType: 'mappingExample', 19 segment: true 20}); 21 22parser.push(manifest); 23parser.end(); 24parser.manifest.segments[0].custom.mappingExample // #NEW-TAG:123
To include m3u8-parser on your website or web application, use any of the following methods.
<script>
TagThis is the simplest case. Get the script in whatever way you prefer and include it on your page.
1<script src="//path/to/m3u8-parser.min.js"></script> 2<script> 3 var parser = new m3u8Parser.Parser(); 4</script>
When using with Browserify, install m3u8-parser via npm and require
the parser as you would any other module.
1var m3u8Parser = require('m3u8-parser'); 2 3var parser = new m3u8Parser.Parser();
With ES6:
1import { Parser } from 'm3u8-parser'; 2 3const parser = new Parser();
When using with RequireJS (or another AMD library), get the script in whatever way you prefer and require
the parser as you normally would:
1require(['m3u8-parser'], function(m3u8Parser) { 2 var parser = new m3u8Parser.Parser(); 3});
Apache-2.0. Copyright (c) Brightcove, Inc
No vulnerabilities found.
No security vulnerabilities found.