1.0.1 • Published 5 years ago

parse-m3u8 v1.0.1

Weekly downloads
147
License
ISC
Repository
github
Last release
5 years ago

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