Installations
npm install m3u8-file-parser
Developer Guide
Typescript
No
Module System
CommonJS
Node Version
15.1.0
NPM Version
7.6.0
Score
82.1
Supply Chain
99.5
Quality
75.6
Maintenance
100
Vulnerability
100
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (100%)
Developer
NimitzDEV
Download Statistics
Total Downloads
497,302
Last Day
621
Last Week
4,209
Last Month
18,178
Last Year
230,735
GitHub Statistics
17 Stars
29 Commits
6 Forks
2 Watching
10 Branches
2 Contributors
Package Meta Information
Latest Version
0.2.4
Package Id
m3u8-file-parser@0.2.4
Unpacked Size
40.21 kB
Size
12.14 kB
File Count
36
NPM Version
7.6.0
Node Version
15.1.0
Total Downloads
Cumulative downloads
Total Downloads
497,302
Last day
4.7%
621
Compared to previous day
Last week
1.1%
4,209
Compared to previous week
Last month
2.2%
18,178
Compared to previous month
Last year
49.7%
230,735
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dev Dependencies
4
m3u8-file-parser
A m3u/m3u8 file parser build against RFC8216 specs.
Installation
npm install m3u8-file-parser --save
or yarn add m3u8-file-parser
Usage
In Node.js
1const M3U8FileParser = require('m3u8-file-parser'); 2const fs = require('fs'); 3const content = fs.readFileSync('./example.m3u8', { encoding: 'utf-8'}); 4 5const reader = new M3U8FileParser(); 6reader.read(content); 7reader.getResult(); // Get the parse result 8reader.reset(); // Optional, If you want to parse a new file, call reset()
In Node.js read line by line
1const M3U8FileParser = require('m3u8-file-parser'); 2const fs = require('fs'); 3const content = fs.readFileSync('./example.m3u8', { encoding: 'utf-8'}); 4const readline = require('readline'); 5 6const reader = new M3U8FileParser(); 7const stream = fs.createReadStream('./example.m3u8', { encoding: 'utf-8' }); 8const interface = readline.createInterface({ input: stream }); 9 10interface.on('line', line => reader.read(line)); // Read line by line 11interface.on('close', () => reader.getResult()); // Get result after file ends.
In browser, use the file in dist instead.
1<!DOCTYPE html> 2<html> 3<head> 4 <meta charset="utf-8" /> 5 <title>M3U8FileParser Browser Example</title> 6 <script src="../../dist/m3u8-file-parser.min.js"></script> 7 <script> 8 var reader = new M3U8FileParser(); 9 var m3u8Content = ` 10 #EXTM3U 11 #EXTINF:10, Sample Title 12 https://example.com/sample1.mp3 13 14 #EXTINF:10, Sample Title 2\n 15 https://example.com/sample2.mp3 16 `; 17 18 reader.read(m3u8Content); 19 console.log('result', reader.getResult()); 20 </script> 21</head> 22<body> 23 <h2>See console for result</h2> 24</body> 25</html>
Also, you can parse file line by line if you want, for example, in Node.js, parsing a large file using readline
Supported Tags
Basic Tags
EXTM3U
EXT-X-VERSION
Media Segment Tags
EXTINF
EXT-X-BYTERANGE
EXT-X-DISCONTINUITY
EXT-X-KEY
EXT-X-MAP
EXT-X-PROGRAM-DATE-TIME
EXT-X-DATERANGE
Media Playlist Tags
EXT-X-TARGETDURATION
EXT-X-MEDIA-SEQUENCE
EXT-X-DISCONTINUITY-SEQUENCE
EXT-X-ENDLIST
EXT-X-PLAYLIST-TYPE
EXT-X-I-FRAMES-ONLY
Master Playlist Tags
EXT-X-MEDIA
EXT-X-STREAM-INF
EXT-X-I-FRAME-STREAM-INF
EXT-X-SESSION-DATA
EXT-X-SESSION-KEY
Media or Master Playlist Tags
EXT-X-INDEPENDENT-SEGMENTS
EXT-X-START
Extended Features
- Attributes in EXTINF, For example:
#EXTINF:10 example="hah", title
- Camel case conversion for attribute list
APIs
read(str: String)
Read the M3U/M3U8 content and parse it, you can pass a whole M3U/M3U8 content or just one line of the content.
getResult(): Object
Get the current parsed result
reset()
Reset the parsed result
Custom Parsers
No support currently.
File an issue if the parsing strategy is wrong
Feel free to file any issues
Other
Currently the parser do not support validation checks for M3U/M3U8 file, like the example given below, are violating Section 4.3.5, but the parser will parse it anyway.
Parsing Example
1#EXTM3U 2#EXT-X-VERSION:2 3#EXT-X-TARGETDURATION:6 4#EXT-X-PLAYLIST-TYPE:VOD 5#EXT-X-DISCONTINUITY-SEQUENCE:1 6#EXT-X-START:PERCISE=NO,TIME-OFFSET=2.11 7#EXT-X-MEDIA-SEQUENCE:1 8#EXT-X-INDEPENDENT-SEGMENTS 9#EXT-X-MEDIA:TYPE=SUBTITLES,GROUP-ID="subs",NAME="English",DEFAULT=YES,AUTOSELECT=YES,FORCED=NO,LANGUAGE="en",CHARACTERISTICS="public.accessibility.transcribes-spoken-dialog, public.accessibility.describes-music-and-sound",URI="subtitles/eng/prog_index.m3u8" 10#EXT-X-MEDIA:TYPE=SUBTITLES,GROUP-ID="subs",NAME="English (Forced)",DEFAULT=NO,AUTOSELECT=NO,FORCED=YES,LANGUAGE="en",URI="subtitles/eng_forced/prog_index.m3u8" 11#EXT-X-MEDIA:TYPE=SUBTITLES,GROUP-ID="subs",NAME="Français",DEFAULT=NO,AUTOSELECT=YES,FORCED=NO,LANGUAGE="fr",CHARACTERISTICS="public.accessibility.transcribes-spoken-dialog, public.accessibility.describes-music-and-sound",URI="subtitles/fra/prog_index.m3u8" 12#EXT-X-MEDIA:TYPE=SUBTITLES,GROUP-ID="subs",NAME="Français (Forced)",DEFAULT=NO,AUTOSELECT=NO,FORCED=YES,LANGUAGE="fr",URI="subtitles/fra_forced/prog_index.m3u8" 13#EXT-X-MEDIA:TYPE=SUBTITLES,GROUP-ID="subs",NAME="Español",DEFAULT=NO,AUTOSELECT=YES,FORCED=NO,LANGUAGE="es",CHARACTERISTICS="public.accessibility.transcribes-spoken-dialog, public.accessibility.describes-music-and-sound",URI="subtitles/spa/prog_index.m3u8" 14#EXT-X-MEDIA:TYPE=SUBTITLES,GROUP-ID="subs",NAME="Español (Forced)",DEFAULT=NO,AUTOSELECT=NO,FORCED=YES,LANGUAGE="es",URI="subtitles/spa_forced/prog_index.m3u8" 15#EXT-X-MEDIA:TYPE=SUBTITLES,GROUP-ID="subs",NAME="日本語",DEFAULT=NO,AUTOSELECT=YES,FORCED=NO,LANGUAGE="ja",CHARACTERISTICS="public.accessibility.transcribes-spoken-dialog, public.accessibility.describes-music-and-sound",URI="subtitles/jpn/prog_index.m3u8" 16#EXT-X-MEDIA:TYPE=SUBTITLES,GROUP-ID="subs",NAME="日本語 (Forced)",DEFAULT=NO,AUTOSELECT=NO,FORCED=YES,LANGUAGE="ja",URI="subtitles/jpn_forced/prog_index.m3u8" 17#EXT-X-SESSION-DATA:DATA-ID="com.example.lyrics",URI="lyrics.json" 18#EXT-X-SESSION-DATA:DATA-ID="com.example.title",LANGUAGE="en", \ 19 VALUE="This is an example" 20#EXT-X-SESSION-DATA:DATA-ID="com.example.title",LANGUAGE="es", \ 21 VALUE="Este es un ejemplo" 22#EXT-X-SESSION-KEY:METHOD=AES-128,URI="https://priv.example.com/key.php?r=52",IV=0x9c7db8778570d05c3177c349fd9236aa 23#EXT-X-STREAM-INF:BANDWIDTH=100,AVERAGE-BANDWIDTH=128,CODECS="MPEG-4;MPEG-2",RESOLUTION=1080,FRAME-RATE=29.97,HDCP-LEVEL="TYPE-0",AUDIO="AUDIO",VIDEO="VIDEO" 24#EXT-X-I-FRAME-STREAM-INF:BANDWIDTH=120,URI="THATFILE.M3U8" 25#EXT-X-BYTERANGE:100@10 26#EXT-X-DISCONTINUITY 27#EXT-X-KEY:METHOD=AES-128,URI="https://priv.example.com/key.php?r=52",IV=0x9c7db8778570d05c3177c349fd9236aa 28#EXT-X-MAP:URI="https://example.map.uri",BYTERANGE="300@0" 29#EXT-X-PROGRAM-DATE-TIME:2010-02-19T14:54:23.031+08:00 30#EXT-X-DATERANGE:ID="ITS ID",CLASS="ITS CLASS",START-DATE="2010-02-19T14:54:23.031+08:00",END-DATE="2010-02-19T14:54:23.031+08:00",DURATION=1.33,PLANNED-DURATION=2.33 31#EXTINF:23.222 tvg-logo="haha, ddd" tvg-aa="sb@" tag=sa, Sample artist, : - Sample title 32C:\Documents and Settings\I\My Music\Sample.mp3 33#EXT-X-ENDLIST 34#COMMENT YAS
Parsed result:
1{ 2 "isExtendedM3U": true, 3 "segments": [ 4 { 5 "isMasterPlaylist": true, 6 "sessionKey": { 7 "method": "AES-128", 8 "uri": "https://priv.example.com/key.php?r=52", 9 "iv": "0x9c7db8778570d05c3177c349fd9236aa" 10 }, 11 "streamInf": { 12 "bandwidth": 100, 13 "averageBandwidth": 128, 14 "codecs": [ 15 "MPEG-4", 16 "MPEG-2" 17 ], 18 "resolution": 1080, 19 "frameRate": 29.97, 20 "hdcpLevel": "TYPE-0", 21 "audio": "AUDIO", 22 "video": "VIDEO" 23 }, 24 "iFrameStreamInf": { 25 "bandwidth": 120, 26 "uri": "THATFILE.M3U8" 27 }, 28 "byteRange": { 29 "length": 100, 30 "offset": 10 31 }, 32 "discontinuity": true, 33 "key": { 34 "method": "AES-128", 35 "uri": "https://priv.example.com/key.php?r=52", 36 "iv": "0x9c7db8778570d05c3177c349fd9236aa" 37 }, 38 "map": { 39 "uri": "https://example.map.uri", 40 "byterange": { 41 "length": 300, 42 "offset": 0 43 } 44 }, 45 "programDateTime": "2010-02-19T06:54:23.031Z", 46 "dateRange": { 47 "id": "ITS ID", 48 "class": "ITS CLASS", 49 "startDate": "2010-02-19T06:54:23.031Z", 50 "endDate": "2010-02-19T06:54:23.031Z", 51 "duration": 1.33, 52 "plannedDuration": 2.33 53 }, 54 "inf": { 55 "duration": 23.222, 56 "title": "Sample artist, : - Sample title", 57 "tvg-logo": "haha, ddd", 58 "tvg-aa": "sb@", 59 "tag": "sa" 60 }, 61 "url": "C:\\Documents and Settings\\I\\My Music\\Sample.mp3" 62 } 63 ], 64 "version": 2, 65 "targetDuration": 6, 66 "playlistType": "VOD", 67 "discontinuitySequence": 1, 68 "start": { 69 "percise": true, 70 "timeOffset": 2.11 71 }, 72 "mediaSequence": 1, 73 "independentSegments": true, 74 "media": { 75 "SUBTITLES": { 76 "subs": { 77 "English": { 78 "groupId": "subs", 79 "type": "SUBTITLES", 80 "name": "English", 81 "default": true, 82 "autoselect": true, 83 "forced": true, 84 "language": "en", 85 "characteristics": "public.accessibility.transcribes-spoken-dialog, public.accessibility.describes-music-and-sound", 86 "uri": "subtitles/eng/prog_index.m3u8" 87 }, 88 "English (Forced)": { 89 "groupId": "subs", 90 "type": "SUBTITLES", 91 "name": "English (Forced)", 92 "default": true, 93 "autoselect": true, 94 "forced": true, 95 "language": "en", 96 "uri": "subtitles/eng_forced/prog_index.m3u8" 97 }, 98 "Français": { 99 "groupId": "subs", 100 "type": "SUBTITLES", 101 "name": "Français", 102 "default": true, 103 "autoselect": true, 104 "forced": true, 105 "language": "fr", 106 "characteristics": "public.accessibility.transcribes-spoken-dialog, public.accessibility.describes-music-and-sound", 107 "uri": "subtitles/fra/prog_index.m3u8" 108 }, 109 "Français (Forced)": { 110 "groupId": "subs", 111 "type": "SUBTITLES", 112 "name": "Français (Forced)", 113 "default": true, 114 "autoselect": true, 115 "forced": true, 116 "language": "fr", 117 "uri": "subtitles/fra_forced/prog_index.m3u8" 118 }, 119 "Español": { 120 "groupId": "subs", 121 "type": "SUBTITLES", 122 "name": "Español", 123 "default": true, 124 "autoselect": true, 125 "forced": true, 126 "language": "es", 127 "characteristics": "public.accessibility.transcribes-spoken-dialog, public.accessibility.describes-music-and-sound", 128 "uri": "subtitles/spa/prog_index.m3u8" 129 }, 130 "Español (Forced)": { 131 "groupId": "subs", 132 "type": "SUBTITLES", 133 "name": "Español (Forced)", 134 "default": true, 135 "autoselect": true, 136 "forced": true, 137 "language": "es", 138 "uri": "subtitles/spa_forced/prog_index.m3u8" 139 }, 140 "日本語": { 141 "groupId": "subs", 142 "type": "SUBTITLES", 143 "name": "日本語", 144 "default": true, 145 "autoselect": true, 146 "forced": true, 147 "language": "ja", 148 "characteristics": "public.accessibility.transcribes-spoken-dialog, public.accessibility.describes-music-and-sound", 149 "uri": "subtitles/jpn/prog_index.m3u8" 150 }, 151 "日本語 (Forced)": { 152 "groupId": "subs", 153 "type": "SUBTITLES", 154 "name": "日本語 (Forced)", 155 "default": true, 156 "autoselect": true, 157 "forced": true, 158 "language": "ja", 159 "uri": "subtitles/jpn_forced/prog_index.m3u8" 160 } 161 } 162 } 163 }, 164 "sessionData": { 165 "com.example.lyrics": { 166 "undefined": { 167 "dataId": "com.example.lyrics", 168 "uri": "lyrics.json" 169 } 170 }, 171 "com.example.title": { 172 "en": { 173 "dataId": "com.example.title", 174 "language": "en", 175 "value": "This is an example" 176 }, 177 "es": { 178 "dataId": "com.example.title", 179 "language": "es", 180 "value": "Este es un ejemplo" 181 } 182 } 183 }, 184 "endList": 2 185}
License
MIT
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
Found 1/18 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 12 are checked with a SAST tool
Reason
36 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-v88g-cgmw-v5xw
- Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-x9w5-v3q2-3rhw
- Warn: Project is vulnerable to: GHSA-gxpj-cx7g-858c
- Warn: Project is vulnerable to: GHSA-w573-4hg7-7wgq
- Warn: Project is vulnerable to: GHSA-434g-2637-qmqr
- Warn: Project is vulnerable to: GHSA-49q7-c7j4-3p7m
- Warn: Project is vulnerable to: GHSA-977x-g7h5-7qgw
- Warn: Project is vulnerable to: GHSA-f7q4-pwc6-w24p
- Warn: Project is vulnerable to: GHSA-fc9h-whq2-v747
- Warn: Project is vulnerable to: GHSA-8r6j-v8pm-fqw3
- Warn: Project is vulnerable to: MAL-2023-462
- Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h
- Warn: Project is vulnerable to: GHSA-6c8f-qphg-qjgp
- Warn: Project is vulnerable to: GHSA-76p3-8jx3-jpfq
- Warn: Project is vulnerable to: GHSA-3rfm-jhwj-7488
- Warn: Project is vulnerable to: GHSA-hhq3-ff78-jv3g
- Warn: Project is vulnerable to: GHSA-29mw-wpgm-hmr9
- Warn: Project is vulnerable to: GHSA-35jh-r3h4-6jhm
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3
- Warn: Project is vulnerable to: GHSA-vh95-rmgr-6w4m / GHSA-xvch-5gv4-984h
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-h9rv-jmmf-4pgx
- Warn: Project is vulnerable to: GHSA-hxcc-f52p-wc94
- Warn: Project is vulnerable to: GHSA-vx3p-948g-6vhq
- Warn: Project is vulnerable to: GHSA-3jfq-g458-7qm9
- Warn: Project is vulnerable to: GHSA-r628-mhmh-qjhw
- Warn: Project is vulnerable to: GHSA-9r2w-394v-53qc
- Warn: Project is vulnerable to: GHSA-5955-9wpr-37jh
- Warn: Project is vulnerable to: GHSA-qq89-hq3f-393p
- Warn: Project is vulnerable to: GHSA-f5x3-32g6-xq36
- Warn: Project is vulnerable to: GHSA-4wf5-vphf-c2xc
- Warn: Project is vulnerable to: GHSA-c4w7-xm78-47vh
- Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw
Score
1.7
/10
Last Scanned on 2024-12-23
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More