Skip to content

Commit 8448f0a

Browse files
committed
AudioStream: remove unused youtube-specific fields
These fields were added in #810 in preparation for a DASH support that never materialized … well it did materialize, but did not use any of these variables. Since they are youtube-specific, it does not make much sense to export them in the generic API, lest people start depending on them as if they belonged to all backends. Well, 4 variables are actually already depended on in places, they will have to be checked separately. But this is the low-hanging fruit.
1 parent 3402cdb commit 8448f0a

File tree

2 files changed

+26
-116
lines changed

2 files changed

+26
-116
lines changed

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

Lines changed: 4 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,6 @@ public final class AudioStream extends Stream {
3333

3434
private final int averageBitrate;
3535

36-
// Fields for DASH
37-
private int itag = ITAG_NOT_AVAILABLE_OR_NOT_APPLICABLE;
38-
private int bitrate;
39-
private int initStart;
40-
private int initEnd;
41-
private int indexStart;
42-
private int indexEnd;
43-
private String quality;
44-
private String codec;
45-
4636
// Fields about the audio track id/name
4737
@Nullable
4838
private final String audioTrackId;
@@ -53,6 +43,7 @@ public final class AudioStream extends Stream {
5343
@Nullable
5444
private final AudioTrackType audioTrackType;
5545

46+
// * Youtube-backend-specific data
5647
@Nullable
5748
private ItagItem itagItem;
5849

@@ -307,8 +298,7 @@ public AudioStream build() {
307298
}
308299

309300
return new AudioStream(id, content, isUrl, mediaFormat, deliveryMethod, averageBitrate,
310-
manifestUrl, audioTrackId, audioTrackName, audioLocale, audioTrackType,
311-
itagItem);
301+
manifestUrl, audioTrackId, audioTrackName, audioLocale, audioTrackType);
312302
}
313303
}
314304

