From d8a5d5545ddae5f19566a30e949db551b24da732 Mon Sep 17 00:00:00 2001 From: Stypox Date: Thu, 28 Mar 2024 10:56:50 +0100 Subject: [PATCH] Fix choosing audio format to mux with video-only download --- .../newpipe/util/SecondaryStreamHelper.java | 54 +++++++------------ 1 file changed, 19 insertions(+), 35 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/util/SecondaryStreamHelper.java b/app/src/main/java/org/schabi/newpipe/util/SecondaryStreamHelper.java index 75d9a3892..69dc697fe 100644 --- a/app/src/main/java/org/schabi/newpipe/util/SecondaryStreamHelper.java +++ b/app/src/main/java/org/schabi/newpipe/util/SecondaryStreamHelper.java @@ -11,7 +11,6 @@ import org.schabi.newpipe.extractor.stream.Stream; import org.schabi.newpipe.extractor.stream.VideoStream; import org.schabi.newpipe.util.StreamItemAdapter.StreamInfoWrapper; -import java.util.Comparator; import java.util.List; public class SecondaryStreamHelper { @@ -43,42 +42,27 @@ public class SecondaryStreamHelper { @NonNull final List audioStreams, @NonNull final VideoStream videoStream) { final MediaFormat mediaFormat = videoStream.getFormat(); - if (mediaFormat == null) { + + if (mediaFormat == MediaFormat.WEBM) { + return audioStreams + .stream() + .filter(audioStream -> audioStream.getFormat() == MediaFormat.WEBMA + || audioStream.getFormat() == MediaFormat.WEBMA_OPUS) + .max(ListHelper.getAudioFormatComparator(MediaFormat.WEBMA, + ListHelper.isLimitingDataUsage(context))) + .orElse(null); + + } else if (mediaFormat == MediaFormat.MPEG_4) { + return audioStreams + .stream() + .filter(audioStream -> audioStream.getFormat() == MediaFormat.M4A) + .max(ListHelper.getAudioFormatComparator(MediaFormat.M4A, + ListHelper.isLimitingDataUsage(context))) + .orElse(null); + + } else { return null; } - - switch (mediaFormat) { - case WEBM: - case MPEG_4: // Is MPEG-4 DASH? - break; - default: - return null; - } - - final boolean m4v = mediaFormat == MediaFormat.MPEG_4; - final boolean isLimitingDataUsage = ListHelper.isLimitingDataUsage(context); - - Comparator comparator = ListHelper.getAudioFormatComparator( - m4v ? MediaFormat.M4A : MediaFormat.WEBMA, isLimitingDataUsage); - int preferredAudioStreamIndex = ListHelper.getAudioIndexByHighestRank( - audioStreams, comparator); - - if (preferredAudioStreamIndex == -1) { - if (m4v) { - return null; - } - - comparator = ListHelper.getAudioFormatComparator( - MediaFormat.WEBMA_OPUS, isLimitingDataUsage); - preferredAudioStreamIndex = ListHelper.getAudioIndexByHighestRank( - audioStreams, comparator); - - if (preferredAudioStreamIndex == -1) { - return null; - } - } - - return audioStreams.get(preferredAudioStreamIndex); } public T getStream() {