Convert Figma logo to code with AI

yausername logoyoutubedl-android

youtube-dl for android

1,005
182
1,005
74

Top Related Projects

82,065

A feature-rich command-line audio/video downloader

131,248

Command-line program to download videos from YouTube.com and other video sites

31,338

A libre lightweight streaming front-end for Android.

Quick Overview

youtubedl-android is an Android library that provides a wrapper for youtube-dl, allowing developers to easily integrate YouTube video downloading functionality into their Android applications. It offers a convenient way to extract video and audio information from YouTube and other supported platforms.

Pros

  • Easy integration into Android projects
  • Supports downloading from multiple platforms, not just YouTube
  • Regular updates to keep up with changes in YouTube's infrastructure
  • Provides both synchronous and asynchronous download options

Cons

  • Depends on youtube-dl, which may face legal challenges
  • Potential performance issues on low-end devices
  • May require frequent updates to maintain compatibility with YouTube changes
  • Limited documentation and examples

Code Examples

  1. Initializing the library:
YoutubeDLOptions youtubeDLOptions = new YoutubeDLOptions();
YoutubeDL.getInstance().init(context, youtubeDLOptions);
  1. Downloading video information:
String videoUrl = "https://www.youtube.com/watch?v=dQw4w9WgXcQ";
VideoInfo videoInfo = YoutubeDL.getInstance().getInfo(videoUrl);
String title = videoInfo.getTitle();
String thumbnail = videoInfo.getThumbnail();
  1. Downloading a video:
String videoUrl = "https://www.youtube.com/watch?v=dQw4w9WgXcQ";
File downloadPath = new File(getExternalFilesDir(null), "downloads");
YoutubeDLRequest request = new YoutubeDLRequest(videoUrl);
request.addOption("-o", downloadPath.getAbsolutePath() + "/%(title)s.%(ext)s");
YoutubeDL.getInstance().execute(request, (progress, etaInSeconds) -> {
    System.out.println(progress + "% (ETA " + etaInSeconds + " seconds)");
});

Getting Started

To use youtubedl-android in your Android project:

  1. Add the JitPack repository to your project's build.gradle file:
allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}
  1. Add the dependency to your app's build.gradle file:
dependencies {
    implementation 'com.github.yausername.youtubedl-android:library:0.14.+'
}
  1. Initialize the library in your application's onCreate method:
YoutubeDL.getInstance().init(getApplicationContext());

Now you can use the YoutubeDL class to download video information and content from YouTube and other supported platforms.

Competitor Comparisons

82,065

A feature-rich command-line audio/video downloader

Pros of yt-dlp

  • More comprehensive support for various video platforms beyond YouTube
  • Actively maintained with frequent updates and bug fixes
  • Supports advanced features like SponsorBlock integration and video chapters

Cons of yt-dlp

  • Not specifically designed for Android integration
  • May require more setup and configuration for mobile use
  • Larger codebase, potentially leading to a bigger app size when integrated

Code Comparison

yt-dlp (Python):

ydl_opts = {'format': 'bestaudio/best'}
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
    ydl.download(['https://www.youtube.com/watch?v=dQw4w9WgXcQ'])

youtubedl-android (Java):

YoutubeDLRequest request = new YoutubeDLRequest("https://www.youtube.com/watch?v=dQw4w9WgXcQ");
request.addOption("-f", "bestaudio/best");
YoutubeDL.getInstance().execute(request, callback);

The code snippets show that yt-dlp uses Python and is more concise, while youtubedl-android provides a Java wrapper for easier Android integration. youtubedl-android offers a more native Android development experience, but yt-dlp provides more flexibility and features for video downloading across platforms.

131,248

Command-line program to download videos from YouTube.com and other video sites

Pros of youtube-dl

  • More comprehensive support for various websites and video platforms
  • Extensive command-line options for customization
  • Actively maintained with frequent updates and bug fixes

Cons of youtube-dl

  • Not specifically designed for Android integration
  • Requires additional setup and configuration for mobile use
  • May have performance limitations on mobile devices

Code Comparison

youtube-dl (Python):

