A 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
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependency>
<groupId>com.github.Wonkglorg</groupId>
<artifactId>yt-dlp-java</artifactId>
<version>(Release Version)</version>
</dependency>
dependencies {
implementation 'com.github.Wonkglorg:yt-dlp-java:Tag'
}
repositories {
maven { url 'https://jitpack.io' }
}
// 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 outputYou may also specify callbacks to get notified about start /the progress and end of the download:
YtDlpRequest request = new YtDlpRequest(VIDEO_URL, DIRECTORY);
request.setDownloadProgressCallback((progress) ->
System.out.println("Downloading %s at %s out of %s".formatted(progress.fileName(), progress.downloadSpeed(), progress.progressPercent())));
YtDlp.execute(request);Provides Typesafe representations of yt-dlp data callbacks to more securely access and see what data is available when using a predefined helper methods including video and playlist data.
// Request
Optional<VideoInfo> videoInfo = YtDlp.getVideoInfo("https://www.youtube.com/watch?v=dQw4w9WgXcQ");
// Accesing the optional if a valid url was given
videoInfo.ifPresent(info -> {
// Accessing data typesafe
String channelID = info.getChannelId();
String videoDescription = info.getDescription();
Map<String, List<Caption>> videoCaptions = info.getAutomaticCaptions();
}
);Built in way to easily download videos and audio, also supports callbacks
VideoFileInfo<VideoInfo> videoFileInfo = new DownloadBuilder(VIDEO_URL, DIRECTORY)
.setFormatOption(FormatOption.MP3) //the format to download the file in
.setOutputName("%(title)s") //the name the file should have
.download(); //starts the download and returns information about the file and its data