【问题标题】:Java youtube-dl no such file or directoryJava youtube-dl 没有这样的文件或目录
【发布时间】:2017-09-20 20:19:31
【问题描述】:

我正在尝试从 youtube 视频下载音频并将其保存在工作目录中为a.mp3。我在这里使用我喜欢的 youtube-dl java 包装器:https://github.com/sapher/youtubedl-java

据我所知,它设置正确,并且我确实提供了一个有效的目录,但我不断得到:

Exception in thread "main" com.sapher.youtubedl.YoutubeDLException: Cannot run program "youtube-dl" (in directory "/Users/stephenogden/workspace/Gary"): error=2, No such file or directory
    at com.sapher.youtubedl.YoutubeDL.execute(YoutubeDL.java:69)
    at TestingFunctions.functionTotest(TestingFunctions.java:43)
    at TestingFunctions.main(TestingFunctions.java:15)

我已尝试移动目标目录,但问题仍然存在。

这是我正在使用的代码:

import java.io.File;
import java.io.IOException;

import com.sapher.youtubedl.YoutubeDL;
import com.sapher.youtubedl.YoutubeDLException;
import com.sapher.youtubedl.YoutubeDLRequest;
import com.sapher.youtubedl.YoutubeDLResponse;

public class TestingFunctions {

    public static void main(String[] args) throws InterruptedException, YoutubeDLException {
        try {

            functionTotest("https://www.youtube.com/watch?v=DECxluN8OZM");

        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void functionTotest(String url) throws IOException, InterruptedException, YoutubeDLException {

        File a = new File("a.mp3");
        if (a.exists()) {
            a.delete();
        }

        // This is the command to run

        String videoUrl = url;
        String directory = System.getProperty("user.dir");

        YoutubeDLRequest request = new YoutubeDLRequest(videoUrl, directory);

        request.setOption("no-mark-watched");
        request.setOption("ignore-errors");
        request.setOption("no-playlist");
        request.setOption("extract-audio");
        request.setOption("audio-format \"mp3\"");
        request.setOption("output \"a.%(ext)s\"");

        YoutubeDLResponse response = YoutubeDL.execute(request);

        String stdOut = response.getOut();

        System.out.println(stdOut);
        System.out.println("File downloaded!");

    }

}

【问题讨论】:

  • 您是否先安装了youtube-dl?如果是 - 您是否将 int 添加到您的 $PATH 中?
  • 是的,我已经安装了它,我使用了brew install youtube-dl,因为这是选项之一。

标签: java youtube youtube-dl


【解决方案1】:

我想通了。

我必须补充:

YoutubeDL.setExecutablePath("/usr/local/Cellar/youtube-dl/2017.09.15/bin/youtube-dl");

【讨论】:

    猜你喜欢
    • 2013-12-05
    • 2015-09-25
    • 2018-01-28
    • 2020-08-05
    • 2017-12-14
    • 2018-12-30
    • 2021-06-24
    • 2015-02-20
    相关资源
    最近更新 更多