Skip to content

Commit

Permalink
Merge pull request #594 from lamarios/fix/video-download-issue
Browse files Browse the repository at this point in the history
fix issue that prevented some videos to download properly
  • Loading branch information
lamarios authored Sep 16, 2024
2 parents b426bdb + 0bbe6c3 commit a040b3b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
32 changes: 23 additions & 9 deletions lib/downloads/states/download_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class DownloadManagerCubit extends Cubit<DownloadManagerState> {
}
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();
Expand Down Expand Up @@ -206,14 +206,22 @@ class DownloadManagerCubit extends Cubit<DownloadManagerState> {
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');

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;
Expand Down Expand Up @@ -262,13 +270,19 @@ class DownloadManagerCubit extends Cubit<DownloadManagerState> {
setVideos();
}

FutureOr<void> onDownloadError(DioException err, DownloadedVideo vid) async {
if (err.type == DioExceptionType.cancel) {
log.fine("video cancelled, nothing to do");
return;
FutureOr<void> 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);
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down

0 comments on commit a040b3b

Please sign in to comment.