-
Notifications
You must be signed in to change notification settings - Fork 0
Getting Started
LucQuebec edited this page Jul 2, 2026
·
4 revisions
- Android 7.0+ (API level 24)
-
INTERNETpermission in your manifest
In your settings.gradle (or settings.gradle.kts):
dependencyResolutionManagement {
repositories {
google()
mavenCentral()
maven { url 'https://jitpack.io' }
}
}// app/build.gradle
dependencies {
implementation 'com.github.ffmpegkit-maintained:yt-dlp-android:1.0.1'
}<!-- AndroidManifest.xml -->
<uses-permission android:name="android.permission.INTERNET" />Initialize the library once, before any download. The best place is your Application class or the first Activity:
import com.lucquebec.ytdlp.YtDlp;
import com.lucquebec.ytdlp.YtDlpException;
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
try {
YtDlp.init(this);
} catch (YtDlpException e) {
Log.e("YtDlp", "Initialization failed", e);
}
}
}import com.lucquebec.ytdlp.YtDlp;
import com.lucquebec.ytdlp.YtDlpRequest;
import com.lucquebec.ytdlp.YtDlpResponse;
import com.lucquebec.ytdlp.YtDlpException;
// Build the request
String outputPath = getExternalFilesDir(null).getAbsolutePath() + "/%(title)s.%(ext)s";
YtDlpRequest request = new YtDlpRequest("https://example.com/video")
.setOutputTemplate(outputPath)
.addOption("-f", "best[height<=720]"); // max 720p
// Execute asynchronously (runs on a background thread)
YtDlp.executeAsync(request, (progress, etaInSeconds, line) -> {
// Called on the background thread — use runOnUiThread() to update UI
runOnUiThread(() -> {
progressBar.setProgress((int) progress);
etaTextView.setText("ETA: " + etaInSeconds + "s");
});
});The
%(title)s.%(ext)stemplate is a yt-dlp output template — it fills in the video title and file extension automatically. See yt-dlp output templates for all options.
// Best quality available
request.addOption("-f", "best");
// Best quality up to 1080p
request.addOption("-f", "best[height<=1080]");
// Audio only (mp3)
request.addOption("-f", "bestaudio")
.addOption("--extract-audio")
.addOption("--audio-format", "mp3");
// Specific format code (get format list first)
request.addOption("-f", "137+140"); // 1080p video + audio mergedSites change their APIs regularly. Keep the bundled yt-dlp binary current:
YtDlp.updateYtDlp(context, new YtDlp.UpdateCallback() {
@Override
public void onComplete(String status) {
Log.d("YtDlp", "Update status: " + status);
}
@Override
public void onError(String error) {
Log.e("YtDlp", "Update failed: " + error);
}
});- Cookie Authentication — for sites that require login
- API Reference — full list of options and methods
- Troubleshooting — if something isn't working