Skip to content

Commit d0a4a8d

Browse files
committed
Implemented StreamResolvingStrategy
Not finished yet
1 parent 81dea3c commit d0a4a8d

File tree

3 files changed

+73
-0
lines changed

3 files changed

+73
-0
lines changed

extractor/src/main/java/org/schabi/newpipe/extractor/stream/StreamExtractor.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import org.schabi.newpipe.extractor.utils.Parser;
3939

4040
import java.io.IOException;
41+
import java.util.Arrays;
4142
import java.util.Collections;
4243
import java.util.List;
4344
import java.util.Locale;
@@ -256,6 +257,35 @@ public String getSubChannelAvatarUrl() throws ParsingException {
256257
return "";
257258
}
258259

260+
/**
261+
* Defines how the current stream info should best be resolved.
262+
*
263+
* <p>
264+
* Service mostly offer different methods for streaming data.
265+
* However the order is not always clearly defined.
266+
* E.g. resolving a livestream might be better using the HLS master playlist.
267+
* </p>
268+
*
269+
* @return A list with the StreamResolutionMode order by priority (0 = highest priority)
270+
*/
271+
@Nonnull
272+
public List<StreamResolvingStrategy> getResolverStrategyPriority() {
273+
if (isLive()) {
274+
return Arrays.asList(
275+
StreamResolvingStrategy.HLS_MASTER_PLAYLIST_URL,
276+
StreamResolvingStrategy.DASH_MPD_URL,
277+
StreamResolvingStrategy.VIDEO_ONLY_AND_AUDIO_STREAMS,
278+
StreamResolvingStrategy.VIDEO_AUDIO_STREAMS
279+
);
280+
}
281+
return Arrays.asList(
282+
StreamResolvingStrategy.VIDEO_ONLY_AND_AUDIO_STREAMS,
283+
StreamResolvingStrategy.VIDEO_AUDIO_STREAMS,
284+
StreamResolvingStrategy.HLS_MASTER_PLAYLIST_URL,
285+
StreamResolvingStrategy.DASH_MPD_URL
286+
);
287+
}
288+
259289
/**
260290
* Get the dash mpd url.
261291
*

extractor/src/main/java/org/schabi/newpipe/extractor/stream/StreamInfo.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ public class StreamInfo extends Info {
7272
private String subChannelUrl = "";
7373
private String subChannelAvatarUrl = "";
7474

75+
private List<StreamResolvingStrategy> streamResolvingStrategies = new ArrayList<>();
7576
private List<VideoAudioStream> videoStreams = new ArrayList<>();
7677
private List<AudioStream> audioStreams = new ArrayList<>();
7778
private List<VideoStream> videoOnlyStreams = new ArrayList<>();
@@ -275,6 +276,15 @@ public void setSubChannelAvatarUrl(final String subChannelAvatarUrl) {
275276
this.subChannelAvatarUrl = subChannelAvatarUrl;
276277
}
277278

279+
@Nonnull
280+
public List<StreamResolvingStrategy> getStreamResolvingStrategies() {
281+
return streamResolvingStrategies;
282+
}
283+
284+
public void setStreamResolvingStrategies(@Nonnull final List<StreamResolvingStrategy> streamResolvingStrategies) {
285+
this.streamResolvingStrategies = streamResolvingStrategies;
286+
}
287+
278288
@Nonnull
279289
public List<VideoAudioStream> getVideoStreams() {
280290
return videoStreams;
@@ -507,6 +517,8 @@ private static StreamInfo extractImportantData(@Nonnull final StreamExtractor ex
507517
private static void extractStreams(final StreamInfo streamInfo,
508518
final StreamExtractor extractor)
509519
throws ExtractionException {
520+
streamInfo.setStreamResolvingStrategies(extractor.getResolverStrategyPriority());
521+
510522
/* ---- Stream extraction goes here ---- */
511523
// At least one type of stream has to be available, otherwise an exception will be thrown
512524
// directly into the frontend.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package org.schabi.newpipe.extractor.stream;
2+
3+
/**
4+
* Defines what strategy of the extractor is used for playback.
5+
*/
6+
public enum StreamResolvingStrategy {
7+
/**
8+
* Uses video streams (with no audio) and separate audio streams.
9+
* @see StreamExtractor#getVideoOnlyStreams()
10+
* @see StreamExtractor#getAudioStreams()
11+
*/
12+
VIDEO_ONLY_AND_AUDIO_STREAMS,
13+
/**
14+
* Uses video streams that include audio data.
15+
*
16+
* @see StreamExtractor#getVideoStreams()
17+
*/
18+
VIDEO_AUDIO_STREAMS,
19+
/**
20+
* Uses the HLS master playlist url.
21+
*
22+
* @see StreamExtractor#getHlsMasterPlaylistUrl()
23+
*/
24+
HLS_MASTER_PLAYLIST_URL,
25+
/**
26+
* Uses the DASH MPD url.
27+
*
28+
* @see StreamExtractor#getDashMpdUrl()
29+
*/
30+
DASH_MPD_URL
31+
}

0 commit comments

Comments
 (0)