Giter Site home page Giter Site logo

youtube-dl-exec's Introduction

microlink cdn microlink cdn

Last version Coverage Status NPM Status

A simple Node.js wrapper for yt-dlp.

Why

  • Auto install the latest yt-dlp version available.
  • Executes any command in an efficient way.
  • Promise & Stream interface support.

Install

Note: It requires Python 3.7 or above available in your system as python3. Otherwise, the library will throw an error.

$ npm install youtube-dl-exec --save

By default, the library will auto-install the latest yt-dlp available that will downloaded on build time.

Usage

Any yt-dlp flags is supported:

const youtubedl = require('youtube-dl-exec')

youtubedl('https://www.youtube.com/watch?v=6xKWiCMKKJg', {
  dumpSingleJson: true,
  noCheckCertificates: true,
  noWarnings: true,
  preferFreeFormats: true,
  addHeader: ['referer:youtube.com', 'user-agent:googlebot']
}).then(output => console.log(output))

It's equivalent to:

$ ./bin/yt-dlp \
  --dump-single-json \
  --no-check-certificates \
  --no-warnings \
  --prefer-free-formats \
  --add-header='user-agent:googlebot' \
  --add-header='referer:youtube.com' \
  'https://www.youtube.com/watch?v=6xKWiCMKKJg'

Type yt-dlp --help for seeing all of them.

Custom binary

In case you need, you can specify your own binary path using .create:

const { create: createYoutubeDl } = require('youtube-dl-exec')
const youtubedl = createYoutubeDl('/my/binary/path')

Progress bar

Since the library is returning a promise, you can use any library that makes a progress estimation taking a promise as input:

const logger = require('progress-estimator')()
const youtubedl = require('youtube-dl-exec')

const url = 'https://www.youtube.com/watch?v=6xKWiCMKKJg'
const promise = youtubedl(url, { dumpSingleJson: true })
const result = await logger(promise, `Obtaining ${url}`)

console.log(result)

Alternatively, you can access to the subprocess to have more granular control. See youtubedl.exec.

Also, combine that with YOUTUBE_DL_SKIP_DOWNLOAD. See environment variables to know more.

API

youtubedl(url, [flags], [options])

It execs any yt-dlp command, returning back the output.

url

Required
Type: string

The URL to target.

flags

Type: object

Any flag supported by yt-dlp.

options

Any option provided here will passed to spawn#options.

youtubedl.exec(url, [flags], [options])

Similar to main method but instead of a parsed output, it will return the internal subprocess object:

const youtubedl = require('youtube-dl-exec')
const fs = require('fs')

const subprocess = youtubedl.exec(
  'https://www.youtube.com/watch?v=6xKWiCMKKJg',
  {
    dumpSingleJson: true
  }
)

console.log(`Running subprocess as ${subprocess.pid}`)

subprocess.stdout.pipe(fs.createWriteStream('stdout.txt'))
subprocess.stderr.pipe(fs.createWriteStream('stderr.txt'))

setTimeout(subprocess.cancel, 30000)

youtubedl.create(binaryPath)

It creates a yt-dlp using the binaryPath provided.

Environment variables

The environment variables are taken into account when you perform a npm install in a project that contains youtube-dl-exec dependency.

These environment variables can also be set through "npm config", for example npm install --YOUTUBE_DL_HOST="Some URL", or store it in .npmrc file.

They setup the download configuration for getting the yt-dlp binary file.

DEBUG

Set DEBUG="youtube-dl-exec*" to enable debug mode. This will enable log additional information during the post-install script.

YOUTUBE_DL_DIR

It determines the folder where to put the binary file.

The default folder is bin.

YOUTUBE_DL_FILENAME

It determines the binary filename.

The default binary file could be yt-dlp or youtube-dl.exe, depending of the YOUTUBE_DL_PLATFORM value.

YOUTUBE_DL_HOST

It determines the remote URL for getting the yt-dlp binary file.

The default URL is yt-dlp/yt-dlp latest release.

YOUTUBE_DL_PLATFORM

It determines the architecture of the machine that will use the yt-dlp binary.

The default value will computed from process.platform, being 'unix' or 'win32'.

YOUTUBE_DL_SKIP_DOWNLOAD

When is present, it will skip the postinstall script for fetching the latest yt-dlp version.

That variable should be set before performing the installation command, such as:

YOUTUBE_DL_SKIP_DOWNLOAD=true npm install

YOUTUBE_DL_SKIP_PYTHON_CHECK

When is present, it skip the python step on installation.

License

youtube-dl-exec © microlink.io, released under the MIT License.
Authored and maintained by Kiko Beats with help from contributors.

microlink.io · GitHub microlink.io · Twitter @microlinkhq

youtube-dl-exec's People

Contributors

bentorkington avatar dependabot[bot] avatar djesonpv avatar dongido001 avatar endchapter avatar foxscore avatar hazmi35 avatar henriquemod avatar imgbot[bot] avatar jeffjassky avatar kikobeats avatar marinos33 avatar miraclx avatar navidmafi avatar nopointexc avatar p-fruck avatar pfirpfel avatar samarmeena avatar skick1234 avatar sozrk avatar vikas5914 avatar william5553 avatar zs1l3nt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

youtube-dl-exec's Issues

How to use with electron?

