Skip to content

Commit

Permalink
Implemented StreamResolvingStrategy
Browse files Browse the repository at this point in the history
Not finished yet
  • Loading branch information
litetex committed Aug 26, 2022
1 parent 81dea3c commit d0a4a8d
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -256,6 +257,35 @@ public String getSubChannelAvatarUrl() throws ParsingException {
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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<>();
Expand Down Expand Up @@ -275,6 +276,15 @@ public void setSubChannelAvatarUrl(final String subChannelAvatarUrl) {
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;
Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit d0a4a8d

Please sign in to comment.