A simple java wrapper for yt-dlp executable
How to properly install yt-dlp executable
Otherwise you will get this error :
Cannot run program "yt-dlp" (in directory "/Users/my/beautiful/path"): error=2, No such file or directory
Pending..
// Video url to download
String videoUrl = "https://www.youtube.com/watch?v=dQw4w9WgXcQ";
// Destination directory
String directory = System.getProperty("user.home");
// Build request
YtDlpRequest request = new YtDlpRequest(videoUrl, directory);
request.setOption("ignore-errors"); // --ignore-errors
request.setOption("output", "%(id)s"); // --output "%(id)s"
request.setOption("retries", 10); // --retries 10
// Make request and return response
YtDlpResponse response = YtDlp.execute(request);
// Response
String stdOut = response.getOut(); // Executable output
You may also specify a callback to get notified about the progress of the download:
...
YtDlpResponse response = YtDlp.execute(request, new DownloadProgressCallback() {
@Override
public void onProgressUpdate(float progress, long etaInSeconds) {
System.out.println(String.valueOf(progress) + "%");
}
});