parent
fa57ec08d2
commit
c9e911ec13
|
@ -38,6 +38,7 @@ import org.schabi.newpipe.extractor.streamdata.stream.VideoStream;
|
||||||
import org.schabi.newpipe.extractor.utils.Parser;
|
import org.schabi.newpipe.extractor.utils.Parser;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
@ -256,6 +257,35 @@ public abstract class StreamExtractor extends Extractor {
|
||||||
return "";
|
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.
|
* Get the dash mpd url.
|
||||||
*
|
*
|
||||||
|
|
|
@ -72,6 +72,7 @@ public class StreamInfo extends Info {
|
||||||
private String subChannelUrl = "";
|
private String subChannelUrl = "";
|
||||||
private String subChannelAvatarUrl = "";
|
private String subChannelAvatarUrl = "";
|
||||||
|
|
||||||
|
private List<StreamResolvingStrategy> streamResolvingStrategies = new ArrayList<>();
|
||||||
private List<VideoAudioStream> videoStreams = new ArrayList<>();
|
private List<VideoAudioStream> videoStreams = new ArrayList<>();
|
||||||
private List<AudioStream> audioStreams = new ArrayList<>();
|
private List<AudioStream> audioStreams = new ArrayList<>();
|
||||||
private List<VideoStream> videoOnlyStreams = new ArrayList<>();
|
private List<VideoStream> videoOnlyStreams = new ArrayList<>();
|
||||||
|
@ -275,6 +276,15 @@ public class StreamInfo extends Info {
|
||||||
this.subChannelAvatarUrl = subChannelAvatarUrl;
|
this.subChannelAvatarUrl = subChannelAvatarUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
|
public List<StreamResolvingStrategy> getStreamResolvingStrategies() {
|
||||||
|
return streamResolvingStrategies;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStreamResolvingStrategies(@Nonnull final List<StreamResolvingStrategy> streamResolvingStrategies) {
|
||||||
|
this.streamResolvingStrategies = streamResolvingStrategies;
|
||||||
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public List<VideoAudioStream> getVideoStreams() {
|
public List<VideoAudioStream> getVideoStreams() {
|
||||||
return videoStreams;
|
return videoStreams;
|
||||||
|
@ -507,6 +517,8 @@ public class StreamInfo extends Info {
|
||||||
private static void extractStreams(final StreamInfo streamInfo,
|
private static void extractStreams(final StreamInfo streamInfo,
|
||||||
final StreamExtractor extractor)
|
final StreamExtractor extractor)
|
||||||
throws ExtractionException {
|
throws ExtractionException {
|
||||||
|
streamInfo.setStreamResolvingStrategies(extractor.getResolverStrategyPriority());
|
||||||
|
|
||||||
/* ---- Stream extraction goes here ---- */
|
/* ---- Stream extraction goes here ---- */
|
||||||
// At least one type of stream has to be available, otherwise an exception will be thrown
|
// At least one type of stream has to be available, otherwise an exception will be thrown
|
||||||
// directly into the frontend.
|
// directly into the frontend.
|
||||||
|
|
|
@ -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
|
||||||
|
}
|
Loading…
Reference in New Issue