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; }