flutter_ytdlp_plugin 2.0.2 copy "flutter_ytdlp_plugin: ^2.0.2" to clipboard
flutter_ytdlp_plugin: ^2.0.2 copied to clipboard

PlatformAndroid

A Flutter plugin for YouTube video streaming using yt-dlp. Supports fetching video formats, related videos, and more.

Flutter YTDLP Plugin #

pub package License: MIT

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: bool
  • status: 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.


๐ŸŽ‰ Happy Streaming! #

4
likes
150
points
49
downloads

Publisher

unverified uploader

Weekly Downloads

A Flutter plugin for YouTube video streaming using yt-dlp. Supports fetching video formats, related videos, and more.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on flutter_ytdlp_plugin

Packages that implement flutter_ytdlp_plugin