Implemented ``StreamResolvingStrategy``

Not finished yet
This commit is contained in:
litetex 2022-08-26 16:58:05 +02:00
parent fa57ec08d2
commit c9e911ec13
3 changed files with 73 additions and 0 deletions

View File

@ -38,6 +38,7 @@ import org.schabi.newpipe.extractor.streamdata.stream.VideoStream;
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 abstract class StreamExtractor extends Extractor {
return "";
}
/**
* Defines how the current stream info should best be resolved.
*
* <p>
* 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.
* </p>
*
* @return A list with the StreamResolutionMode order by priority (0 = highest priority)
*/
@Nonnull
public List<StreamResolvingStrategy> 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.
*

View File

@ -72,6 +72,7 @@ public class StreamInfo extends Info {
private String subChannelUrl = "";
private String subChannelAvatarUrl = "";
private List<StreamResolvingStrategy> streamResolvingStrategies = new ArrayList<>();
private List<VideoAudioStream> videoStreams = new ArrayList<>();
private List<AudioStream> audioStreams = new ArrayList<>();
private List<VideoStream> videoOnlyStreams = new ArrayList<>();
@ -275,6 +276,15 @@ public class StreamInfo extends Info {
this.subChannelAvatarUrl = subChannelAvatarUrl;
}
@Nonnull
public List<StreamResolvingStrategy> getStreamResolvingStrategies() {
return streamResolvingStrategies;
}
public void setStreamResolvingStrategies(@Nonnull final List<StreamResolvingStrategy> streamResolvingStrategies) {
this.streamResolvingStrategies = streamResolvingStrategies;
}
@Nonnull
public List<VideoAudioStream> getVideoStreams() {
return videoStreams;
@ -507,6 +517,8 @@ public class StreamInfo extends Info {
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.

View File

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