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

bc-dlp

v2.0.0

Published

Wrapper around yt-dlp with a few utilities for downloading the latest version for breadcrum.net

Downloads

110

Readme

bc-dlp

Actions Status Coverage Status

A yt-dlp wrapper with a few utilities for downloading the latest release.

A simple node.js wrapper for yt-dlp for use with breadcrum.net.

  • Has a few dependencies
  • EventEmitter, Promise and Stream interface
  • Working Progress events
  • Utility functions
  • Migrated to real esm. Not backwards compatible with CJS require (use import).
  • ~~Typescript Support~~ Maybe typescript-in-js support someday. PRs welcome.

The interfaces may change a bit as things evolve here.

Installation

$ npm install bc-dlp

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. eventEmitter.child exposes the spawned yt-dlp process.

import { BcDLP } from 'bc-dlp'
const bcDLP = new BcDLP('yt-dlp') // If its in your process path

const eventEmitter = bcDLP
  .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(eventEmitter.child.pid)

Readable Stream

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

import { BcDLP } from 'bc-dlp'
import * as fs from 'fs'
const bcDLP = new BcDLP('yt-dlp')

const { readStream, execEventEmitter } = bcDLP.execStream([
  'https://www.youtube.com/watch?v=aqz-KE-bpKQ',
  '-f',
  'best[ext=mp4]'
])
readableStream.pipe(fs.createWriteStream('test.mp4'))
console.log(execEventEmitter.child.pid)

Promise

Excecute yt-dlp and returns an Promise.

const stdout = await bcDLP.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.

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

setTimeout(() => {
  controller.abort()
  console.log(eventEmitter.ytDlpProcess.killed) // true
}, 500)

Note: This fails crashes V8 with bcDLP.execPromise for some reason.

Metadata

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

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

Utility functions

Just a few utility functions to get informations.

const version = await bcDLP.getVersion()
const userAgent = await bcDLP.getUserAgent()
const help = await bcDLP.getHelp()
const extractors = await bcDLP.getExtractors()
const extractorDescriptions = await bcDLP.getExtractorDescriptions()

See also

This is re-write of foxesdocode/yt-dlp-wrap which is in turn a fork of youtube-dl-wrap. They were both well done modules, but some things were broken and extra flexability was needed for breadcrum.net.

License

MIT