I am trying to use "youtube-dl-exec" in electron, it works fine in a development environment, but when I package the application "youtube-dl-exec" it doesn't work.

Error: Command failed with ENOENT: C:\Users\vital\AppData\Local\Programs\vitalplayer\resources\app.asar\node_modules\youtube-dl-exec\bin\youtube-dl.exe https://example.com/artejones --dump-single-json --no-warnings --no-call-home --no-check-certificate --prefer-free-formats --youtube-skip-dash-manifest --referer https://example.com/artejones spawn C:\Users\vital\AppData\Local\Programs\vitalplayer\resources\app.asar\node_modules\youtube-dl-exec\bin\youtube-dl.exe ENOENT at Process.ChildProcess._handle.onexit (internal/child_process.js:264) at onErrorNT (internal/child_process.js:456) at processTicksAndRejections (internal/process/task_queues.js:80)

package.json

"dependencies": { "source-map-support": "^0.5.16", "electron-updater": "^4.0.6", "youtube-dl-exec": "^2.0.7" },

How to gracefully stop ?

I am unable to find any way to gracefully stop the download. Even if I use the raw ChildProcess and kill it, the youtube-dl process is killed but it leaves the ffmpeg process hanging, locking the resulting file. And manually killing the ffmpeg process leaves the file corrupted.

youtube-dl returns an invalid JSON

Hi!

Thanks for writing this - the new wrapper is far easier to use!

I seem to be hitting issues when dealing with playlists, not sure if it's down to my implementation in the code or an error with your library, hopefully you can help!

Here's a simple test function I wrote:

const youtubedl = require("youtube-dl-exec")

async function Test(VideoURL){
    let result = await youtubedl(VideoURL,{
        dumpJson: true,
        noCallHome: true,
    })
    console.log(result)
}

Test("https://www.youtube.com/playlist?list=PLvgS71fU12MawZ_u2HverscJHqsB84M3z")

When I run this I get the following error:

