npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

yt-dlp-wrap-plus

v2.3.20

Published

A simple node.js wrapper for yt-dlp.

Downloads

158

Readme

yt-dlp-wrap-plus

This is a fork of yt-dlp-wrap with some modifications (Downloads full executable for linux and fixed problems with progress).

A simple node.js wrapper for yt-dlp.

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

Installation

You can install yt-dlp-wrap-plus via npm (npm i yt-dlp-wrap-plus).
YT-dlp itself will not be automatically downloaded.
Provide it yourself or use some of the following functions to download the binary.

Typescript (only import differs)

import YTDlpWrap from 'yt-dlp-wrap-plus';

Javascript

const YTDlpWrap = require('yt-dlp-wrap-plus').default;

//Get the data from the github releases API. In this case get page 1 with a maximum of 5 items.
let githubReleasesData = await YTDlpWrap.getGithubReleases(1, 5);

//Download the yt-dlp binary for the given version and platform to the provided path.
//By default the latest version will be downloaded to "./yt-dlp" and platform = os.platform().
await YTDlpWrap.downloadFromGithub(
    'path/to/yt-dlp/binary',
    '2020.06.16.1',
    'win32'
);

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

Usage

EventEmitter

Excecute yt-dlp and returns an EventEmitter.
The ytDlpEvent event will expose all yt-dlp events, for example:
The log message [download] Destination: output.mp4 will emit the event type download and the event data Destination: output.mp4.
ytDlpEmitter.ytDlpProcess exposes the spawned yt-dlp process.

const YTDlpWrap = require('yt-dlp-wrap-plus').default;
const ytDlpWrap = new YTDlpWrap('path/to/yt-dlp/binary');

let ytDlpEventEmitter = ytDlpWrap
    .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('ytDlpEvent', (eventType, eventData) =>
        console.log(eventType, eventData)
    )
    .on('error', (error) => console.error(error))
    .on('close', () => console.log('all done'));

console.log(ytDlpEventEmitter.ytDlpProcess.pid);

Readable Stream

Excecute yt-dlp and returns an Readable Stream.
The interface works just like the EventEmitter.

let readableStream = ytDlpWrap.execStream([
    'https://www.youtube.com/watch?v=aqz-KE-bpKQ',
    '-f',
    'best[ext=mp4]',
]);
readableStream.pipe(fs.createWriteStream('test.mp4'));

Promise

Excecute yt-dlp and returns an Promise.

let stdout = await ytDlpWrap.execPromise([
    'https://www.youtube.com/watch?v=aqz-KE-bpKQ',
    '-f',
    'best',
    '-o',
    'output.mp4',
]);
console.log(stdout);

Options and Cancellation

Additionally you can set the options of the spawned process and abort the process.
The abortion of the spawned process is handled by passing the signal of an AbortController.

let controller = new AbortController();
let ytDlpEventEmitter = ytDlpWrap.exec(
    [
        'https://www.youtube.com/watch?v=aqz-KE-bpKQ',
        '-f',
        'best',
        '-o',
        'output.mp4',
    ],
    { shell: true, detached: true },
    controller.signal
);

setTimeout(() => {
    controller.abort();
    console.log(ytDlpEventEmitter.ytDlpProcess.killed);
}, 500);

Metadata

Returns the yt-dlp --dump-json metadata as an object.

let metadata = await ytDlpWrap.getVideoInfo(
    'https://www.youtube.com/watch?v=aqz-KE-bpKQ'
);
console.log(metadata.title);

Utility functions

Just a few utility functions to get informations.

let version = await ytDlpWrap.getVersion();
let userAgent = await ytDlpWrap.getUserAgent();
let help = await ytDlpWrap.getHelp();
let extractors = await ytDlpWrap.getExtractors();
let extractorDescriptions = await ytDlpWrap.getExtractorDescriptions();

License

MIT