Skip to content

Commit f6ec7f9

Browse files
committed
Update DefaultStreamExtractorTest and SoundcloudStreamExtractorTest to support changes made in Stream classes
1 parent 7477ed0 commit f6ec7f9

2 files changed

Lines changed: 43 additions & 20 deletions

File tree

extractor/src/test/java/org/schabi/newpipe/extractor/services/DefaultStreamExtractorTest.java

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -271,13 +271,20 @@ public void testVideoStreams() throws Exception {
271271
assertFalse(videoStreams.isEmpty());
272272

273273
for (final VideoStream stream : videoStreams) {
274-
assertIsSecureUrl(stream.getUrl());
275-
assertFalse(stream.getResolution().isEmpty());
276-
277-
final int formatId = stream.getFormatId();
278-
// see MediaFormat: video stream formats range from 0 to 0x100
279-
assertTrue(0 <= formatId && formatId < 0x100,
280-
"format id does not fit a video stream: " + formatId);
274+
if (stream.isUrl()) {
275+
assertIsSecureUrl(stream.getContent());
276+
}
277+
final StreamType streamType = extractor().getStreamType();
278+
// On some video streams, the resolution can be empty and the format be unknown,
279+
// especially on livestreams (like streams with HLS master playlists)
280+
if (streamType != StreamType.LIVE_STREAM
281+
&& streamType != StreamType.AUDIO_LIVE_STREAM) {
282+
assertFalse(stream.getResolution().isEmpty());
283+
final int formatId = stream.getFormatId();
284+
// see MediaFormat: video stream formats range from 0 to 0x100
285+
assertTrue(0 <= formatId && formatId < 0x100,
286+
"Format id does not fit a video stream: " + formatId);
287+
}
281288
}
282289
} else {
283290
assertTrue(videoStreams.isEmpty());
@@ -294,12 +301,17 @@ public void testAudioStreams() throws Exception {
294301
assertFalse(audioStreams.isEmpty());
295302

296303
for (final AudioStream stream : audioStreams) {
297-
assertIsSecureUrl(stream.getUrl());
304+
if (stream.isUrl()) {
305+
assertIsSecureUrl(stream.getContent());
306+
}
298307

299-
final int formatId = stream.getFormatId();
300-
// see MediaFormat: video stream formats range from 0x100 to 0x1000
301-
assertTrue(0x100 <= formatId && formatId < 0x1000,
302-
"format id does not fit an audio stream: " + formatId);
308+
// The media format can be unknown on some audio streams
309+
if (stream.getFormat() != null) {
310+
final int formatId = stream.getFormat().id;
311+
// see MediaFormat: audio stream formats range from 0x100 to 0x1000
312+
assertTrue(0x100 <= formatId && formatId < 0x1000,
313+
"Format id does not fit an audio stream: " + formatId);
314+
}
303315
}
304316
} else {
305317
assertTrue(audioStreams.isEmpty());
@@ -316,12 +328,14 @@ public void testSubtitles() throws Exception {
316328
assertFalse(subtitles.isEmpty());
317329

318330
for (final SubtitlesStream stream : subtitles) {
319-
assertIsSecureUrl(stream.getUrl());
331+
if (stream.isUrl()) {
332+
assertIsSecureUrl(stream.getContent());
333+
}
320334

321335
final int formatId = stream.getFormatId();
322336
// see MediaFormat: video stream formats range from 0x1000 to 0x10000
323337
assertTrue(0x1000 <= formatId && formatId < 0x10000,
324-
"format id does not fit a subtitles stream: " + formatId);
338+
"Format id does not fit a subtitles stream: " + formatId);
325339
}
326340
} else {
327341
assertTrue(subtitles.isEmpty());
@@ -344,7 +358,8 @@ public void testGetDashMpdUrl() throws Exception {
344358
assertTrue(dashMpdUrl.isEmpty());
345359
} else {
346360
assertIsSecureUrl(dashMpdUrl);
347-
ExtractorAsserts.assertContains(expectedDashMpdUrlContains(), extractor().getDashMpdUrl());
361+
ExtractorAsserts.assertContains(expectedDashMpdUrlContains(),
362+
extractor().getDashMpdUrl());
348363
}
349364
}
350365

extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamExtractorTest.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import org.schabi.newpipe.extractor.exceptions.SoundCloudGoPlusContentException;
1313
import org.schabi.newpipe.extractor.services.DefaultStreamExtractorTest;
1414
import org.schabi.newpipe.extractor.stream.AudioStream;
15+
import org.schabi.newpipe.extractor.stream.DeliveryMethod;
1516
import org.schabi.newpipe.extractor.stream.StreamExtractor;
1617
import org.schabi.newpipe.extractor.stream.StreamType;
1718

@@ -21,7 +22,7 @@
2122

2223
import javax.annotation.Nullable;
2324

24-
import static org.junit.jupiter.api.Assertions.assertEquals;
25+
import static org.junit.jupiter.api.Assertions.*;
2526
import static org.schabi.newpipe.extractor.ServiceList.SoundCloud;
2627

2728
public class SoundcloudStreamExtractorTest {
@@ -188,15 +189,22 @@ public void testAudioStreams() throws Exception {
188189
final List<AudioStream> audioStreams = extractor.getAudioStreams();
189190
assertEquals(2, audioStreams.size());
190191
for (final AudioStream audioStream : audioStreams) {
191-
final String mediaUrl = audioStream.getUrl();
192+
final DeliveryMethod deliveryMethod = audioStream.getDeliveryMethod();
193+
assertSame(DeliveryMethod.PROGRESSIVE_HTTP, deliveryMethod,
194+
"Wrong delivery method for stream " + audioStream.getId() + ": "
195+
+ deliveryMethod);
196+
final String mediaUrl = audioStream.getContent();
192197
if (audioStream.getFormat() == MediaFormat.OPUS) {
193-
// assert that it's an OPUS 64 kbps media URL with a single range which comes from an HLS SoundCloud CDN
198+
// Assert that it's an OPUS 64 kbps media URL with a single range which comes
199+
// from an HLS SoundCloud CDN
194200
ExtractorAsserts.assertContains("-hls-opus-media.sndcdn.com", mediaUrl);
195201
ExtractorAsserts.assertContains(".64.opus", mediaUrl);
196202
}
197203
if (audioStream.getFormat() == MediaFormat.MP3) {
198-
// assert that it's a MP3 128 kbps media URL which comes from a progressive SoundCloud CDN
199-
ExtractorAsserts.assertContains("-media.sndcdn.com/bKOA7Pwbut93.128.mp3", mediaUrl);
204+
// Assert that it's a MP3 128 kbps media URL which comes from a progressive
205+
// SoundCloud CDN
206+
ExtractorAsserts.assertContains("-media.sndcdn.com/bKOA7Pwbut93.128.mp3",
207+
mediaUrl);
200208
}
201209
}
202210
}

0 commit comments

Comments
 (0)