node utils/temp.js 
(node:352052) UnhandledPromiseRejectionWarning: SyntaxError: Unexpected token { in JSON at position 37553
    at JSON.parse (<anonymous>)
    at parse (/home/robert/Documents/Personal-Code/ssvd-metafetcher/node_modules/youtube-dl-exec/src/index.js:13:54)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async Test (/home/robert/Documents/Personal-Code/ssvd-metafetcher/utils/temp.js:4:18)

if I run the youtube-dl command by hand, it does return valid JSON:

node_modules/youtube-dl-exec/bin/youtube-dl --no-call-home --dump-json https://www.youtube.com/playlist?list=PLVJa0bdiLG6H9zOYoNEt_J-PtQFrp22wx | jq

(the output was huge, so I'll spare pasting it here, but jq parsed the output without any problems)

It works perfectly with a single video, so only seems to affect playlists, I've tried a few different playlist URL's and it seems an issue on all of them,

I've also tried with the noWarnings param and that made no difference.

youtube-dl binary version is: 2021.04.17 (though tried it with latest and made no difference)
youtube-dl-exec version is: 1.2.1
node version is: v14.16.0
OS is: Ubuntu 20.04

Hopefully it's something simple!

an offer of help.

Hello there, people of Microlink :)

I come from a land afar to help you with package quality.

Here's my plan:

  1. Migrate to TypeScript
  2. Replace redundant dependencies such as is-unix
  3. Detect youtube-dl from path before attempting to install it

If you sign off on each of these changes, I'll open PRs for them.

Download link directly to client

Hi, i want to download the link directly to the client
In ytdl-core
I have code:

app.get('/test', (req, res) => {
  var url = "https://www.youtube.com/watch?v=[id]";
  res.header("Content-Disposition", 'attachment; filename="Video.mp4');
  ytdl(url,{ format: 'mp4' }).pipe(res);
})

How can i do the same in youtube-dl-exec ? thanks for help

Cannot read properties of undefined (reading 'signals')

After connecting the library to the JS project,
const youtubedl = require('youtube-dl-exec')
I get the following error in the browser console:

`Uncaught TypeError: Cannot read properties of undefined (reading 'signals')

at normalizeSignal (signals.js?93eb:30:1)
at Array.map (<anonymous>)
at getSignals (signals.js?93eb:10:1)
at getSignalsByName (main.js?0739:9:1)
at eval (main.js?0739:23:1)
at Object../node_modules/youtube-dl-exec/node_modules/human-signals/build/src/main.js (chunk-vendors.js:1210:1)
at __webpack_require__ (app.js:849:30)
at fn (app.js:151:20)
at eval (error.js?c63c:2:1)
at Object../node_modules/youtube-dl-exec/node_modules/execa/lib/error.js (chunk-vendors.js:1114:1)`

Library added to node_modules
Please, prompt in what there can be a reason. I can't find the answer on google

How to download subtitles?

Can anyone tell me how to download the subtitles using this plugin? I'd like to download both the auto and human subtitles. Thanks in advance.

React-Native Compatibility

Hi,

It's seems that this package is not compatible with React-Native because it uses some module from NodeJS that are not implemented in React-Native, the modules involved are: assert, child_process, fs, os, path, stream and util. I tried to implement them first with
node-libs-react-native and then with rn-nodeify but I cannot make it works.

Do you have any Idea how I could use this package in a React-Native app ?

Thanks in advance.

Not working when using in the AWS Lambda (node.js) using serverless framework

2021-10-24T09:15:09.936Z	85f334fc-5831-45bb-b3fb-652f79ba3857	INFO  Error: Command failed with exit code 127: /opt/nodejs/node_modules/youtube-dl-exec/bin/youtube-dl https://www.youtube.com/watch?v=P_MfXIRQIwc --dump-single-json --no-warnings --no-call-home --no-check-certificate --prefer-free-formats --youtube-skip-dash-manifest --referer https://www.youtube.com/watch?v=P_MfXIRQIwc
/usr/bin/env: python: No such file or directory
    at makeError (/opt/nodejs/node_modules/execa/lib/error.js:60:11)
    at handlePromise (/opt/nodejs/node_modules/execa/index.js:118:26)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at async getYoutubeVideCloseCpationV2 (/var/task/handlers/webscraper/v1/index.js:253:22)
    at async Runtime.module.exports.handler (/var/task/handlers/webscraper/v1/index.js:65:27) {
  shortMessage: 'Command failed with exit code 127: /opt/nodejs/node_modules/youtube-dl-exec/bin/youtube-dl https://www.youtube.com/watch?v=P_MfXIRQIwc --dump-single-json --no-warnings --no-call-home --no-check-certificate --prefer-free-formats --youtube-skip-dash-manifest --referer https://www.youtube.com/watch?v=P_MfXIRQIwc',
  command: '/opt/nodejs/node_modules/youtube-dl-exec/bin/youtube-dl https://www.youtube.com/watch?v=P_MfXIRQIwc --dump-single-json --no-warnings --no-call-home --no-check-certificate --prefer-free-formats --youtube-skip-dash-manifest --referer https://www.youtube.com/watch?v=P_MfXIRQIwc',
  escapedCommand: '"/opt/nodejs/node_modules/youtube-dl-exec/bin/youtube-dl" "https://www.youtube.com/watch?v=P_MfXIRQIwc" --dump-single-json --no-warnings --no-call-home --no-check-certificate --prefer-free-formats --youtube-skip-dash-manifest --referer "https://www.youtube.com/watch?v=P_MfXIRQIwc"',
  exitCode: 127,
  signal: undefined,
  signalDescription: undefined,
  stdout: '',
  stderr: '/usr/bin/env: python: No such file or directory',
  failed: true,
  timedOut: false,
  isCanceled: false,
  killed: false
}

[Bug or Misunderstanding] Attempting to JSON dump to file saves object to text instead

I have this snippet of code here

const youtubedl = require('youtube-dl-exec')
const fs = require('fs');


async function downloadVid(urlString) {

    const resp = await youtubedl('https://www.youtube.com/watch?v=dQw4w9WgXcQ', {dumpJson: true})

    console.log(await resp)

    fs.writeFile('helloworld.txt', (await resp).toString(), function (err) {
        if (err) return console.log(err);
        console.log('Hello World > helloworld.txt');
      });


}

downloadVid()

My goal is to:

  1. Write the JSON dump to a file instead of just making it appear in the console
  2. Download the mp4 file

The code here only outputs the JSON dump to the console but does not save it. In fact, it just saves "[Object object]" to the file. It also does not download the the video. I have to remove the parameters to make it do that.

Is this a bug or a misunderstanding on my end

Getting a 429 error when using tthe

Hello,
I am using the library inside an express.js application.
My dependencies are mainly:
"dependencies": { "express": "^4.17.1", "youtube-dl-exec": "^1.2.0" }, "devDependencies": { "jest": "^26.6.3", "nodemon": "^2.0.7", "prettier": "2.2.1" }

Works well with local testing but when deploying to Heroku I am getting the following error:

ERROR: Unable to download webpage: HTTP Error 429: - (caused by <HTTPError 429: '-'>);

Is this a common issue? Do we get 429 because of Instagram blocking the request?

Attched is my full heroku log:
Error: Command failed with exit code 1: /app/node_modules/youtube-dl-exec/bin/youtube-dl https://www.instagram.com/p/CCRq_InFZ44 --dump-json --no-warnings --no-call-home --no-check-certificate --prefer-free-formats --youtube-skip-dash-manifest 2021-04-06T23:52:47.208255+00:00 app[web.1]: ERROR: Unable to download webpage: HTTP Error 429: - (caused by <HTTPError 429: '-'>); please report this issue on https://yt-dl.org/bug . Make sure you are using the latest version; type youtube-dl -U to update. Be sure to call youtube-dl with the --verbose flag and include its complete output. 2021-04-06T23:52:47.208256+00:00 app[web.1]: at makeError (/app/node_modules/youtube-dl-exec/node_modules/execa/lib/error.js:59:11) 2021-04-06T23:52:47.208256+00:00 app[web.1]: at handlePromise (/app/node_modules/youtube-dl-exec/node_modules/execa/index.js:114:26) 2021-04-06T23:52:47.208257+00:00 app[web.1]: at processTicksAndRejections (node:internal/process/task_queues:94:5) { 2021-04-06T23:52:47.208257+00:00 app[web.1]: shortMessage: 'Command failed with exit code 1: /app/node_modules/youtube-dl-exec/bin/youtube-dl https://www.instagram.com/p/CCRq_InFZ44 --dump-json --no-warnings --no-call-home --no-check-certificate --prefer-free-formats --youtube-skip-dash-manifest', 2021-04-06T23:52:47.208260+00:00 app[web.1]: command: '/app/node_modules/youtube-dl-exec/bin/youtube-dl https://www.instagram.com/p/CCRq_InFZ44 --dump-json --no-warnings --no-call-home --no-check-certificate --prefer-free-formats --youtube-skip-dash-manifest', 2021-04-06T23:52:47.208260+00:00 app[web.1]: exitCode: 1, 2021-04-06T23:52:47.208260+00:00 app[web.1]: signal: undefined, 2021-04-06T23:52:47.208261+00:00 app[web.1]: signalDescription: undefined, 2021-04-06T23:52:47.208261+00:00 app[web.1]: stdout: '', 2021-04-06T23:52:47.208262+00:00 app[web.1]: stderr: "ERROR: Unable to download webpage: HTTP Error 429: - (caused by <HTTPError 429: '-'>); please report this issue on https://yt-dl.org/bug . Make sure you are using the latest version; type youtube-dl -U to update. Be sure to call youtube-dl with the --verbose flag and include its complete output.", 2021-04-06T23:52:47.208262+00:00 app[web.1]: failed: true, 2021-04-06T23:52:47.208262+00:00 app[web.1]: timedOut: false, 2021-04-06T23:52:47.208262+00:00 app[web.1]: isCanceled: false, 2021-04-06T23:52:47.208263+00:00 app[web.1]: killed: false 2021-04-06T23:52:47.208263+00:00 app[web.1]: }

Error: Command failed with exit code 1:

Getting this error!!!

Error: Command failed with exit code 1: /var/www/vhosts/xyz.com/httpdocs/node_modules/youtube-dl-exec/bin/youtube-dl https://www.youtube.com/watch?v=LPM1sY0ipNM --dump-single-json --no-warnings --format 140 --audio-format mp3 --no-check-certificate --prefer-free-formats --extract-audio --youtube-skip-dash-manifest --referer https://www.youtube.com/watch?v=LPM1sY0ipNM
ERROR: No video formats found; please report this issue on https://yt-dl.org/bug . Make sure you are using the latest version; type youtube-dl -U to update. Be sure to call youtube-dl with the --verbose flag and include its complete output.
at makeError (/var/www/vhosts/xyz.com/httpdocs/node_modules/execa/lib/error.js:60:11)
at handlePromise (/var/www/vhosts/xyz.com/httpdocs/node_modules/execa/index.js:118:26)
at runMicrotasks ()
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async Object.apiResolver (/var/www/vhosts/xyz.com/httpdocs/node_modules/next/dist/server/api-utils.js:101:9)
at async NextNodeServer.runApi (/var/www/vhosts/xyz.com/httpdocs/node_modules/next/dist/server/next-server.js:319:9)
at async Object.fn (/var/www/vhosts/xyz.com/httpdocs/node_modules/next/dist/server/base-server.js:486:37)
at async Router.execute (/var/www/vhosts/xyz.com/httpdocs/node_modules/next/dist/server/router.js:228:32)
at async NextNodeServer.run (/var/www/vhosts/xyz.com/httpdocs/node_modules/next/dist/server/base-server.js:598:29)
at async NextNodeServer.handleRequest (/var/www/vhosts/xyz.com/httpdocs/node_modules/next/dist/server/base-server.js:305:20)

erro youtube

[PLAY] → Obtive erros no comando /play → Command failed with exit code 3221225781: C:\Users\Meu\kaotic\node_modules\youtube-dl-exec\bin\youtube-dl.exe https://youtu.be/EiQmbrvvDaY --no-warnings --no-call-home --no-check-certificate --prefer-free-formats --youtube-skip-dash-manifest --referer https://youtu.be/EiQmbrvvDaY -x --audio-format mp3 -o ./lib/media/audio/55759803244997.mp3 -

No vbr field in YtFormat

After using the --dump-json flag I get a json file in which the formats contain a vbr field but that field is not declared in the YtFormat type and thus not accessible in the wrapper.

[Command Failed] [Code 3221225781]

Hi, thank for job.

After has install Python 3.10 and youtube-dl-exec, i've attempt run minimal snippet code of Usage documentation.
But i've error at output as:

Error: Command failed with exit code 3221225781: <PATH>\node_modules\youtube-dl-exec\bin\youtube-dl.exe https://www.youtube.com/watch?v=6xKWiCMKKJg --dump-single-json --no-warnings --no-call-home --no-check-certificate --prefer-free-formats --youtube-skip-dash-manifest --referer https://www.youtube.com/watch?v=6xKWiCMKKJg
    at makeError (<PATH>\node_modules\execa\lib\error.js:60:11)
    at handlePromise (<PATH>\node_modules\execa\index.js:118:26)
    at processTicksAndRejections (node:internal/process/task_queues:96:5) {
  shortMessage: 'Command failed with exit code 3221225781: <PATH>\\node_modules\\youtube-dl-exec\\bin\\youtube-dl.exe https://www.youtube.com/watch?v=6xKWiCMKKJg --dump-single-json --no-warnings --no-call-home --no-check-certificate --prefer-free-formats --youtube-skip-dash-manifest --referer https://www.youtube.com/watch?v=6xKWiCMKKJg',
  command: '<PATH>\\node_modules\\youtube-dl-exec\\bin\\youtube-dl.exe https://www.youtube.com/watch?v=6xKWiCMKKJg --dump-single-json --no-warnings --no-call-home --no-check-certificate --prefer-free-formats --youtube-skip-dash-manifest --referer https://www.youtube.com/watch?v=6xKWiCMKKJg',
  escapedCommand: '"<PATH>\\node_modules\\youtube-dl-exec\\bin\\youtube-dl.exe" "https://www.youtube.com/watch?v=6xKWiCMKKJg" --dump-single-json --no-warnings --no-call-home --no-check-certificate --prefer-free-formats --youtube-skip-dash-manifest --referer "https://www.youtube.com/watch?v=6xKWiCMKKJg"',
  exitCode: 3221225781,
  signal: undefined,
  signalDescription: undefined,
  stdout: '',
  stderr: '',
  failed: true,
  timedOut: false,
  isCanceled: false,
  killed: false
}

Output error is not very dev friendly give only a not documented error code 3221225781 and call stack.

I've see at other issue same problem has been opened #30 but never response has been provide.
I porpose documented for error code provide at output.

youtube-dl-exec not working?

I ran the example code from the github snippet. It was working 3 days ago: it saved the video to the directory and logged the output in console, but now it no longer works? There's no video output for some reason

const youtubedl = require('youtube-dl-exec')

youtubedl('https://www.youtube.com/watch?v=6xKWiCMKKJg', {
  dumpSingleJson: true,
  noWarnings: true,
  noCallHome: true,
  noCheckCertificate: true,
  preferFreeFormats: true,
  youtubeSkipDashManifest: true,
  referer: 'https://www.youtube.com/watch?v=6xKWiCMKKJg'
}).then(output => console.log(output))

Expose currently configured binary path

I need a way to read the current binary path.

The only way I could find to do this was using require('youtube-dl-exec/src/constants') which works for now but doesn't seem ideal.

It may be useful to export the constants from the module itself. I have created a pull request containing this change.

Pull Request here: #70

Download Progress

Hello,

I'd like to know how to get it's download progress. The output doesn't seems to be working.


const youtubedl = require('youtube-dl-exec');

youtubedl('https://d2zihajmogu5jn.cloudfront.net/bipbop-advanced/bipbop_16x9_variant.m3u8', {
	noWarnings: true,
	noCheckCertificate: true,
}).then((output) => console.log(output));

npm install error

Hi,

I'm getting this error while trying to npm install this package.

image

Do you have any idea how it could be solved ?
Thanks in advance.

getting this error every time i try to install.

i keep getting this error every time i try to install, and yes i do have python.

npm ERR! code 1
npm ERR! path C:\Users\prote\OneDrive\Documents\GitHub\xxxx\node_modules\youtube-dl-exec
npm ERR! command failed
npm ERR! command C:\WINDOWS\system32\cmd.exe /d /s /c npx bin-version-check-cli python ">=2"
npm ERR! Error: Couldn't find version of python
npm ERR! at binaryVersion (file:///C:/Users/prote/AppData/Local/npm-cache/_npx/7b761a280cf4a94b/node_modules/bin-version/index.js:55:8)
npm ERR! at processTicksAndRejections (node:internal/process/task_queues:96:5)
npm ERR! at async binaryVersionCheck (file:///C:/Users/prote/AppData/Local/npm-cache/_npx/7b761a280cf4a94b/node_modules/bin-version-check/index.js:14:18)

npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\prote\AppData\Local\npm-cache_logs\2022-03-21T04_05_37_646Z-debug-0.log

Usage in Electron with Webpack 5

Did anyone got this package working in Electron using Webpack 5?

From what I know the thing which makes this complicated is that webpack 5 does not provide auto-polyfill anymore. Even after trying to add everything necessary I´m just running from one issue to another.

If someone has an idea which steps are needed to make this work, it would be great if you could share this :)

Thanks

Handle different binary filename at runtime

Why

I want to use yt-dlp with youtube-dl-exec. While using https://github.com/microlinkhq/youtube-dl-exec#environment-variables can download the correct binary, but on runtime, we need to set YOUTUBE_DL_FILENAME manually in process.env

How

It should implement or document how to handle different binary filenames at runtime.

Either document how to do it with process.env or create something to handle these different binary filenames, either way, I'm fine

bin-version-check-cli Errors

I've encountered two errors around bin-version-check-cli:

Error 1

When running npm i youtube-dl-exec, I was met with the following error (on both Windows and Linux, though this example is from my windows machine):

T:\all 3\code\search-and-download>npm i youtube-dl-exec
npm ERR! code 1
npm ERR! path T:\all 3\code\search-and-download\node_modules\youtube-dl-exec
npm ERR! command failed
npm ERR! command C:\WINDOWS\system32\cmd.exe /d /s /c npx bin-version-check-cli python ">=2"
npm ERR! 'bin-version-check' is not recognized as an internal or external command,
npm ERR! operable program or batch file.

I was able to solve this by manually running npm i -g bin-version-check-cli, but this could be listed as a dependency for youtube-dl-exec, which I think would solve this issue. (Though, I could be wrong)

Error 2

Even after installing bin-version-check-cli, trying to run npm i youtube-dl-exec yields the following (again, on both OS's):

npm ERR! command failed
npm ERR! command C:\WINDOWS\system32\cmd.exe /d /s /c npx bin-version-check-cli python ">=2"
npm ERR! Error: Couldn't find the `python` binary. Make sure it's installed and in your $PATH.

However, I do have python installed, on both machines. The issue here arises because on both windows and linux, python wasn't a valid command. The valid command was py on windows and python3 on linux. I was able to fix this on windows by installing python from the app store, which added the python command to the terminal. This seems fixable by looking for not just python but py and python3.

Binary Issue [Couldn't find the...]

Hi there,

I actually fot this problem: Error: Couldn't find the python binary. Make sure it's installed and in your $PATH.

Here is the whole log:

npm ERR! path /home/container/node_modules/youtube-dl-exec npm ERR! command failed npm ERR! command sh -c npx bin-version-check-cli python ">=2" npm ERR! Error: Couldn't find the python binary. Make sure it's installed and in your $PATH. npm ERR! at binaryVersion (file:///home/container/.npm/_npx/7b761a280cf4a94b/node_modules/bin-version/index.js:44:22) npm ERR! at processTicksAndRejections (node:internal/process/task_queues:96:5) npm ERR! at async binaryVersionCheck (file:///home/container/.npm/_npx/7b761a280cf4a94b/node_modules/bin-version-check/index.js:14:18)

npm ERR! A complete log of this run can be found in: npm ERR! /home/container/.npm/_logs/2022-02-17T23_06_47_501Z-debug-0.log

I'm actually inside a container, using Docker. My home path is /home/container

Eviroment:

  • NodeJs -> v17.5.0
  • NPM -> 8.5.1
  • Python -> 3.9.2

Anyone who can help me?

Npm install not working because of requirement

Error: Cannot find module 'fs/promises'
Require stack:
-<folder>/node_modules/youtube-dl-exec/scripts/postinstall.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:815:15)
    at Function.Module._load (internal/modules/cjs/loader.js:667:27)
    at Module.require (internal/modules/cjs/loader.js:887:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at Object.<anonymous> (<folder>/node_modules/youtube-dl-exec/scripts/postinstall.js:4:12)
    at Module._compile (internal/modules/cjs/loader.js:999:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
    at Module.load (internal/modules/cjs/loader.js:863:32)
    at Function.Module._load (internal/modules/cjs/loader.js:708:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '<folder>/node_modules/youtube-dl-exec/scripts/postinstall.js'
  ]
}

This is probably fixed with changing

const fs = require("fs/promises");

to

const fs = require("fs").promises;

I reverted back to version 1.0.0 for now.
Love the package 😉

"not a function" and "undefined" upon usage

Hello!

Using the package like so, I seem to get the variable undefined.

 const youtubedl = require("youtube-dl-exec");
 const stream = youtubedl(
    data.queue[0].url,
    {
      o: '-',
      q: '',
      f: 'bestaudio[ext=webm+acodec=opus+asr=48000]/bestaudio',
      r: '100K',
    }, { stdio: ['ignore', 'pipe', 'ignore'] }
  )
  
  console.log(stream); // undefined

I've also tried to use the "raw" method, but that throws a "not a function".

 const youtubedl = require("youtube-dl-exec").raw;
 const stream = youtubedl( 
    data.queue[0].url,
    {
      o: '-',
      q: '',
      f: 'bestaudio[ext=webm+acodec=opus+asr=48000]/bestaudio',
      r: '100K',
    }, { stdio: ['ignore', 'pipe', 'ignore'] }
  )
  
  > "youtubedl" is not a function

My aim is to replace ytdl for my discord music bot with youtube-dl, using your wrapper.
Upon inspection, the package does indeed install a binary - im however very lost in why i cant use the package properly.

image

Edit: "youtube-dl-exec": "^2.0.9",

Handling Readable Stream

I'm working on a whatsapp bot using whatsapp-web.js which is about to download videos from social media. It requires me to send the media either using base64 string or a link.
Is there a way to do this without downloading the video on my desktop ?
I could do it with node-ytdl-core but it only allows youtube videos

Module parse failed: 'import' and 'export' may appear only with 'sourceType: module'

I tried using your code from "Usage" and got : Uncaught ReferenceError: require is not defined.
After that i tried a lot of fixes and changed const youtubedl = require('youtube-dl-exec') to import * as youtubedl from 'youtube-dl-exec'; and got another error : Module parse failed: 'import' and 'export' may appear only with 'sourceType: module' (1:0)

webpack.config.js

module.exports = {
    entry: './src/js/2.js',
    optimization: {
        minimize: false
    },
    devtool: 'inline-source-map',
    resolve: {
        extensions: ['.tsx', '.ts', '.js'],
    },
    module: {
        rules: [
            {
                "test": /\.js$/,
                "exclude": /node_modules/,
                "use": {
                  "loader": "babel-loader",
                  "options": {
                    "presets": [
                      "@babel/preset-env",
                    ]
                  }
                }
              },
        ]
    },
    "mode": "none",
}

Package.json
{
 "scripts": {
  "start": "webpack --mode development --watch"
 },
 "dependencies": {
  "babel-loader": "^8.2.3",
  "path-browserify": "^1.0.1",
  "webpack": "^5.69.1",
  "webpack-cli": "^4.9.2",
  "youtube-dl-exec": "^2.0.5"
 },
  "type": "commonjs",
  
  "babel": {
    "presets": [
      "@babel/env"
  ]
}
}




`youtube-dl` not being downloaded

Just installed the dependency on a new project and realize that it did not work.
Upon inspection inside of .\node_modules\youtube-dl-exec\bin is empty.
EDIT: I have installed this with no antivirus or malware software running, and it still did not install

The current workaround is just copying youtube-dl from another location to the bin folder.

Install details:

  • Node v16.6.1
  • npm 7.23.0
  • Windows 10 21H1 Build 19043.1237

Download binary from custom mirror, e.g. S3

Currently, it seems like the binary can only be downloaded from S3. I created przemyslawpluta/node-youtube-dl#351 on node-youtube-dl

Since this package supersedes node-youtube-dl I think there should be an option for a custom mirror.

A possible implementation could use the YOUTUBE_DL_DIRECT_BINARY_DOWNLOAD_URL environment variable:

YOUTUBE_DL_DIRECT_BINARY_DOWNLOAD_URL - download the youtube-dl binary from the given download url, completely ignoring the ** YOUTUBE_DL_HOST** option, while performing no lookup for retrieving the latest version of the binary. This is useful if you are hosting the youtube-dl binary on your own S3 bucket. The platform-specific extension will be appended.
E.g. the value https://xxxxx.s3.xxxxxx.amazonaws.com/2020.11.12-youtube-dl will result in downloading https://xxxxx.s3.xxxxxx.amazonaws.com/2020.11.12-youtube-dl.exe on windows.

-f option is not being formatted correctly

Issue

When using the -f (format) option, youtube-dl-exec's converter puts a = between -f and the value, instead of a space.

For example: youtubedl(link, { g: true, f: format })

  • It will run as youtube-dl [link] -g -f=[format]
  • It must run youtube-dl [link] -g -f [format] to work.

Other options may also suffer from this problem, but I don't really have time to experiment right now (sorry).

Stacktrace

Error: Command failed with exit code 1: /root/yt2s.hub/node_modules/youtube-dl-exec/bin/youtube-dl https://youtube.com/watch?v=dQw4w9WgXcQ-g -f=140 ERROR: requested format not available at makeError (/root/yt2s.hub/node_modules/execa/lib/error.js:59:11) at handlePromise (/root/yt2s.hub/node_modules/execa/index.js:114:26) at processTicksAndRejections (node:internal/process/task_queues:94:5)

Hi Couldn't find the python binary

I have this error when install with npm im already have python installed python3

npm ERR! code 1
npm ERR! path /home/carlos/Documentos/Development/Projects/NextCloud projects/Node js Bot Nextcloud/node_modules/youtube-dl-exec
npm ERR! command failed
npm ERR! command sh -c npm run check && node scripts/postinstall.js
npm ERR! > [email protected] check
npm ERR! > bin-version-check python ">=2"
npm ERR! Error: Couldn't find the python binary. Make sure it's installed and in your $PATH.

UnhandledPromiseRejectionWarning: TypeError [ERR_INVALID_ARG_TYPE]

W20211109-17:05:13.651(5)? (STDERR) (node:19624) UnhandledPromiseRejectionWarning: TypeError [ERR_INVALID_ARG_TYPE]: The "original" argument must be of type function
W20211109-17:05:13.697(5)? (STDERR) at promisify (internal/util.js:209:11)
W20211109-17:05:13.697(5)? (STDERR) at Object. (D:\irisvision\iv-web-management-platform\node_modules\youtube-dl-exec\node_modules\get-stream\index.js:7:35)
W20211109-17:05:13.697(5)? (STDERR) at Module._compile (module.js:652:30)
W20211109-17:05:13.697(5)? (STDERR) at Object.Module._extensions..js (module.js:663:10)
W20211109-17:05:13.698(5)? (STDERR) at Module.load (module.js:565:32)
W20211109-17:05:13.698(5)? (STDERR) at tryModuleLoad (module.js:505:12)
W20211109-17:05:13.698(5)? (STDERR) at Function.Module._load (module.js:497:3)
W20211109-17:05:13.698(5)? (STDERR) at Module.require (module.js:596:17)
W20211109-17:05:13.698(5)? (STDERR) at require (internal/module.js:11:18)
W20211109-17:05:13.698(5)? (STDERR) at Object. (D:\irisvision\iv-web-management-platform\node_modules\youtube-dl-exec\node_modules\execa\lib\stream.js:3:19)
W20211109-17:05:13.698(5)? (STDERR) at Module._compile (module.js:652:30)
W20211109-17:05:13.699(5)? (STDERR) at Object.Module._extensions..js (module.js:663:10)
W20211109-17:05:13.700(5)? (STDERR) at Module.load (module.js:565:32)
W20211109-17:05:13.700(5)? (STDERR) at tryModuleLoad (module.js:505:12)
W20211109-17:05:13.700(5)? (STDERR) at Function.Module._load (module.js:497:3)
W20211109-17:05:13.700(5)? (STDERR) at Module.require (module.js:596:17)
W20211109-17:05:13.700(5)? (STDERR) (node:19624) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
W20211109-17:05:13.700(5)? (STDERR) (node:19624) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

QA issue: provide please, an example of ES style import

Instead of provided comonjs require i would like to use

import * as youtubedlexec from 'youtube-dl-exec'
const { create: createYoutubeDl } = youtubedlexec
const ytdlpath='path_to_my_ytdl'
const youtubedl = createYoutubeDl(ytdlpath)

then i use example code from readme


youtubedl('https://url-of-mine', {
  dumpSingleJson: true,
  noWarnings: true,
  noCallHome: true,
  noCheckCertificate: true,
  preferFreeFormats: true,
  youtubeSkipDashManifest: true,
  referer: 'https://example.com'
})
  .then(output => console.log(output))

and i got

in output this

{
  id: '40011486',
  ext: 'mp3',
  url: 'http://s17sas.storage.yandex.net/get-mp3/...
skiped }

do i need to fetch url by my self, or youtube-dl-exec can do it? there is no problem but info question
how to do this?

Dependency security issue

This npm package currently (as of v1.2.2) has some security issues within its dependencies, which originate from the bin-version-check-cli package. The last time this package has been updated was two years ago, which is why it uses outdated dependencies. I was trying to resolve the issue, but then I realized this package seems like an unused dependency within your project. Can you please confirm this assumption and if so remove the dependency or otherwise tell me how this package is used within your project?

PS: below is the output of npm audit

                                                                                
                       === npm audit security report ===                        
                                                                                
┌──────────────────────────────────────────────────────────────────────────────┐
│                                Manual Review                                 │
│            Some vulnerabilities require your attention to resolve            │
│                                                                              │
│         Visit https://go.npm.me/audit-guide for additional guidance          │
└──────────────────────────────────────────────────────────────────────────────┘
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ Low           │ Prototype Pollution                                          │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ yargs-parser                                                 │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in    │ >=13.1.2 <14.0.0 || >=15.0.1 <16.0.0 || >=18.1.2             │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ youtube-dl-exec                                              │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ youtube-dl-exec > bin-version-check-cli > meow >             │
│               │ yargs-parser                                                 │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://npmjs.com/advisories/1500                            │
└───────────────┴──────────────────────────────────────────────────────────────┘
found 1 low severity vulnerability in 381 scanned packages
  1 vulnerability requires manual review. See the full report for details.

Cookies aren't being used when looking up explicit content

Hello. I noticed that some videos I try to download are flagged requiring an age limit, so I'm getting a 410 error. I tried adding cookies to my request like the following:
ytdl( this.url, { o: '-', q: '', f: 'bestaudio[ext=webm+acodec=opus+asr=48000]/bestaudio', r: '100K', cookies: 'C:\\Users\\USER\\cookies.txt' }, { stdio: ['ignore', 'pipe', 'ignore'] }, );

However I am still getting the same 410 error. When I run youtube-dl manually e.g.
youtube-dl --cookies=C:\\Users\\USER\\cookies.txt https://www.youtube.com/watch?v=j0lN0w5HVT8&t=1s
it successfully downloads the video.

YoutubeDL doesn't support pipe

Look like youtube object doesn't have the pipe function?

I'm trying to use Lambda + this library to stream youtube videos to S3 Without any download to /tmp

const stream = require('stream');
const youtubedl = require('youtube-dl-exec')
const AWS = require('aws-sdk');

const BUCKET_NAME = "storage-bucket"

    youtubedl.raw('https://www.youtube.com/watch?v=4cquiuAQBco', {
    dumpSingleJson: true,
    noWarnings: true,
    noCallHome: true,
    noCheckCertificate: true,
    preferFreeFormats: true,
    youtubeSkipDashManifest: true,
    referer: 'https://facebook.com',
  })
    .then(
      
      output => {

        console.log(output)

        const passtrough = new stream.PassThrough();        
        console.log(output.id)
        const key = output.id+`.mp4`;
        
        const upload = new AWS.S3.ManagedUpload({
          accessKeyId: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
          secretAccessKey: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
          params: {
            Bucket: BUCKET_NAME,
            Key: key,
            Body: passtrough
          },
          partSize: 1024 * 1024 * 64 // in bytes
        });

        upload.on('httpUploadProgress', (progress) => {
          console.log(`[`+output.id+`] copying video ...`, progress);
        });


        upload.send((err) => {
          if (err) {
            cb(err);
          } else {
            cb(null, {
              bucketName: BUCKET_NAME,
              key,
              url: `s3://`+BUCKET_NAME+`/`+key
            });
          }
        });
        output.pipe(passtrough);


      })

consider switching to yt-dlp?

hello,
since the official youtube-dl release does not seems to be up to date I'm trying out the yt-dlp fork and so far it seems to work fine (and faster)

if someone is interested in testing those are the necessary ENVs:

YOUTUBE_DL_HOST=https://api.github.com/repos/yt-dlp/yt-dlp/releases?per_page=1
YOUTUBE_DL_FILENAME=yt-dlp

beside some different output behavior it works, so my suggestion is to consider an official switch -- if not feel free to close, thanks for the lib!

Setting dumpJson: false throws an error

throws:

youtube-dl: error: no such option: --no-dump-json

I realize I can just leave it off and it works, but if someone programatically sets it to false, it shoudn't prepend --no-

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.