Skip to content

Commit 5fa7521

Browse files
committed
Add a baseUrl field to Stream classes
1 parent a724529 commit 5fa7521

7 files changed

Lines changed: 42 additions & 17 deletions

File tree

extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubeStreamExtractor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,9 +247,9 @@ private List<VideoStream> getVideoStreamsFromArray(final JsonArray streams) thro
247247
final MediaFormat format = MediaFormat.getFromSuffix(extension);
248248
final String id = resolution + "." + extension;
249249
videoStreams.add(new VideoStream(id, url, true, format,
250-
DeliveryMethod.PROGRESSIVE_HTTP, resolution, false));
250+
DeliveryMethod.PROGRESSIVE_HTTP, resolution, false, null));
251251
videoStreams.add(new VideoStream(id, torrentUrl, true, format,
252-
DeliveryMethod.TORRENT, resolution, false));
252+
DeliveryMethod.TORRENT, resolution, false, null));
253253
}
254254
return videoStreams;
255255
} catch (final Exception e) {

extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ public List<AudioStream> getAudioStreams() throws ExtractionException {
522522
final ItagItem itag = entry.getValue();
523523
final AudioStream audioStream = new AudioStream(String.valueOf(itag.id),
524524
entry.getKey(), true, itag.getMediaFormat(),
525-
DeliveryMethod.PROGRESSIVE_HTTP, itag.avgBitrate, itag);
525+
DeliveryMethod.PROGRESSIVE_HTTP, itag.avgBitrate, itag, null);
526526
audioStreams.add(audioStream);
527527
}
528528

@@ -547,7 +547,7 @@ public List<VideoStream> getVideoStreams() throws ExtractionException {
547547
final ItagItem itag = entry.getValue();
548548
final VideoStream videoStream = new VideoStream(String.valueOf(itag.id),
549549
entry.getKey(), true, itag.getMediaFormat(),
550-
DeliveryMethod.PROGRESSIVE_HTTP, itag.resolutionString, false, itag);
550+
DeliveryMethod.PROGRESSIVE_HTTP, itag.resolutionString, false, itag, null);
551551
videoStreams.add(videoStream);
552552
}
553553

@@ -572,7 +572,7 @@ public List<VideoStream> getVideoOnlyStreams() throws ExtractionException {
572572

573573
final VideoStream videoStream = new VideoStream(String.valueOf(itag.id),
574574
entry.getKey(), true, itag.getMediaFormat(),
575-
DeliveryMethod.PROGRESSIVE_HTTP, itag.resolutionString, true, itag);
575+
DeliveryMethod.PROGRESSIVE_HTTP, itag.resolutionString, true, itag, null);
576576
videoOnlyStreams.add(videoStream);
577577
}
578578

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.schabi.newpipe.extractor.services.youtube.ItagItem;
2525

2626
import javax.annotation.Nonnull;
27+
import javax.annotation.Nullable;
2728

