Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

bc-dlp

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bc-dlp

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

latest
Source
npmnpm
Version
2.0.0
Version published
Weekly downloads
9
-66.67%
Maintainers
1
Weekly downloads
 
Created
Source

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

Keywords

youtube-dl

FAQs

Package last updated on 23 Dec 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts