From fad4252ceb703e1162d28e526ced40f3d8782e3f Mon Sep 17 00:00:00 2001 From: office-pc nix root Date: Mon, 16 Sep 2024 19:25:49 +0800 Subject: [PATCH 1/2] fix issue that prevented some videos to download properly --- lib/downloads/states/download_manager.dart | 31 +++++++++++++++------- pubspec.yaml | 2 +- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/lib/downloads/states/download_manager.dart b/lib/downloads/states/download_manager.dart index 4a9a21c7..4ea5eef4 100644 --- a/lib/downloads/states/download_manager.dart +++ b/lib/downloads/states/download_manager.dart @@ -138,7 +138,7 @@ class DownloadManagerCubit extends Cubit { } AdaptiveFormat audio = vid.adaptiveFormats .sortByReversed((e) => int.parse(e.bitrate ?? "0")) - .firstWhere((element) => element.type.contains("audio")); + .firstWhere((element) => element.type.contains("audio/webm")); String audioUrl = audio.url; Dio dio = Dio(); @@ -211,9 +211,16 @@ class DownloadManagerCubit extends Cubit { final returnCode = await session.getReturnCode(); - onProgress(1, 1, downloadedVideo, step: 3, totalSteps: 3); + var success = returnCode?.isValueSuccess() ?? false; + if (success) { + onProgress(1, 1, downloadedVideo, step: 3, totalSteps: 3); + } else { + final logs = await session.getLogs(); - return returnCode?.isValueSuccess() ?? false; + onDownloadError("Couldn't merge audio and video ${logs.join("\n")}", + downloadedVideo); + } + return success; } } catch (e) { rethrow; @@ -262,13 +269,19 @@ class DownloadManagerCubit extends Cubit { setVideos(); } - FutureOr onDownloadError(DioException err, DownloadedVideo vid) async { - if (err.type == DioExceptionType.cancel) { - log.fine("video cancelled, nothing to do"); - return; + FutureOr onDownloadError(dynamic err, DownloadedVideo vid) async { + if (err is DioException) { + if (err.type == DioExceptionType.cancel) { + log.fine("video cancelled, nothing to do"); + return; + } + } + if (err is Error) { + log.severe( + "Failed to download video ${vid.title}, removing it", err.stackTrace); + } else { + log.severe("Failed to download video ${vid.title}, removing it", err); } - log.severe( - "Failed to download video ${vid.title}, removing it", err.stackTrace); vid.downloadFailed = true; vid.downloadComplete = false; onProgress(1, 1, vid, step: 1, totalSteps: 1); diff --git a/pubspec.yaml b/pubspec.yaml index 7d96a3fa..3a593eea 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: invidious -version: 1.21.1+4060 +version: 1.21.2+4061 publish_to: none description: A new Flutter project. environment: From 0bbe6c35447319a2a88aaf5cc19ecf1a33992fff Mon Sep 17 00:00:00 2001 From: office-pc nix root Date: Mon, 16 Sep 2024 19:36:44 +0800 Subject: [PATCH 2/2] fix progress when running ffmpeg --- lib/downloads/states/download_manager.dart | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/downloads/states/download_manager.dart b/lib/downloads/states/download_manager.dart index 4ea5eef4..60260dff 100644 --- a/lib/downloads/states/download_manager.dart +++ b/lib/downloads/states/download_manager.dart @@ -206,6 +206,7 @@ class DownloadManagerCubit extends Cubit { onProgress(1, 1, downloadedVideo, step: 2, totalSteps: 2); return true; } else { + onProgress(0, 1, downloadedVideo, step: 3, totalSteps: 3); final session = await FFmpegKit.execute( '-y -i $videoPath -i $audioPath -c:v copy -c:a copy $mediaPath');