Skip to content

BobbyESP/youtubedl-android

 
 

Repository files navigation

youtubedl-android

Android library wrapper for yt-dlp (formerly youtube-dl) executable.

Maven Central Version

Credits

  • youtubedl-java by sapher. youtubedl-android extends youtubedl-java by adding Android compatibility.

Sample App

A debug APK for testing can be downloaded from the releases page.

Download Example Streaming Example

Using a Configuration File

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"

Related Projects

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.

Installation

Gradle

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
}

Android Configuration

  • Set android:extractNativeLibs="true" in your app's manifest.
  • Use abiFilters 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a' in app/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/ and Documents/ directories. See the related issue.

Usage

Initialization

try {
    YoutubeDL.getInstance().init(this);
} catch (YoutubeDLException e) {
    Log.e(TAG, "Failed to initialize youtubedl-android", e);
}

Downloading / Custom Command

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)");
});

Stopping a Download

final String processId = "MyProcessDownloadId";
YoutubeDL.getInstance().execute(request, (progress, etaInSeconds) -> {
    System.out.println(progress + "% (ETA " + etaInSeconds + " seconds)");
}, processId);
...
YoutubeDL.getInstance().destroyProcessById(processId);

Getting Stream Info

Equivalent to --dump-json in yt-dlp.

VideoInfo streamInfo = YoutubeDL.getInstance().getInfo("https://vimeo.com/22439234");
System.out.println(streamInfo.getTitle());

Getting a Single Playable Link (Video + Audio)

YoutubeDLRequest request = new YoutubeDLRequest("https://youtu.be/Pv61yEcOqpw");
request.addOption("-f", "best");
VideoInfo streamInfo = YoutubeDL.getInstance().getInfo(request);
System.out.println(streamInfo.getUrl());

Updating yt-dlp Binary

An example can be found in the sample app.

YoutubeDL.getInstance().updateYoutubeDL(this, UpdateChannel.STABLE);

FFmpeg Support

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);
}

Aria2c Support

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);
}

Configuring aria2c

request.addOption("--downloader", "libaria2c.so");

Documentation

Donate

Support the project with a donation:

Type Address
Bitcoin bc1qw3g7grh6dxk69mzwjmewanj9gj2ycc5mju5dc4
Monero 49SQgJTxoifhRB1vZGzKwUXUUNPMsrsxEacZ8bRs5tqeFgxFUHyDFBiUYh3UBRLAq355tc2694gbX9LNT7Ho7Vch2XEP4n4

About

youtube-dl for android

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Kotlin 55.0%
  • Java 45.0%