Skip to content

Commit 7191ece

Browse files
committed
Don't remove public access of averageBitrate field in AudioStream and resolution and isVideoOnly fields in VideoStream but deprecate their use
Getters should be used instead of the fields, like for the others. Return a new constant (one for the AudioStream class, one for the VideoStream class, but they have the same value (because this method is not implemented in the Stream class)) for streams which don't have an itag instead of 0: ITAG_NOT_AVAILABLE_OR_NOT_APPLICABLE, which is equal to -1 (because an itag id should be not negative). Also fix some small issues in the Stream class.
1 parent 1e102b6 commit 7191ece

3 files changed

Lines changed: 65 additions & 17 deletions

File tree

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

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,22 @@ public class AudioStream extends Stream {
3232

3333
public static final int UNKNOWN_BITRATE = -1;
3434

35-
private final int averageBitrate;
35+
/**
36+
* An integer to represent that the itag id returned is not available (only for YouTube, this
37+
* should never happen) or not applicable (for other services than YouTube).
38+
*
39+
* <p>
40+
* An itag should not have a negative value so {@code -1} is used for this constant.
41+
* </p>
42+
*/
43+
public static final int ITAG_NOT_AVAILABLE_OR_NOT_APPLICABLE = -1;
44+
45+
/** @deprecated Use {@link #getAverageBitrate()} instead. */
46+
@Deprecated
47+
public final int averageBitrate;
48+
3649
// Fields for DASH
37-
private int itag;
50+
private int itag = ITAG_NOT_AVAILABLE_OR_NOT_APPLICABLE;
3851
private int bitrate;
3952
private int initStart;
4053
private int initEnd;
@@ -168,9 +181,14 @@ public int getAverageBitrate() {
168181
}
169182

170183
/**
171-
* Get the itag of the stream.
184+
* Get the itag identifier of the stream.
185+
*
186+
* <p>
187+
* Always equals to {@link #ITAG_NOT_AVAILABLE_OR_NOT_APPLICABLE} for other streams than the
188+
* ones of the YouTube service.
189+
* </p>
172190
*
173-
* @return the number of the {@link ItagItem} passed in the constructor of the stream.
191+
* @return the number of the {@link ItagItem} passed in the constructor of the audio stream.
174192
*/
175193
public int getItag() {
176194
return itag;

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

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@
1717
public abstract class Stream implements Serializable {
1818
private static final long serialVersionUID = -59591092068744672L;
1919

20+
public static final int FORMAT_ID_UNKNOWN = -1;
21+
2022
private final String id;
2123
@Nullable private final MediaFormat mediaFormat;
2224
private final String content;
2325
private final boolean isUrl;
2426
private final DeliveryMethod deliveryMethod;
2527
@Nullable private final String baseUrl;
2628

27-
public static final int FORMAT_ID_UNKNOWN = -1;
28-
2929
/**
30-
* Instantiates a new stream object.
30+
* Instantiates a new {@code Stream} object.
3131
*
3232
* @param id the ID which uniquely identifies the file, e.g. for YouTube this would
3333
* be the itag
@@ -54,7 +54,7 @@ protected Stream(final String id,
5454
}
5555

5656
/**
57-
* Check if the list already contains one stream with equals stats.
57+
* Checks if the list already contains one stream with equals stats.
5858
*
5959
* @param stream the stream which will be compared to the streams in the stream list
6060
* @param streamList the list of {@link Stream Streams} which will be compared
@@ -81,22 +81,26 @@ public static boolean containSimilarStream(final Stream stream,
8181
* If the {@link MediaFormat media format} of the stream is unknown, the streams are compared
8282
* by only using the {@link DeliveryMethod delivery method} and their id.
8383
* </p>
84+
*
8485
* <p>
8586
* Note: This method always returns always false if the stream passed is null.
8687
* </p>
88+
*
8789
* @param cmp the stream object to be compared to this stream object
8890
* @return whether the stream have the same stats or not, based on the criteria above
8991
*/
9092
public boolean equalStats(final Stream cmp) {
9193
if (cmp == null) {
9294
return false;
9395
}
96+
9497
Boolean haveSameMediaFormatId = null;
9598
if (mediaFormat != null && cmp.mediaFormat != null) {
9699
haveSameMediaFormatId = mediaFormat.id == cmp.mediaFormat.id;
97100
}
98101
final boolean areUsingSameDeliveryMethodAndAreUrlStreams =
99102
deliveryMethod == cmp.deliveryMethod && isUrl == cmp.isUrl;
103+
100104
return haveSameMediaFormatId != null
101105
? haveSameMediaFormatId && areUsingSameDeliveryMethodAndAreUrlStreams
102106
: areUsingSameDeliveryMethodAndAreUrlStreams;
@@ -113,7 +117,7 @@ public boolean equals(final Stream cmp) {
113117
}
114118

115119
/**
116-
* Gets the ID for this stream, e.g. itag for YouTube.
120+
* Gets the identifier of this stream, e.g. the itag for YouTube.
117121
*
118122
* @return the id
119123
*/
@@ -122,10 +126,10 @@ public String getId() {
122126
}
123127

124128
/**
125-
* Gets the URL.
129+
* Gets the URL of this stream if the content is a URL, or {@code null} if that's the not case.
126130
*
127131
* @return the URL if the content is a URL, {@code null} otherwise
128-
* @deprecated Use {@link #getContent()} instead
132+
* @deprecated Use {@link #getContent()} instead.
129133
*/
130134
@Deprecated
131135
@Nullable
@@ -186,6 +190,7 @@ public DeliveryMethod getDeliveryMethod() {
186190

187191
/**
188192
* Gets the base URL of a stream.
193+
*
189194
* <p>
190195
* If the stream is not a DASH stream or an HLS stream, this value will always be null.
191196
* It may be also null for these streams too.
@@ -200,6 +205,7 @@ public String getBaseUrl() {
200205

201206
/**
202207
* Gets the {@link ItagItem} of a stream.
208+
*
203209
* <p>
204210
* If the stream is not a YouTube stream, this value will always be null.
205211
* </p>

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

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,26 @@ public class VideoStream extends Stream {
3232

3333
public static final String RESOLUTION_UNKNOWN = "";
3434

35-
private final String resolution;
36-
private final boolean isVideoOnly;
35+
/**
36+
* An integer to represent that the itag id returned is not available (only for YouTube, this
37+
* should never happen) or not applicable (for other services than YouTube).
38+
*
39+
* <p>
40+
* An itag should not have a negative value so {@code -1} is used for this constant.
41+
* </p>
42+
*/
43+
public static final int ITAG_NOT_AVAILABLE_OR_NOT_APPLICABLE = -1;
44+
45+
/** @deprecated Use {@link #getResolution()} instead. */
46+
@Deprecated
47+
public final String resolution;
48+
49+
/** @deprecated Use {@link #isVideoOnly()} instead. */
50+
@Deprecated
51+
public final boolean isVideoOnly;
52+
3753
// Fields for DASH
38-
private int itag;
54+
private int itag = ITAG_NOT_AVAILABLE_OR_NOT_APPLICABLE;
3955
private int bitrate;
4056
private int initStart;
4157
private int initEnd;
@@ -141,6 +157,7 @@ public VideoStream(final String id,
141157

142158
/**
143159
* Create a new video stream.
160+
*
144161
* <p>
145162
* The media format and the resolution will be set by using respectively
146163
* {@link ItagItem#getMediaFormat()} and {@link ItagItem#resolutionString}.
@@ -183,6 +200,7 @@ public boolean equalStats(final Stream cmp) {
183200

184201
/**
185202
* Get the video resolution.
203+
*
186204
* <p>
187205
* It can be unknown for some streams, like for HLS master playlists. In this case,
188206
* {@link #RESOLUTION_UNKNOWN} is returned by this method.
@@ -195,7 +213,8 @@ public String getResolution() {
195213
}
196214

197215
/**
198-
* Return if the stream is video-only.
216+
* Return whether the stream is video-only.
217+
*
199218
* <p>
200219
* Video-only streams have no audio.
201220
* </p>
@@ -207,9 +226,14 @@ public boolean isVideoOnly() {
207226
}
208227

209228
/**
210-
* Get the itag of the stream.
229+
* Get the itag identifier of the stream.
230+
*
231+
* <p>
232+
* Always equals to {@link #ITAG_NOT_AVAILABLE_OR_NOT_APPLICABLE} for other streams than the
233+
* ones of the YouTube service.
234+
* </p>
211235
*
212-
* @return the number of the {@link ItagItem} passed in the constructor of the stream.
236+
* @return the number of the {@link ItagItem} passed in the constructor of the video stream.
213237
*/
214238
public int getItag() {
215239
return itag;

0 commit comments

Comments
 (0)