Skip to content

Commit

Permalink
feat: add ability to disable chunking (fent#717)
Browse files Browse the repository at this point in the history
* ability to disable chunking

* make code shorter

* fix missing semicolon
  • Loading branch information
Roki100 authored and pull[bot] committed Oct 3, 2020
1 parent ab5f2f2 commit b728e53
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Attempts to download a video from the given url. Returns a [readable stream](htt
* `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. Defaults to 512KB.
* `dlChunkSize` - The size of the download chunk in bytes. When the chosen format is video only or audio only, the download in this case is separated into multiple chunks to avoid throttling. Defaults to 10MB.
* `dlChunkSize` - The size of the download chunk in bytes. When the chosen format is video only or audio only, the download in this case is separated into multiple chunks to avoid throttling. Setting it to 0 disables chunking. Defaults to 10MB.
* `lang` - The 2 character symbol of a language. Default is `en`.

#### Event: info
Expand Down
3 changes: 2 additions & 1 deletion example/discord.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ client.on('message', async message => {
return;
}
const connection = await voiceChannel.join();
const stream = ytdl(url, { filter: 'audioonly' });
// Disabling chunking is recommended in Discord bots
const stream = ytdl(url, { filter: 'audioonly', dlChunkSize: 0 });
const dispatcher = connection.play(stream);
dispatcher.on('speaking', speaking => {
if (!speaking) voiceChannel.leave();
Expand Down
2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ const downloadFromInfoCallback = (stream, info, options) => {
backoff: { inc: 500, max: 10000 },
});

const shouldBeChunked = !format.hasAudio || !format.hasVideo;
let shouldBeChunked = dlChunkSize !== 0 && (!format.hasAudio || !format.hasVideo);

if (shouldBeChunked) {
let start = (options.range && options.range.start) || 0;
Expand Down

0 comments on commit b728e53

Please sign in to comment.