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 SupportMaybe typescript-in-js support someday. PRs welcome.
The interfaces may change a bit as things evolve here.
$ npm install bc-dlp
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)
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)
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)
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.
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)
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()
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.
MIT