fix: yt-dlp playback not working and add partial support for HLS streaming

This commit is contained in:
Kingkor Roy Tirtho 2025-09-05 22:40:18 +06:00
parent 6940e92142
commit 469a76dbd6
4 changed files with 25 additions and 8 deletions

View File

@ -117,6 +117,24 @@ class ServerPlaybackRoutes {
return dio.head(url, options: options);
});
// Redirect to m3u8 link directly as it handles range requests internally
if (contentLengthRes?.headers.value("content-type") ==
"application/vnd.apple.mpegurl") {
return (
response: dio_lib.Response<Uint8List>(
statusCode: 301,
statusMessage: "M3U8 Redirect",
headers: Headers.fromMap({
"location": [url],
"content-type": ["application/vnd.apple.mpegurl"],
}),
requestOptions: RequestOptions(path: request.requestedUri.toString()),
isRedirect: true,
),
bytes: null,
);
}
final contentLength = contentLengthRes?.headers.value("content-length");
/// Forcing partial content range as mpv sometimes greedily wants

View File

@ -11,9 +11,7 @@ import 'package:http_parser/http_parser.dart';
class YtDlpEngine implements YouTubeEngine {
StreamManifest _parseFormats(List formats, videoId) {
final audioOnlyStreams = formats
.where(
(f) => f["resolution"] == "audio only" && f["manifest_url"] == null,
)
.where((f) => f["resolution"] == "audio only")
.sorted((a, b) => a["quality"] > b["quality"] ? 1 : -1)
.map((f) {
final filesize = f["filesize"] ?? f["filesize_approx"];
@ -22,13 +20,14 @@ class YtDlpEngine implements YouTubeEngine {
0,
Uri.parse(f["url"]),
StreamContainer.parse(
f["container"]?.replaceAll("_dash", "").replaceAll("m4a", "mp4"),
f["container"]?.replaceAll("_dash", "").replaceAll("m4a", "mp4") ??
(f["protocol"] == "m3u8_native" ? "m3u8" : "mp4"),
),
filesize != null ? FileSize(filesize) : FileSize.unknown,
Bitrate(
(((f["abr"] ?? f["tbr"] ?? 0) * 1000) as num).toInt(),
),
f["acodec"] ?? "webm",
f["acodec"] ?? "aac",
f["format_note"],
[],
MediaType.parse(

View File

@ -2881,8 +2881,8 @@ packages:
dependency: "direct main"
description:
path: "."
ref: e2d82305fab18566408d6f8758361017d1640c3d
resolved-ref: e2d82305fab18566408d6f8758361017d1640c3d
ref: "4e5310e14af74bdbb51e2a4766e66d6c6a2562a8"
resolved-ref: "4e5310e14af74bdbb51e2a4766e66d6c6a2562a8"
url: "https://github.com/KRTirtho/yt_dlp_dart.git"
source: git
version: "1.0.0"

View File

@ -132,7 +132,7 @@ dependencies:
yt_dlp_dart:
git:
url: https://github.com/KRTirtho/yt_dlp_dart.git
ref: e2d82305fab18566408d6f8758361017d1640c3d
ref: 4e5310e14af74bdbb51e2a4766e66d6c6a2562a8
flutter_new_pipe_extractor:
git:
url: https://github.com/KRTirtho/flutter_new_pipe_extractor.git