fent / node-m3u8stream

Concatenates segments from a m3u8/dash-mpd playlist into a consumable stream.
MIT License
216 stars 53 forks source link
m3u8 nodejs stream

node-m3u8stream

Reads segments from a m3u8 playlist or DASH MPD file into a consumable stream.

Depfu codecov

Usage

const fs = require('fs');
const m3u8stream = require('m3u8stream')

m3u8stream('http://somesite.com/link/to/the/playlist.m3u8')
    .pipe(fs.createWriteStream('videofile.mp4'));

API

m3u8stream(url, [options])

Creates a readable stream of binary media data. options can have the following

Stream#end()

If called, stops requesting segments, and refreshing the playlist.

Event: progress

For static non-live playlists, emitted each time a segment has finished downloading. Since total download size is unknown until all segment endpoints are hit, progress is calculated based on how many segments are available.

miniget events

All miniget events are forwarded and can be listened to from the returned stream.

m3u8stream.parseTimestamp(time)

Converts human friendly time to milliseconds. Supports the format
00:00:00.000 for hours, minutes, seconds, and milliseconds respectively.
And 0ms, 0s, 0m, 0h, and together 1m1s.

Limitations

Currently, it does not support encrypted media segments. This is because the sites where this was tested on and intended for, YouTube and Twitch, don't use it.

This does not parse master playlists, only media playlists. If you want to parse a master playlist to get links to media playlists, you can try the m3u8 module.

Install

npm install m3u8stream

Tests

Tests are written with mocha

npm test