我试图从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!");
}
}
答案 0 :(得分:0)
我明白了。
我不得不补充道:
<a class="page-content-header-item" routerLink="/page1" routerLinkActive="selected">Page 1</a>