Skip to content

Commit

Permalink
feat: start from latest segment on live streams
Browse files Browse the repository at this point in the history
closes #157, #263
  • Loading branch information
fent committed Jul 19, 2018
1 parent facf299 commit 6309425
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
3 changes: 2 additions & 1 deletion README.md
Expand Up @@ -28,7 +28,8 @@ Attempts to download a video from the given url. Returns a readable stream. `opt
* `filter` - Can be `audioandvideo` to filter formats that contain both video and audio, `video` to filter for formats that contain video, `videoonly` for formats that contain video and no additional audio track. Can also be `audio` or `audioonly`. You can give a filtering function that gets called with each format available. Used to decide what format to download. This function is given the `format` object as its first argument, and should return true if the format is preferable.
* `format` - This can be a specific `format` object returned from `getInfo`. This is primarily used to download specific video or audio streams. Note: Supplying this option will ignore the `filter` and `quality` options since the format is explicitly provided.
* `range` - A byte range in the form `{start: INT, end: INT}` that specifies part of the file to download. ie {start: 10355705, end: 12452856}. Note: this downloads a portion of the file, and not a separately spliced video.
* `begin` - What time to begin downloading the video, supports formats 00:00:00.000, or 0ms, 0s, 0m, 0h, or number of milliseconds. Example: 1:30, 05:10.123, 10m30s. This option may not work on super short (less than 30s) videos, and has to be at or above 6s, see [#129](https://github.com/fent/node-ytdl-core/issues/129). It may also not work for some formats, see [#219](https://github.com/fent/node-ytdl-core/issues/219).
* `begin` - What time in the video to begin, supports formats 00:00:00.000, or 0ms, 0s, 0m, 0h, or number of milliseconds. Example: 1:30, 05:10.123, 10m30s. This option may not work on super short (less than 30s) videos, and has to be at or above 6s, see [#129](https://github.com/fent/node-ytdl-core/issues/129). It may also not work for some formats, see [#219](https://github.com/fent/node-ytdl-core/issues/219). For live videos, this also accepts a unix timestamp or Date, and defaults to `Date.now()`.
* `liveBuffer` - How much time buffer to use for live videos in milliseconds. Default is `20000`.
* `requestOptions` - Anything to merge into the request options which [miniget](https://github.com/fent/node-miniget) is called with, such as headers.
* `highWaterMark` - How much of the video download to buffer into memory. See [node's docs](https://nodejs.org/api/stream.html#stream_constructor_new_stream_writable_options) for more.
* `retries` - The number of retries ytdl is allowed to do before terminating the stream with an error. The default is set to 5.
Expand Down
2 changes: 2 additions & 0 deletions lib/index.js
Expand Up @@ -73,6 +73,8 @@ function downloadFromInfoCallback(stream, info, options) {
if (format.live) {
let req = m3u8stream(url, {
chunkReadahead: +info.live_chunk_readahead,
begin: options.begin || Date.now(),
liveBuffer: options.liveBuffer,
requestOptions: options.requestOptions,
});
req.on('error', stream.emit.bind(stream, 'error'));
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -30,7 +30,7 @@
},
"dependencies": {
"html-entities": "^1.1.3",
"m3u8stream": "^0.2.1",
"m3u8stream": "^0.3.0",
"miniget": "^1.1.0",
"sax": "^1.1.3"
},
Expand Down

0 comments on commit 6309425

Please sign in to comment.