flutter_ytdlp_plugin 2.0.2
flutter_ytdlp_plugin: ^2.0.2 copied to clipboard
A Flutter plugin for YouTube video streaming using yt-dlp. Supports fetching video formats, related videos, and more.
Flutter YTDLP Plugin #
A Flutter plugin that provides YouTube stream extraction capabilities using yt-dlp.
This plugin uses Chaquopy to execute Python code on Android devices for advanced video/audio extraction.
โจ Features #
- โ Check video availability status
- ๐ฅ Extract video streams with quality preferences
- ๐ Extract audio streams with bitrate preferences
- ๐ Get unified streams (video + audio) with codec options
- โก Concurrent processing for performance
- ๐ Automatic debug mode detection
- ๐ก๏ธ Robust error handling
๐ฑ Platform Support #
| Platform | Support |
|---|---|
| Android | โ Supported |
| iOS | โ Not supported |
| Web | โ Not supported |
| Desktop | โ Not supported |
๐ฆ Installation #
Add this to your pubspec.yaml:
dependencies:
flutter_ytdlp_plugin:
git:
url: https://github.com/your-repo/flutter_ytdlp_plugin.git
ref: main
โ๏ธ Android Setup #
1. Add Chaquopy to android/app/build.gradle #
android {
...
defaultConfig {
...
python {
version "3.8"
}
ndk {
abiFilters "armeabi-v7a", "arm64-v8a", "x86", "x86_64"
}
}
}
2. Create requirements.txt in android/app/ #
yt-dlp>=2023.11.16
๐ Usage #
Import the plugin #
import 'package:flutter_ytdlp_plugin/flutter_ytdlp_plugin.dart';
Initialize #
final ytdlp = FlutterYtdlpPlugin();
๐ API Methods #
1. Check Video Status #
final status = await ytdlp.checkStatus(videoId: 'dQw4w9WgXcQ');
print(status);
Response:
{
"available": true,
"status": "available",
"error": null
}
available:boolstatus:String('available','private','age_restricted', etc.)error:String?(nullable)
2. Get Video Streams #
final streams = await ytdlp.getVideoStreams(
videoId: 'dQw4w9WgXcQ',
quality: '1080p', // Default: 1080p
);
print(streams);
Returns: List<Map<String, dynamic>>
[
{
"url": "...",
"ext": "mp4",
"resolution": "1920x1080",
"height": 1080,
"width": 1920,
"bitrate": 2500.0,
"codec": "avc1.640028",
"filesize": 12345678,
"formatNote": "1080p",
"formatId": "137"
}
]
3. Get Audio Streams #
final streams = await ytdlp.getAudioStreams(
videoId: 'dQw4w9WgXcQ',
bitrate: 192, // Default: 192 kbps
codec: 'opus', // Optional
);
print(streams);
Returns: List<Map<String, dynamic>>
[
{
"url": "...",
"ext": "webm",
"bitrate": 192,
"codec": "opus",
"filesize": 4321000,
"formatId": "251"
}
]
4. Get Unified Streams (Video + Audio) #
final result = await ytdlp.getUnifiedStreams(
videoId: 'dQw4w9WgXcQ',
audioBitrate: 192,
videoQuality: '1080p',
audioCodec: 'opus', // Optional
videoCodec: 'avc1', // Optional
includeVideo: true, // Default: true
includeAudio: true, // Default: true
);
print(result);
Response:
{
"duration": 213,
"video": [ ... ],
"audio": [ ... ]
}
duration:int(seconds)video:List<Map<String, dynamic>>?(optional)audio:List<Map<String, dynamic>>?(optional)
โ Error Handling #
Exceptions are thrown as PlatformException with the following error codes:
| Error Code | Description |
|---|---|
INVALID_ARGUMENT |
Missing required parameters |
PYTHON_ERROR |
Python execution failed |
EXCEPTION |
Unexpected error occurred |
๐งช Example #
try {
final status = await ytdlp.checkStatus(videoId: videoUrl);
if (status['available'] == true) {
final streams = await ytdlp.getUnifiedStreams(
videoId: videoUrl,
videoQuality: '720p',
audioBitrate: 128,
);
// Use streams...
}
} on PlatformException catch (e) {
print('Error: ${e.message}');
}
โ ๏ธ Limitations #
- Android only: iOS is not supported due to Python runtime restrictions.
- Larger APK size: Adds ~25MB because of embedded Python.
- No downloading: Only extracts stream information; does not download media.
๐ค Contributing #
Pull requests are welcome!
For major changes, please open an issue first to discuss what you would like to change.