Skip to content
This repository has been archived by the owner on Mar 8, 2021. It is now read-only.
/ youtube-dl-wrap Public archive

A simple node.js wrapper for youtube-dl.

License

Notifications You must be signed in to change notification settings

mattoz0/youtube-dl-wrap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

45 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

youtube-dl-wrap

NPM version

A simple node.js wrapper for youtube-dl.

  • 0 dependencies
  • EventEmitter, Promise and Stream interface
  • Progress events
  • Utility functions

Usage

Youtube-dl will not be automatically downloaded.
Provide it yourself or use some of the following functions to download the binary.

const YoutubeDlWrap = require("youtube-dl-wrap");

//Downloads the latest youtube-dl binary for the given platform to the provided path.
//By default the path will be "./youtube-dl" and platform will be os.platform().
await YoutubeDlWrap.downloadLatestYoutubeDl("path/to/youtube-dl/binary", "win32");

//Init an instance with a given binary path.
//If none is provided "youtube-dl" will be used as command.
const youtubeDlWrap = new YoutubeDlWrap("path/to/youtube-dl/binary");
//The binary path can also be changed later on.
youtubeDlWrap.setBinaryPath("path/to/another/youtube-dl/binary");

To interface with youtube-dl the following methods can be used.

const YoutubeDlWrap = require("youtube-dl-wrap");
const youtubeDlWrap = new YoutubeDlWrap("path/to/youtube-dl/binary");

//Execute and return an EventEmitter
youtubeDlWrap.exec(["https://www.youtube.com/watch?v=aqz-KE-bpKQ",
    "-f", "best", "-o", "output.mp4"])
  .on("progress", (progress) => 
    console.log(progress.percent, progress.totalSize, progress.currentSpeed, progress.eta))
  .on("error", (exitCode, processError, stderr) => 
    console.error("An error occured", exitCode, processError, stderr))
  .on("close", () => console.log("All done"));

//Execute and return a Promise
await youtubeDlWrap.execPromise(["https://www.youtube.com/watch?v=aqz-KE-bpKQ",
    "-f", "best", "-o", "output.mp4"]);

//Execute and return a Readable Stream
let readStream = youtubeDlWrap.execStream(["https://www.youtube.com/watch?v=aqz-KE-bpKQ",
    "-f", "best"])
  .on("progress", (progress) => 
    console.log(progress.percent, progress.totalSize, progress.currentSpeed, progress.eta));  


//Get the --dump-json metadata as object
let metadata = await youtubeDlWrap.getVideoInfo("https://www.youtube.com/watch?v=aqz-KE-bpKQ");


//Get the version
let version = await youtubeDlWrap.getVersion();

//Get the user agent
let userAgent = await youtubeDlWrap.getUserAgent();

//Get the help output
let help = await youtubeDlWrap.getHelp();

//Get the extractor list
let extractors = await youtubeDlWrap.getExtractors();

//Get the extractor description list
let extractorDescriptions = await youtubeDlWrap.getExtractorDescriptions();

License

MIT

About

A simple node.js wrapper for youtube-dl.

Resources

License

Stars

Watchers

Forks

Packages

No packages published