Step 1. Add the JitPack repository to your build file
Add it in your root settings.gradle at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
Add it in your settings.gradle.kts at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url = uri("https://jitpack.io") }
}
}
Add to pom.xml
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Add it in your build.sbt at the end of resolvers:
resolvers += "jitpack" at "https://jitpack.io"
Add it in your project.clj at the end of repositories:
:repositories [["jitpack" "https://jitpack.io"]]
Step 2. Add the dependency
dependencies {
implementation 'com.github.sapher:youtubedl-java:1.1'
}
dependencies {
implementation("com.github.sapher:youtubedl-java:1.1")
}
<dependency>
<groupId>com.github.sapher</groupId>
<artifactId>youtubedl-java</artifactId>
<version>1.1</version>
</dependency>
libraryDependencies += "com.github.sapher" % "youtubedl-java" % "1.1"
:dependencies [[com.github.sapher/youtubedl-java "1.1"]]
A simple java wrapper for youtube-dl executable
There's a lot of thing left to do. Parsing output is one of them. Too bad, youtube-dl doesn't output formatted data.
:warning: Youtube-dl should be installed and available in your `$PATH.
How to properly install YoutubeDL executable
Otherwise you will get this error :
Cannot run program "youtube-dl" (in directory "/Users/my/beautiful/path"): error=2, No such file or directory
You can use jitpack.io to add the library to your project.
Step 1 : Add jitpack repository to your build file
allprojects {
repositories {
maven { url 'https://jitpack.io' }
}
}
Step 2: Add the dependency
dependencies {
compile 'com.github.sapher:youtubedl-java:1.+'
}
// Video url to download
String videoUrl = "https://www.youtube.com/watch?v=dQw4w9WgXcQ";
// Destination directory
String directory = System.getProperty("user.home");
// Build request
YoutubeDLRequest request = new YoutubeDLRequest(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
YoutubeDLResponse response = YoutubeDL.execute(request);
// Response
String stdOut = response.getOut(); // Executable output
You may also specify a callback to get notified about the progress of the download:
...
YoutubeDLResponse response = YoutubeDL.execute(request, new DownloadProgressCallback() {
@Override
public void onProgressUpdate(float progress, long etaInSeconds) {
System.out.println(String.valueOf(progress) + "%");
}
});