1 | # node-m3u8stream
|
2 |
|
3 | Reads segments from a [m3u8 playlist][1] or [DASH MPD file][2] into a consumable stream.
|
4 |
|
5 | [1]: https://tools.ietf.org/html/draft-pantos-http-live-streaming-20
|
6 | [2]: http://standards.iso.org/ittf/PubliclyAvailableStandards/MPEG-DASH_schema_files/DASH-MPD.xsd
|
7 |
|
8 | [![Build Status](https://secure.travis-ci.org/fent/node-m3u8stream.svg)](http://travis-ci.org/fent/node-m3u8stream)
|
9 | [![Dependency Status](https://david-dm.org/fent/node-m3u8stream.svg)](https://david-dm.org/fent/node-m3u8stream)
|
10 | [![codecov](https://codecov.io/gh/fent/node-m3u8stream/branch/master/graph/badge.svg)](https://codecov.io/gh/fent/node-m3u8stream)
|
11 |
|
12 |
|
13 | # Usage
|
14 |
|
15 | ```js
|
16 | const fs = require('fs');
|
17 | const m3u8stream = require('m3u8stream')
|
18 |
|
19 | m3u8stream('http://somesite.com/link/to/the/playlist.m3u8')
|
20 | .pipe(fs.createWriteStream('videofile.mp4'));
|
21 | ```
|
22 |
|
23 |
|
24 | # API
|
25 |
|
26 | ### m3u8stream(url, [options])
|
27 |
|
28 | Creates a readable stream of binary media data. `options` can have the following
|
29 |
|
30 | * `begin` - Where to begin playing the video. Accepts an absolute unix timestamp or date, and a relative time in the formats `1:23:45.123` and `1m2s`.
|
31 | * `liveBuffer` - How much buffer in milliseconds to have for live streams. Default is `20000`.
|
32 | * `chunkReadahead` - How many chunks to preload ahead. Default is `3`.
|
33 | * `highWaterMark` - How much of the download to buffer into the stream. See [node's docs](https://nodejs.org/api/stream.html#stream_constructor_new_stream_writable_options) for more. Note that the actual amount buffered can be higher since each chunk request maintains its own buffer.
|
34 | * `requestOptions` - Any options you want to pass to [miniget](https://github.com/fent/node-miniget), such as `headers`.
|
35 | * `parser` - Either "m3u8" or "dash-mpd". Defaults to "m3u8".
|
36 | * `id` - If playlist contains multiple media options. Otherwise, the first representation will be picked.
|
37 |
|
38 | Stream has an `.end()` method, that if called, stops requesting segments, and refreshing the playlist.
|
39 |
|
40 | ### Limitations
|
41 |
|
42 | Currently, it does not support [encrypted media segments](https://tools.ietf.org/html/draft-pantos-http-live-streaming-20#section-4.3.2.4). This is because the sites where this was tested on and intended for, YouTube and Twitch, don't use it.
|
43 |
|
44 | 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](https://github.com/tedconf/node-m3u8).
|
45 |
|
46 |
|
47 | # Install
|
48 |
|
49 | npm install m3u8stream
|
50 |
|
51 |
|
52 | # Tests
|
53 | Tests are written with [mocha](https://mochajs.org)
|
54 |
|
55 | ```bash
|
56 | npm test
|
57 | ```
|