@@ -329,7 +319,6 @@ public AudioStream build() {
329319
* @param audioTrackId the id of the audio track
330320
* @param audioTrackName the name of the audio track
331321
* @param audioLocale the {@link Locale} of the audio stream, representing its language
332-
* @param itagItem the {@link ItagItem} corresponding to the stream, which cannot be null
333322
* @param manifestUrl the URL of the manifest this stream comes from (if applicable,
334323
* otherwise null)
335324
*/
@@ -344,20 +333,9 @@ private AudioStream(@Nonnull final String id,
344333
@Nullable final String audioTrackId,
345334
@Nullable final String audioTrackName,
346335
@Nullable final Locale audioLocale,
347-
@Nullable final AudioTrackType audioTrackType,
348-
@Nullable final ItagItem itagItem) {
336+
@Nullable final AudioTrackType audioTrackType
337+
) {
349338
super(id, content, isUrl, format, deliveryMethod, manifestUrl);
350-
if (itagItem != null) {
351-
this.itagItem = itagItem;
352-
this.itag = itagItem.id;
353-
this.quality = itagItem.getQuality();
354-
this.bitrate = itagItem.getBitrate();
355-
this.initStart = itagItem.getInitStart();
356-
this.initEnd = itagItem.getInitEnd();
357-
this.indexStart = itagItem.getIndexStart();
358-
this.indexEnd = itagItem.getIndexEnd();
359-
this.codec = itagItem.getCodec();
360-
}
361339
this.averageBitrate = averageBitrate;
362340
this.audioTrackId = audioTrackId;
363341
this.audioTrackName = audioTrackName;
@@ -386,88 +364,6 @@ public int getAverageBitrate() {
386364
return averageBitrate;
387365
}
388366

389-
/**
390-
* Get the itag identifier of the stream.
391-
*
392-
* <p>
393-
* Always equals to {@link #ITAG_NOT_AVAILABLE_OR_NOT_APPLICABLE} for other streams than the
394-
* ones of the YouTube service.
395-
* </p>
396-
*
397-
* @return the number of the {@link ItagItem} passed in the constructor of the audio stream.
398-
*/
399-
public int getItag() {
400-
return itag;
401-
}
402-
403-
/**
404-
* Get the bitrate of the stream.
405-
*
406-
* @return the bitrate set from the {@link ItagItem} passed in the constructor of the stream.
407-
*/
408-
public int getBitrate() {
409-
return bitrate;
410-
}
411-
412-
/**
413-
* Get the initialization start of the stream.
414-
*
415-
* @return the initialization start value set from the {@link ItagItem} passed in the
416-
* constructor of the stream.
417-
*/
418-
public int getInitStart() {
419-
return initStart;
420-
}
421-
422-
/**
423-
* Get the initialization end of the stream.
424-
*
425-
* @return the initialization end value set from the {@link ItagItem} passed in the constructor
426-
* of the stream.
427-
*/
428-
public int getInitEnd() {
429-
return initEnd;
430-
}
431-
432-
/**
433-
* Get the index start of the stream.
434-
*
435-
* @return the index start value set from the {@link ItagItem} passed in the constructor of the
436-
* stream.
437-
*/
438-
public int getIndexStart() {
439-
return indexStart;
440-
}
441-
442-
/**
443-
* Get the index end of the stream.
444-
*
445-
* @return the index end value set from the {@link ItagItem} passed in the constructor of the
446-
* stream.
447-
*/
448-
public int getIndexEnd() {
449-
return indexEnd;
450-
}
451-
452-
/**
453-
* Get the quality of the stream.
454-
*
455-
* @return the quality label set from the {@link ItagItem} passed in the constructor of the
456-
* stream.
457-
*/
458-
public String getQuality() {
459-
return quality;
460-
}
461-
462-
/**
463-
* Get the codec of the stream.
464-
*
465-
* @return the codec set from the {@link ItagItem} passed in the constructor of the stream.
466-
*/
467-
public String getCodec() {
468-
return codec;
469-
}
470-
471367
/**
472368
* Get the id of the audio track.
473369
*

extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeDashManifestCreatorsTest.java

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.io.StringReader;
2323
import java.util.List;
2424
import java.util.Locale;
25+
import java.util.Objects;
2526
import java.util.Random;
2627
import java.util.function.Consumer;
2728
import java.util.stream.Collectors;
@@ -123,12 +124,17 @@ private void assertDashStreams(final List<? extends Stream> streams) throws Exce
123124
for (final Stream stream : assertFilterStreams(streams, DeliveryMethod.DASH)) {
124125
//noinspection ConstantConditions
125126
final String manifest = YoutubeOtfDashManifestCreator.fromOtfStreamingUrl(
126-
stream.getContent(), stream.getItagItem(), videoLength);
127+
stream.getContent(),
128+
// We know that itagItem has to be set, because it’s youtube-specific
129+
Objects.requireNonNull(stream.getItagItem()),
130+
videoLength
131+
);
127132
assertNotBlank(manifest);
128133

129134
assertManifestGenerated(
130135
manifest,
131-
stream.getItagItem(),
136+
// We know that itagItem has to be set, because it’s youtube-specific
137+
Objects.requireNonNull(stream.getItagItem()),
132138
document -> assertAll(
133139
() -> assertSegmentTemplateElement(document),
134140
() -> assertSegmentTimelineAndSElements(document)
@@ -143,16 +149,22 @@ private void assertProgressiveStreams(final List<? extends Stream> streams) thro
143149
//noinspection ConstantConditions
144150
final String manifest =
145151
YoutubeProgressiveDashManifestCreator.fromProgressiveStreamingUrl(
146-
stream.getContent(), stream.getItagItem(), videoLength);
152+
stream.getContent(),
153+
// We know that itagItem has to be set, because it’s youtube-specific
154+
Objects.requireNonNull(stream.getItagItem()),
155+
videoLength);
147156
assertNotBlank(manifest);
148157

158+
@Nonnull final ItagItem itagItem =
159+
// We know that itagItem has to be set, because it’s youtube-specific
160+
Objects.requireNonNull(stream.getItagItem());
149161
assertManifestGenerated(
150162
manifest,
151-
stream.getItagItem(),
163+
itagItem,
152164
document -> assertAll(
153165
() -> assertBaseUrlElement(document),
154-
() -> assertSegmentBaseElement(document, stream.getItagItem()),
155-
() -> assertInitializationElement(document, stream.getItagItem())
166+
() -> assertSegmentBaseElement(document, itagItem),
167+
() -> assertInitializationElement(document, itagItem)
156168
)
157169
);
158170
}
@@ -171,15 +183,17 @@ private List<? extends Stream> assertFilterStreams(
171183
assertAll(filteredStreams.stream()
172184
.flatMap(stream -> java.util.stream.Stream.of(
173185
() -> assertNotBlank(stream.getContent()),
174-
() -> assertNotNull(stream.getItagItem())
186+
() ->
187+
// We know that itagItem has to be set, because it’s youtube-specific
188+
assertNotNull(stream.getItagItem())
175189
))
176190
);
177191

178192
return filteredStreams;
179193
}
180194

181195
private void assertManifestGenerated(final String dashManifest,
182-
final ItagItem itagItem,
196+
@Nonnull final ItagItem itagItem,
183197
final Consumer<Document> additionalAsserts)
184198
throws Exception {
185199

0 commit comments

Comments
 (0)