Nodejs Youtube:Spawn未知错误

时间:2018-04-11 08:29:46

标签: node.js download youtube-api youtube-data-api youtube-dl

我在nodejs中的代码是这样的: -

var fs = require('fs');
var youtubedl = require('youtube-dl');
var video = youtubedl('http://www.youtube.com/watch?v=90AiXO1pAiA',
  // Optional arguments passed to youtube-dl.

  // Additional options can be given for calling `child_process.execFile()`.
  );

// Will be called when the download starts.

video.on('info', function(info) {
  console.log('Download started');
  console.log('filename: ' + info.filename);
  console.log('size: ' + info.size);
});

video.pipe(fs.createWriteStream('myvideo.mp4'));

我收到此错误: -

  

SPAWN未知

您还可以建议另一种制作youtube下载程序的方法。

1 个答案:

答案 0 :(得分:3)

我在Windows上遇到同样的问题,我将其修复为:

第1步: 转到linkhttps://rg3.github.io/youtube-dl/download.html

第2步: 下载Windows exe (sig - SHA256 7071c7a2.....................)

第3步: 将其替换为\node_modules\youtube-dl\bin

第4步: 运行你的代码:

const fs = require('fs');
const youTube = require('youtube-dl');
const video = youTube('http://www.youtube.com/watch?v=90AiXO1pAiA');

// called when the download starts.
video.on('info', function(info) {
    console.log('Download started');
    console.log('filename: ' + info.filename);
    console.log('size: ' + info.size);
});

video.pipe(fs.createWriteStream('downloads/downloaded_video.mp4'));

第5步: 预期的控制台输出:

/*  Sample Output   */
/*
    Download started
    filename: lol-90AiXO1pAiA.webm
    size: 1029843
    NOTE: File will be downloaded in downloads folder
*/

完整文件和正在运行的项目:

克隆节点作弊youtube_download_videos,运行node download_script.js后跟npm i youtube-dl