2829
public class AudioStream extends Stream {
2930
public final int averageBitrate;
@@ -66,7 +67,7 @@ public AudioStream(final String id,
6667
final MediaFormat format,
6768
final DeliveryMethod deliveryMethod,
6869
final int averageBitrate) {
69-
super(id, content, isUrl, format, deliveryMethod);
70+
super(id, content, isUrl, format, deliveryMethod, null);
7071
this.averageBitrate = averageBitrate;
7172
}
7273

@@ -76,8 +77,9 @@ public AudioStream(final String id,
7677
final MediaFormat format,
7778
final DeliveryMethod deliveryMethod,
7879
final int averageBitrate,
79-
@Nonnull final ItagItem itag) {
80-
super(id, content, isUrl, format, deliveryMethod);
80+
@Nonnull final ItagItem itag,
81+
@Nullable final String baseUrl) {
82+
super(id, content, isUrl, format, deliveryMethod, baseUrl);
8183
this.itag = itag.id;
8284
this.quality = itag.getQuality();
8385
this.bitrate = itag.getBitrate();

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import org.schabi.newpipe.extractor.MediaFormat;
44

5+
import javax.annotation.Nullable;
56
import java.io.Serializable;
67
import java.util.List;
78

@@ -16,6 +17,7 @@ public abstract class Stream implements Serializable {
1617
private final String content;
1718
private final boolean isUrl;
1819
private final DeliveryMethod deliveryMethod;
20+
private final String baseUrl;
1921

2022
/**
2123
* Instantiates a new stream object.
@@ -27,17 +29,20 @@ public abstract class Stream implements Serializable {
2729
* manifest
2830
* @param format the format
2931
* @param deliveryMethod the delivery method
32+
* @param baseUrl the base URL of the content if the stream is a DASH or an HLS manifest
3033
*/
3134
public Stream(final String id,
3235
final String content,
3336
final boolean isUrl,
3437
final MediaFormat format,
35-
final DeliveryMethod deliveryMethod) {
38+
final DeliveryMethod deliveryMethod,
39+
@Nullable final String baseUrl) {
3640
this.id = id;
3741
this.content = content;
3842
this.isUrl = isUrl;
3943
this.mediaFormat = format;
4044
this.deliveryMethod = deliveryMethod;
45+
this.baseUrl = baseUrl;
4146
}
4247

4348
/**
@@ -122,4 +127,17 @@ public int getFormatId() {
122127
public DeliveryMethod getDeliveryMethod() {
123128
return deliveryMethod;
124129
}
130+
131+
/**
132+
* Gets the base URL of a stream.
133+
* <p>
134+
* If the stream is not a DASH stream or an HLS stream, this value will be null.
135+
* </p>
136+
*
137+
* @return the base URL of the stream or null
138+
*/
139+
@Nullable
140+
public String getBaseUrl() {
141+
return baseUrl;
142+
}
125143
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public SubtitlesStream(final String id,
2525
final MediaFormat format,
2626
@Nonnull final String languageCode,
2727
final boolean autoGenerated) {
28-
super(id, url, true, format, DeliveryMethod.PROGRESSIVE_HTTP);
28+
super(id, url, true, format, DeliveryMethod.PROGRESSIVE_HTTP, null);
2929

3030
/*
3131
* Locale.forLanguageTag only for API >= 21

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.schabi.newpipe.extractor.services.youtube.ItagItem;
2525

2626
import javax.annotation.Nonnull;
27+
import javax.annotation.Nullable;
2728

2829
public class VideoStream extends Stream {
2930
private final String resolution;
@@ -47,7 +48,8 @@ public VideoStream(final String id,
4748
final MediaFormat format,
4849
final String resolution,
4950
final boolean isVideoOnly) {
50-
this(id, url, true, format, DeliveryMethod.PROGRESSIVE_HTTP, resolution, isVideoOnly);
51+
this(id, url, true, format, DeliveryMethod.PROGRESSIVE_HTTP, resolution, isVideoOnly,
52+
null);
5153
}
5254

5355
public VideoStream(final String id,
@@ -56,8 +58,9 @@ public VideoStream(final String id,
5658
final MediaFormat format,
5759
final DeliveryMethod deliveryMethod,
5860
final String resolution,
59-
final boolean isVideoOnly) {
60-
super(id, content, isUrl, format, deliveryMethod);
61+
final boolean isVideoOnly,
62+
@Nullable final String baseUrl) {
63+
super(id, content, isUrl, format, deliveryMethod, baseUrl);
6164
this.resolution = resolution;
6265
this.isVideoOnly = isVideoOnly;
6366
}
@@ -69,8 +72,9 @@ public VideoStream(final String id,
6972
final DeliveryMethod deliveryMethod,
7073
final String resolution,
7174
final boolean isVideoOnly,
72-
@Nonnull final ItagItem itag) {
73-
super(id, content, isUrl, format, deliveryMethod);
75+
@Nonnull final ItagItem itag,
76+
@Nullable final String baseUrl) {
77+
super(id, content, isUrl, format, deliveryMethod, baseUrl);
7478
this.itag = itag.id;
7579
this.bitrate = itag.getBitrate();
7680
this.initStart = itag.getInitStart();

extractor/src/main/java/org/schabi/newpipe/extractor/utils/DashMpdParser.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,14 +145,15 @@ public static Result getStreams(final String dashMpdUrl)
145145
if (itag.itagType.equals(ItagItem.ItagType.AUDIO)) {
146146
final AudioStream audioStream = new AudioStream(String.valueOf(itag.id),
147147
manualDashFromRepresentation(doc, representation), false,
148-
mediaFormat, DeliveryMethod.DASH, itag.avgBitrate, itag);
148+
mediaFormat, DeliveryMethod.DASH, itag.avgBitrate, itag,
149+
dashMpdUrl);
149150
audioStreams.add((audioStream));
150151
} else {
151152
final boolean isVideoOnly = itag.itagType == ItagItem.ItagType.VIDEO_ONLY;
152153
final VideoStream videoStream = new VideoStream(String.valueOf(itag.id),
153154
manualDashFromRepresentation(doc, representation), false,
154155
mediaFormat, DeliveryMethod.DASH, itag.resolutionString,
155-
isVideoOnly, itag);
156+
isVideoOnly, itag, dashMpdUrl);
156157

157158
if (isVideoOnly) {
158159
videoOnlyStreams.add(videoStream);

0 commit comments

Comments
 (0)