Android library wrapper for yt-dlp (formerly youtube-dl) executable.
- youtubedl-java by sapher. youtubedl-android extends youtubedl-java by adding Android compatibility.
A debug APK for testing can be downloaded from the releases page.
If you wish to use a configuration file with the --config-location
option, create a file named config.txt
inside the youtubedl-android
directory and add your preferred commands, for example:
--no-mtime
-o /sdcard/Download/youtubedl-android/%(title)s.%(ext)s
-f "bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best"
Check out dvd, a video downloader app based on this library.
Also, take a look at Seal, another video/audio downloader app showcasing a more advanced and customized use of this library.
repositories {
mavenCentral()
}
dependencies {
implementation("io.github.junkfood02.youtubedl-android:library:0.16.0")
implementation("io.github.junkfood02.youtubedl-android:ffmpeg:0.16.0")
implementation("io.github.junkfood02.youtubedl-android:aria2c:0.16.0") // Optional
}
- Set
android:extractNativeLibs="true"
in your app's manifest. - Use
abiFilters 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a'
inapp/build.gradle
. See the sample app. - Use ABI splits to reduce APK size. See the sample app.
- On Android 10 (API 29), set
android:requestLegacyExternalStorage="true"
. - On Android 10+ (API 30 or higher), due to Scoped Storage changes, apps can only directly access the
Download/
andDocuments/
directories. See the related issue.
try {
YoutubeDL.getInstance().init(this);
} catch (YoutubeDLException e) {
Log.e(TAG, "Failed to initialize youtubedl-android", e);
}
A detailed example can be found in the sample app.
File youtubeDLDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), "youtubedl-android");
YoutubeDLRequest request = new YoutubeDLRequest("https://vimeo.com/22439234");
request.addOption("-o", youtubeDLDir.getAbsolutePath() + "/%(title)s.%(ext)s");
YoutubeDL.getInstance().execute(request, (progress, etaInSeconds) -> {
System.out.println(progress + "% (ETA " + etaInSeconds + " seconds)");
});
final String processId = "MyProcessDownloadId";
YoutubeDL.getInstance().execute(request, (progress, etaInSeconds) -> {
System.out.println(progress + "% (ETA " + etaInSeconds + " seconds)");
}, processId);
...
YoutubeDL.getInstance().destroyProcessById(processId);
Equivalent to --dump-json
in yt-dlp.
VideoInfo streamInfo = YoutubeDL.getInstance().getInfo("https://vimeo.com/22439234");
System.out.println(streamInfo.getTitle());
YoutubeDLRequest request = new YoutubeDLRequest("https://youtu.be/Pv61yEcOqpw");
request.addOption("-f", "best");
VideoInfo streamInfo = YoutubeDL.getInstance().getInfo(request);
System.out.println(streamInfo.getUrl());
An example can be found in the sample app.
YoutubeDL.getInstance().updateYoutubeDL(this, UpdateChannel.STABLE);
To use FFmpeg features in yt-dlp (e.g., --extract-audio
), include and initialize the FFmpeg library:
try {
YoutubeDL.getInstance().init(this);
FFmpeg.getInstance().init(this);
} catch (YoutubeDLException e) {
Log.e(TAG, "Failed to initialize youtubedl-android", e);
}
To use aria2c
as an external downloader, include and initialize the aria2c
library:
try {
YoutubeDL.getInstance().init(this);
FFmpeg.getInstance().init(this);
Aria2c.getInstance().init(this);
} catch (YoutubeDLException e) {
Log.e(TAG, "Failed to initialize youtubedl-android", e);
}
request.addOption("--downloader", "libaria2c.so");
- Building Python for Android: BUILD_PYTHON.md
- Building FFmpeg: BUILD_FFMPEG.md
- yt-dlp Lazy Extractors: ytdlp-lazy
- Building
aria2
: Requireslibc++, c-ares, OpenSSL, libxml2, zlib, libiconv
. See the method used to build Python or FFmpeg.
Support the project with a donation:
Type | Address |
---|---|
bc1qw3g7grh6dxk69mzwjmewanj9gj2ycc5mju5dc4 | |
49SQgJTxoifhRB1vZGzKwUXUUNPMsrsxEacZ8bRs5tqeFgxFUHyDFBiUYh3UBRLAq355tc2694gbX9LNT7Ho7Vch2XEP4n4 |