Java youtube-dl 没有那个文件或目录
Java youtube-dl no such file or directory
我正在尝试从 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!");
}
}
我想通了。
我必须补充:
YoutubeDL.setExecutablePath("/usr/local/Cellar/youtube-dl/2017.09.15/bin/youtube-dl");
我正在尝试从 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!");
}
}
我想通了。
我必须补充:
YoutubeDL.setExecutablePath("/usr/local/Cellar/youtube-dl/2017.09.15/bin/youtube-dl");