diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/stream/StreamExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/stream/StreamExtractor.java index 0d2d8d1d76..8d9d8b5ffe 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/stream/StreamExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/stream/StreamExtractor.java @@ -38,6 +38,7 @@ import org.schabi.newpipe.extractor.utils.Parser; import java.io.IOException; +import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Locale; @@ -256,6 +257,35 @@ public String getSubChannelAvatarUrl() throws ParsingException { return ""; } + /** + * Defines how the current stream info should best be resolved. + * + *

+ * Service mostly offer different methods for streaming data. + * However the order is not always clearly defined. + * E.g. resolving a livestream might be better using the HLS master playlist. + *

+ * + * @return A list with the StreamResolutionMode order by priority (0 = highest priority) + */ + @Nonnull + public List getResolverStrategyPriority() { + if (isLive()) { + return Arrays.asList( + StreamResolvingStrategy.HLS_MASTER_PLAYLIST_URL, + StreamResolvingStrategy.DASH_MPD_URL, + StreamResolvingStrategy.VIDEO_ONLY_AND_AUDIO_STREAMS, + StreamResolvingStrategy.VIDEO_AUDIO_STREAMS + ); + } + return Arrays.asList( + StreamResolvingStrategy.VIDEO_ONLY_AND_AUDIO_STREAMS, + StreamResolvingStrategy.VIDEO_AUDIO_STREAMS, + StreamResolvingStrategy.HLS_MASTER_PLAYLIST_URL, + StreamResolvingStrategy.DASH_MPD_URL + ); + } + /** * Get the dash mpd url. * diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/stream/StreamInfo.java b/extractor/src/main/java/org/schabi/newpipe/extractor/stream/StreamInfo.java index 2c16ce71b8..a834d726d1 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/stream/StreamInfo.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/stream/StreamInfo.java @@ -72,6 +72,7 @@ public class StreamInfo extends Info { private String subChannelUrl = ""; private String subChannelAvatarUrl = ""; + private List streamResolvingStrategies = new ArrayList<>(); private List videoStreams = new ArrayList<>(); private List audioStreams = new ArrayList<>(); private List videoOnlyStreams = new ArrayList<>(); @@ -275,6 +276,15 @@ public void setSubChannelAvatarUrl(final String subChannelAvatarUrl) { this.subChannelAvatarUrl = subChannelAvatarUrl; } + @Nonnull + public List getStreamResolvingStrategies() { + return streamResolvingStrategies; + } + + public void setStreamResolvingStrategies(@Nonnull final List streamResolvingStrategies) { + this.streamResolvingStrategies = streamResolvingStrategies; + } + @Nonnull public List getVideoStreams() { return videoStreams; @@ -507,6 +517,8 @@ private static StreamInfo extractImportantData(@Nonnull final StreamExtractor ex private static void extractStreams(final StreamInfo streamInfo, final StreamExtractor extractor) throws ExtractionException { + streamInfo.setStreamResolvingStrategies(extractor.getResolverStrategyPriority()); + /* ---- Stream extraction goes here ---- */ // At least one type of stream has to be available, otherwise an exception will be thrown // directly into the frontend. diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/stream/StreamResolvingStrategy.java b/extractor/src/main/java/org/schabi/newpipe/extractor/stream/StreamResolvingStrategy.java new file mode 100644 index 0000000000..b024fcbad0 --- /dev/null +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/stream/StreamResolvingStrategy.java @@ -0,0 +1,31 @@ +package org.schabi.newpipe.extractor.stream; + +/** + * Defines what strategy of the extractor is used for playback. + */ +public enum StreamResolvingStrategy { + /** + * Uses video streams (with no audio) and separate audio streams. + * @see StreamExtractor#getVideoOnlyStreams() + * @see StreamExtractor#getAudioStreams() + */ + VIDEO_ONLY_AND_AUDIO_STREAMS, + /** + * Uses video streams that include audio data. + * + * @see StreamExtractor#getVideoStreams() + */ + VIDEO_AUDIO_STREAMS, + /** + * Uses the HLS master playlist url. + * + * @see StreamExtractor#getHlsMasterPlaylistUrl() + */ + HLS_MASTER_PLAYLIST_URL, + /** + * Uses the DASH MPD url. + * + * @see StreamExtractor#getDashMpdUrl() + */ + DASH_MPD_URL +}