Skip to content

nose-gnome/youtubedl-android

 
 

Repository files navigation

youtubedl-android

Android library wrapper for youtube-dl executable

Credits


Sample app

Debug apk for testing can be downloaded from the releases page

Download Example Streaming Example

If you wish to use config file in the download option by using this command --config-location you must create a file named config.txt inside youtubedl-android directory and add the 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"

Checkout dvd, a video downloader app based on this library.

dvd

Installation

Gradle

Step 1 : Add jitpack repository to your project build file

allprojects {
    repositories {
        maven { url 'https://jitpack.io' }
    }
}

Step 2: Add the dependency

dependencies {
    implementation 'com.github.yausername.youtubedl-android:library:0.12.+'
}

Optional FFmpeg dependency can also be added

dependencies {
    implementation 'com.github.yausername.youtubedl-android:library:0.12.+'
    implementation 'com.github.yausername.youtubedl-android:ffmpeg:0.12.+'
}

  • Set android:extractNativeLibs="true" in your app's manifest.
  • Use abiFilters 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a' in app/build.gradle, see sample app.
  • Use abi splits to reduce apk size, see sample app.
  • On android 10 set android:requestLegacyExternalStorage="true". I haven't tested with scoped storage, feel free to do so.

Usage

  • youtube-dl executable and python 3.8 are bundled in the library.
  • Initialize library, preferably in onCreate.
try {
    YoutubeDL.getInstance().init(getApplication());
} 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(String.valueOf(progress) + "% (ETA " + String.valueOf(etaInSeconds) + " seconds)");
});
  • Get stream info (equivalent to --dump-json of youtube-dl)
VideoInfo streamInfo = YoutubeDL.getInstance().getInfo("https://vimeo.com/22439234");
System.out.println(streamInfo.getTitle());
  • Get a single playable link containing 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());
  • youtube-dl supports myriad different options which be seen here

  • youtube-dl binary can be updated from within the library

YoutubeDL.getInstance().updateYoutubeDL(getApplication());

FFmpeg

If you wish to use ffmpeg features of youtube-dl (e.g. --extract-audio), include and initialize the ffmpeg library.

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

Docs

  • Though not required for just using this library, documentation on building python for android can be seen here. Same for ffmpeg here. Alternatively, you can use pre-built packages from here (android5+) or here (android7+).
  • youtubedl-android uses lazy extractors based build of youtube-dl (youtubedl-lazy)

About

youtube-dl for android

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 100.0%