ydl_opts = {'format': 'bestaudio/best'}
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
    ydl.download(['https://www.youtube.com/watch?v=dQw4w9WgXcQ'])

youtubedl-android (Java):

YoutubeDLRequest request = new YoutubeDLRequest("https://www.youtube.com/watch?v=dQw4w9WgXcQ");
request.addOption("-f", "bestaudio/best");
YoutubeDL.getInstance().execute(request, callback);

Summary

youtube-dl is a versatile and powerful tool for downloading videos from various platforms, offering extensive customization options and broad website support. However, it's not specifically designed for Android integration.

youtubedl-android, on the other hand, is tailored for Android use, providing a more streamlined experience for mobile applications. It may have limitations in terms of supported websites and features compared to youtube-dl, but it offers better integration with Android development workflows.

The code comparison shows that while youtube-dl uses Python and is more straightforward for command-line use, youtubedl-android provides a Java interface that's more suitable for Android app development.

31,338

A libre lightweight streaming front-end for Android.

Pros of NewPipe

  • Full-featured YouTube client with a wide range of functionalities
  • Open-source and ad-free, respecting user privacy
  • Supports background playback and picture-in-picture mode

Cons of NewPipe

  • Requires separate installation, not available on Google Play Store
  • May break occasionally due to YouTube API changes
  • Limited to YouTube content, unlike youtubedl-android's broader support

Code Comparison

NewPipe uses a custom extractor for YouTube content:

public class YoutubeStreamExtractor extends StreamExtractor {
    // Custom implementation for YouTube extraction
}

youtubedl-android utilizes youtube-dl as a backend:

YoutubeDLRequest request = new YoutubeDLRequest(youtubeLink);
YoutubeDL.getInstance().execute(request, callback);

NewPipe offers a more integrated Android experience, while youtubedl-android provides a flexible library for developers to incorporate YouTube downloading functionality into their apps. NewPipe is a standalone app focused on YouTube, whereas youtubedl-android is a library that can be integrated into other applications and supports multiple platforms beyond YouTube.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

youtubedl-android

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

Maven Central Version

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.

Also take a look at Seal, another video/audio downloader app which demonstrates 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
}
  • 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 (API 29), set android:requestLegacyExternalStorage="true".
  • On Android 10+ (API 30 or higher), due to Android's Scoped Storage changes, apps only have the direct access to Download/ and Documents/ . And you can only download the videos into these two directories, see related issue.

Usage

  • yt-dlp executable and python 3.8 are bundled in the library.
  • Initialize library, preferably in onCreate.
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(String.valueOf(progress) + "% (ETA " + String.valueOf(etaInSeconds) + " seconds)");
    });
  • Stopping a previously started download process
    YoutubeDLRequest request = new YoutubeDLRequest("https://vimeo.com/22439234");
    final String processId = "MyProcessDownloadId";
    YoutubeDL.getInstance().execute(request, (progress, etaInSeconds) -> {
    System.out.println(String.valueOf(progress) + "% (ETA " + String.valueOf(etaInSeconds) + " seconds)");
    }, processId);
    ...
    YoutubeDL.getInstance().destroyProcessById(processId);
  • Get stream info (equivalent to --dump-json of yt-dlp)
    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());
  • yt-dlp supports myriad different options which be seen here

  • yt-dlp binary can be updated from within the library (A example can be found in the sample app)

    YoutubeDL.getInstance().updateYoutubeDL(this, updateChannel); // UpdateChannel.NIGHTLY or UpdateChannel.STABLE

FFmpeg

If you wish to use ffmpeg features of 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

This library can make use of aria2c as the 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);
}

and options for the request as below:

request.addOption("--downloader", "libaria2c.so");
request.addOption("--external-downloader-args", "aria2c:\"--summary-interval=1\"");

Docs

Donate

You can support the project by donating to below addresses.

TypeAddress
Bitcoinbc1qw3g7grh6dxk69mzwjmewanj9gj2ycc5mju5dc4
Monero49SQgJTxoifhRB1vZGzKwUXUUNPMsrsxEacZ8bRs5tqeFgxFUHyDFBiUYh3UBRLAq355tc2694gbX9LNT7Ho7Vch2XEP4n4