From 8c9d045e1d5029c702d2264341d59d9012236d9b Mon Sep 17 00:00:00 2001 From: Kelvin Date: Tue, 10 Dec 2024 22:35:38 +0100 Subject: [PATCH] Download playlist fix for videos without audio file --- .../platformplayer/downloads/VideoDownload.kt | 30 +++++++++++++++++-- .../platformplayer/states/StateDownloads.kt | 4 +-- app/src/stable/assets/sources/odysee | 2 +- app/src/stable/assets/sources/rumble | 2 +- app/src/stable/assets/sources/youtube | 2 +- app/src/unstable/assets/sources/odysee | 2 +- app/src/unstable/assets/sources/rumble | 2 +- app/src/unstable/assets/sources/youtube | 2 +- 8 files changed, 36 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/com/futo/platformplayer/downloads/VideoDownload.kt b/app/src/main/java/com/futo/platformplayer/downloads/VideoDownload.kt index e4e9bedb..84c019c8 100644 --- a/app/src/main/java/com/futo/platformplayer/downloads/VideoDownload.kt +++ b/app/src/main/java/com/futo/platformplayer/downloads/VideoDownload.kt @@ -100,6 +100,7 @@ class VideoDownload { var requireVideoSource: Boolean = false; var requireAudioSource: Boolean = false; + var requiredCheck: Boolean = false; @Contextual @Transient @@ -164,7 +165,7 @@ class VideoDownload { onStateChanged.emit(newState); } - constructor(video: IPlatformVideo, targetPixelCount: Long? = null, targetBitrate: Long? = null) { + constructor(video: IPlatformVideo, targetPixelCount: Long? = null, targetBitrate: Long? = null, optionalSources: Boolean = false) { this.video = SerializedPlatformVideo.fromVideo(video); this.videoSource = null; this.audioSource = null; @@ -175,8 +176,9 @@ class VideoDownload { this.requiresLiveVideoSource = false; this.requiresLiveAudioSource = false; this.targetVideoName = videoSource?.name; - this.requireVideoSource = targetPixelCount != null + this.requireVideoSource = targetPixelCount != null; this.requireAudioSource = targetBitrate != null; //TODO: May not be a valid check.. can only be determined after live fetch? + this.requiredCheck = optionalSources; } constructor(video: IPlatformVideoDetails, videoSource: IVideoSource?, audioSource: IAudioSource?, subtitleSource: SubtitleRawSource?) { this.video = SerializedPlatformVideo.fromVideo(video); @@ -250,6 +252,30 @@ class VideoDownload { if(original !is IPlatformVideoDetails) throw IllegalStateException("Original content is not media?"); + if(requiredCheck) { + if(original.video is VideoUnMuxedSourceDescriptor) { + if(requireVideoSource) { + if((original.video as VideoUnMuxedSourceDescriptor).audioSources.any() && !original.video.videoSources.any()) { + requireVideoSource = false; + targetPixelCount = null; + } + } + if(requireAudioSource) { + if(!(original.video as VideoUnMuxedSourceDescriptor).audioSources.any() && original.video.videoSources.any()) { + requireAudioSource = false; + targetBitrate = null; + } + } + } + else { + if(requireAudioSource) { + requireAudioSource = false; + targetBitrate = null; + } + } + requiredCheck = false; + } + if(original.video.hasAnySource() && !original.isDownloadable()) { Logger.i(TAG, "Attempted to download unsupported video [${original.name}]:${original.url}"); throw DownloadException("Unsupported video for downloading", false); diff --git a/app/src/main/java/com/futo/platformplayer/states/StateDownloads.kt b/app/src/main/java/com/futo/platformplayer/states/StateDownloads.kt index e4caab81..4bfeae7b 100644 --- a/app/src/main/java/com/futo/platformplayer/states/StateDownloads.kt +++ b/app/src/main/java/com/futo/platformplayer/states/StateDownloads.kt @@ -251,7 +251,7 @@ class StateDownloads { } else { Logger.i(TAG, "New watchlater video ${item.name}"); - download(VideoDownload(item, playlistDownload.targetPxCount, playlistDownload.targetBitrate) + download(VideoDownload(item, playlistDownload.targetPxCount, playlistDownload.targetBitrate, true) .withGroup(VideoDownload.GROUP_WATCHLATER, VideoDownload.GROUP_WATCHLATER), false); hasNew = true; } @@ -296,7 +296,7 @@ class StateDownloads { } else { Logger.i(TAG, "New playlist video ${item.name}"); - download(VideoDownload(item, playlistDownload.targetPxCount, playlistDownload.targetBitrate) + download(VideoDownload(item, playlistDownload.targetPxCount, playlistDownload.targetBitrate, true) .withGroup(VideoDownload.GROUP_PLAYLIST, playlist.id), false); hasNew = true; } diff --git a/app/src/stable/assets/sources/odysee b/app/src/stable/assets/sources/odysee index 77b90125..8ddb2e2f 160000 --- a/app/src/stable/assets/sources/odysee +++ b/app/src/stable/assets/sources/odysee @@ -1 +1 @@ -Subproject commit 77b9012590ef98afce8659b154028aff85834eb2 +Subproject commit 8ddb2e2f15bf907bd8523aac4326b92b8e3b0e8e diff --git a/app/src/stable/assets/sources/rumble b/app/src/stable/assets/sources/rumble index cbfe372b..6811ff4b 160000 --- a/app/src/stable/assets/sources/rumble +++ b/app/src/stable/assets/sources/rumble @@ -1 +1 @@ -Subproject commit cbfe372bcc7bf9c339809c30291b85c53bfa2f7d +Subproject commit 6811ff4b412cfb94ff74c3b2b88f7d87b76e8902 diff --git a/app/src/stable/assets/sources/youtube b/app/src/stable/assets/sources/youtube index e1fa4980..59d694b6 160000 --- a/app/src/stable/assets/sources/youtube +++ b/app/src/stable/assets/sources/youtube @@ -1 +1 @@ -Subproject commit e1fa498059f481a81639fef3b62adc2ec05a95dd +Subproject commit 59d694b619e9a60d1c2d7315c87c51672383ffc5 diff --git a/app/src/unstable/assets/sources/odysee b/app/src/unstable/assets/sources/odysee index 77b90125..8ddb2e2f 160000 --- a/app/src/unstable/assets/sources/odysee +++ b/app/src/unstable/assets/sources/odysee @@ -1 +1 @@ -Subproject commit 77b9012590ef98afce8659b154028aff85834eb2 +Subproject commit 8ddb2e2f15bf907bd8523aac4326b92b8e3b0e8e diff --git a/app/src/unstable/assets/sources/rumble b/app/src/unstable/assets/sources/rumble index cbfe372b..6811ff4b 160000 --- a/app/src/unstable/assets/sources/rumble +++ b/app/src/unstable/assets/sources/rumble @@ -1 +1 @@ -Subproject commit cbfe372bcc7bf9c339809c30291b85c53bfa2f7d +Subproject commit 6811ff4b412cfb94ff74c3b2b88f7d87b76e8902 diff --git a/app/src/unstable/assets/sources/youtube b/app/src/unstable/assets/sources/youtube index e1fa4980..59d694b6 160000 --- a/app/src/unstable/assets/sources/youtube +++ b/app/src/unstable/assets/sources/youtube @@ -1 +1 @@ -Subproject commit e1fa498059f481a81639fef3b62adc2ec05a95dd +Subproject commit 59d694b619e9a60d1c2d7315c87c51672383ffc5