YT Download

YT Download is a Deno library that allows you to download YouTube videos. It is losely based on ytdl-core, for which there is a direct port.

This is a rewrite keeping only the core functionality, hopefully making it easier to maintain.

Install

The main use of yt_download is as a library, but when installed it can also be used as a command line tool.

deno install --allow-net --allow-write -n yt_download https://deno.land/x/yt_download@1.5/mod.ts

yt_download https://www.youtube.com/watch?v=rEq1Z0bjdwc ./hello_there.mp4
yt_download rEq1Z0bjdwc ./hello_there_muted.mp4 --no-audio
yt_download rEq1Z0bjdwc ./hello_there.mp3 --no-video --mime-type='audio/webm; codecs=""opus""'

Or even as a desktop application using deuteron!

Either download the latest binary from the releases or compile it yourself:

deuteron --title yt-download --webview-url "https://jaspervanesveld.github.io/yt_download/" --allow-net https://deno.land/x/yt_download@1.5/mod.ts

image

Basic Usage

import { ytDownload } from "https://deno.land/x/yt_download@1.5/mod.ts";

// Gets a download stream for a given video ID.
// The highest bitrate is chosen for the given options.
// The default options require audio and video.
//
// NOTE: Often there is a higher bitrate option that does not include audio.
const stream = await ytDownload("rEq1Z0bjdwc");

// Pipe the stream to a file to save it
const destFile = await Deno.open(`./result.mp4`, {
  create: true,
  write: true,
  truncate: true,
});
await stream.pipeTo(destFile.writable);

Options

// Options can be passed to filter certain formats
await ytDownload("rEq1Z0bjdwc", {
  hasAudio: true,
  hasVideo: false,
  mimeType: `audio/webm; codecs="opus"`,
});

Manual Filter

The options only provide common ways to filter. But it is possible to manually filter the available formats.

import { getFormats, getDataStream } from "https://deno.land/x/yt_download@1.5/mod.ts";
const formats = await getFormats("rEq1Z0bjdwc");
const stream = await getDataStream(formats[2]); // Select the format you want to download