代码之家  ›  专栏  ›  技术社区  ›  Spud

Java youtube dl没有这样的文件或目录

  •  1
  • Spud  · 技术社区  · 7 年前

    我正试图从youtube视频下载音频;将其保存在工作目录中 a.mp3 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!");
    
        }
    
    }
    
    1 回复  |  直到 7 年前
        1
  •  1
  •   Spud    7 年前

    我想出来了。

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