【问题标题】:Getting information about files using node youtube-dl with MeteorJS使用带有 MeteorJS 的节点 youtube-dl 获取有关文件的信息
【发布时间】:2015-07-09 18:50:14
【问题描述】:

我使用 node youtube-dl modul 和 Meteor.js 来获取有关 youtube 视频的信息,因为我正在学习使用 Meteor 服务器端,但是我得到了这个我半天都无法解决的错误。由于 youtube-dl 是 npm 模块,Meteor 可以在没有进一步定制的情况下使用吗?

客户端代码:

if (Meteor.isClient) {
  Template.front.events({
    'click #buttondl': function () {
      // if submited link to input
      if (inputdl.value != '') {
        var link = inputdl.value;
        Meteor.call('information', link);
      }
    }
  });
}

服务器代码:

if (Meteor.isServer) {
  Meteor.methods({
    information: function (link) {
      var youtubedl = Meteor.require('youtube-dl');
      var url = youtubedl(link);

      youtubedl.getInfo(url, function(err, info) {
        if (err) throw err;

        console.log('id:', info.id);
        console.log('title:', info.title);
        console.log('url:', info.url);
        console.log('thumbnail:', info.thumbnail);
        console.log('description:', info.description);
        console.log('filename:', info._filename);
        console.log('duration:', info.duration);
        console.log('format_id:', info.format_id);
      });
    }
  });
}

我得到的错误是:

W20150709-14:35:19.472(-4)? (STDERR) events.js:72
W20150709-14:35:19.472(-4)? (STDERR)         throw er; // Unhandled 'error' event
W20150709-14:35:19.472(-4)? (STDERR)               ^
W20150709-14:35:19.477(-4)? (STDERR) Error: Command failed:   File "/Users/matejhlavacka/node_modules/youtube-dl/bin/youtube-dl", line 2
W20150709-14:35:19.478(-4)? (STDERR) SyntaxError: Non-ASCII character '\xc4' in file /Users/matejhlavacka/node_modules/youtube-dl/bin/youtube-dl on line 3, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details
W20150709-14:35:19.478(-4)? (STDERR) 
W20150709-14:35:19.478(-4)? (STDERR)     at ChildProcess.exithandler (child_process.js:658:15)
W20150709-14:35:19.478(-4)? (STDERR)     at ChildProcess.emit (events.js:98:17)
W20150709-14:35:19.478(-4)? (STDERR)     at maybeClose (child_process.js:766:16)
W20150709-14:35:19.478(-4)? (STDERR)     at Socket.<anonymous> (child_process.js:979:11)
W20150709-14:35:19.478(-4)? (STDERR)     at Socket.emit (events.js:95:17)
W20150709-14:35:19.479(-4)? (STDERR)     at Pipe.close (net.js:466:12)

编辑:

我终于解决了。而不是node-youtube-dl,我使用基本的python youtube-dlhow to execute unix command with Meteor 上的本教程。

在服务器上获取视频描述的示例代码如下:

Meteor.methods({
    information: function (link) {

        exec = Npm.require('child_process').exec;

        runCommand = function (error, stdout, stderr) {
          console.log('stdout: ' + stdout);
          console.log('stderr: ' + stderr);

          if(error !== null) {
            console.log('exec error: ' + error);
          }
        }

        exec("youtube-dl --get-description " + link, runCommand);

    }
});

【问题讨论】:

    标签: javascript node.js meteor youtube-dl


    【解决方案1】:

    它失败可能是因为你的 python 版本太旧,因为documented in the youtube-dl FAQ 你需要 python 2.6 或更高版本。升级python应该可以解决这个问题。

    【讨论】:

    • 我的 OS X Yosemite 默认安装了 python 2.7,但我重新安装到 Python 2.7.9 后仍然出现同样的错误。
    • 这很奇怪,您应该检查从 node.js 运行 python --version 时得到的输出。
    • 我已经解决了这个问题 - 请参阅上面的编辑问题。
    猜你喜欢
    • 2020-11-02
    • 1970-01-01
    • 2021-02-16
    • 2017-11-12
    • 2020-12-28
    • 2014-07-06
    • 2023-01-21
    • 2013-01-16
    • 2021-04-15
    相关资源
    最近更新 更多