Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to disable chunking #717

Merged
merged 3 commits into from
Oct 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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