parse-m3u8

1.0.1 • Public • Published

parse-m3u8

npm version Build Status codecov

A Node.js module to parse M3U8

const parseM3u8 = require('parse-m3u8');
 
parseM3u8(`#EXTM3U
#EXT-X-TARGETDURATION:10
#EXTINF:10,
0.ts
#EXTINF:20,
1.ts
`).segments; /*=>  [
  {
    duration: 10,
    uri: '0.ts',
    timeline: 0
  },
  {
    duration: 20,
    uri: '1.ts',
    timeline: 0
  }
*/

Installation

Use npm.

npm install parse-m3u8

API

const parseM3u8 = require('parse-m3u8');

parseM3u8(contents [, option])

contents: string
option: Object
Return: Object

It parses a given string with m3u8-parser and returns a result Object.

option.baseUri

Type: string | URL

Rebase uri properties of each items in playlists and segments to this URL.

const source = `#EXTM3U
#EXT-X-STREAM-INF:BANDWIDTH=300000
low.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=600000
high.m3u8`;
 
parseM3u8(source).playlists; /*=> [
  {
    attributes: {BANDWIDTH: 300000},
    uri: 'low.m3u8',
    timeline: 0
  },
  {
    attributes: {BANDWIDTH: 600000},
    uri: 'high.m3u8',
    timeline: 0
  }
*/
 
parseM3u8(source, {baseUri: 'https://example.org/assets/playlists/'}).playlists; /*=> [
  {
    attributes: {BANDWIDTH: 300000},
    uri: 'https://example.org/assets/playlists/low.m3u8',
    timeline: 0
  },
  {
    attributes: {BANDWIDTH: 600000},
    uri: 'https://example.org/assets/playlists/high.m3u8',
    timeline: 0
  }
*/

License

ISC License © 2018 - 2019 Watanabe Shinnosuke

Package Sidebar

Install

npm i parse-m3u8

Weekly Downloads

50

Version

1.0.1

License

ISC

Unpacked Size

5.22 kB

Total Files

4

Last publish

Collaborators

  • shinnn