1515import org .junit .jupiter .api .Test ;
1616import org .schabi .newpipe .extractor .ExtractorAsserts ;
1717import org .schabi .newpipe .extractor .InfoItemsCollector ;
18- import org .schabi .newpipe .extractor .MediaFormat ;
1918import org .schabi .newpipe .extractor .MetaInfo ;
2019import org .schabi .newpipe .extractor .localization .DateWrapper ;
21- import org .schabi .newpipe .extractor .stream .AudioStream ;
2220import org .schabi .newpipe .extractor .stream .Description ;
2321import org .schabi .newpipe .extractor .stream .Frameset ;
2422import org .schabi .newpipe .extractor .stream .Privacy ;
2523import org .schabi .newpipe .extractor .stream .StreamExtractor ;
2624import org .schabi .newpipe .extractor .stream .StreamType ;
25+ import org .schabi .newpipe .extractor .streamdata .delivery .DASHManifestDeliveryData ;
26+ import org .schabi .newpipe .extractor .streamdata .delivery .DeliveryData ;
27+ import org .schabi .newpipe .extractor .streamdata .delivery .UrlBasedDeliveryData ;
28+ import org .schabi .newpipe .extractor .streamdata .stream .AudioStream ;
29+ import org .schabi .newpipe .extractor .streamdata .stream .SubtitleStream ;
30+ import org .schabi .newpipe .extractor .streamdata .stream .VideoAudioStream ;
31+ import org .schabi .newpipe .extractor .streamdata .stream .VideoStream ;
2732
2833import java .net .MalformedURLException ;
2934import java .net .URL ;
4247public abstract class DefaultStreamExtractorTest extends DefaultExtractorTest <StreamExtractor >
4348 implements BaseStreamExtractorTest {
4449
45- public abstract StreamType expectedStreamType ();
50+ public boolean expectedIsLive () { return false ; }
51+ public boolean expectedIsAudioOnly () { return false ; }
4652 public abstract String expectedUploaderName ();
4753 public abstract String expectedUploaderUrl ();
4854 public boolean expectedUploaderVerified () { return false ; }
@@ -61,8 +67,9 @@ public abstract class DefaultStreamExtractorTest extends DefaultExtractorTest<St
6167 public boolean expectedHasRelatedItems () { return true ; } // default: there are related videos
6268 public int expectedAgeLimit () { return StreamExtractor .NO_AGE_LIMIT ; } // default: no limit
6369 @ Nullable public String expectedErrorMessage () { return null ; } // default: no error message
64- public boolean expectedHasVideoStreams () { return true ; } // default: there are video streams
65- public boolean expectedHasAudioStreams () { return true ; } // default: there are audio streams
70+ public boolean expectedHasVideoOnlyStreams () { return true ; }
71+ public boolean expectedHasVideoAndAudioStreams () { return true ; }
72+ public boolean expectedHasAudioStreams () { return true ; }
6673 public boolean expectedHasSubtitles () { return true ; } // default: there are subtitles streams
6774 @ Nullable public String expectedDashMpdUrlContains () { return null ; } // default: no dash mpd
6875 public boolean expectedHasFrames () { return true ; } // default: there are frames
@@ -254,34 +261,39 @@ public void testErrorMessage() throws Exception {
254261
255262 @ Test
256263 @ Override
257- public void testVideoStreams () throws Exception {
258- final List <VideoStream > videoStreams = extractor ().getVideoStreams ();
264+ public void testVideoOnlyStreams () throws Exception {
259265 final List <VideoStream > videoOnlyStreams = extractor ().getVideoOnlyStreams ();
260- assertNotNull (videoStreams );
261266 assertNotNull (videoOnlyStreams );
262- videoStreams .addAll (videoOnlyStreams );
263267
264- if (expectedHasVideoStreams ()) {
265- assertFalse (videoStreams .isEmpty ());
268+ if (expectedHasVideoOnlyStreams ()) {
269+ assertFalse (videoOnlyStreams .isEmpty ());
266270
267- for (final VideoStream stream : videoStreams ) {
268- if (stream .isUrl ()) {
269- assertIsSecureUrl (stream .getContent ());
270- }
271- final StreamType streamType = extractor ().getStreamType ();
272- // On some video streams, the resolution can be empty and the format be unknown,
273- // especially on livestreams (like streams with HLS master playlists)
274- if (streamType != StreamType .LIVE_STREAM
275- && streamType != StreamType .AUDIO_LIVE_STREAM ) {
276- assertFalse (stream .getResolution ().isEmpty ());
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 );
281- }
271+ for (final VideoStream stream : videoOnlyStreams ) {
272+ assertNotNull (stream .mediaFormat ());
273+ assertNotNull (stream .videoQualityData ());
274+ checkDeliveryData (stream .deliveryData ());
275+ }
276+ } else {
277+ assertTrue (videoOnlyStreams .isEmpty ());
278+ }
279+ }
280+
281+ @ Test
282+ @ Override
283+ public void testVideoAudioStreams () throws Exception {
284+ final List <VideoAudioStream > videoAudioStreams = extractor ().getVideoStreams ();
285+ assertNotNull (videoAudioStreams );
286+
287+ if (expectedHasVideoAndAudioStreams ()) {
288+ assertFalse (videoAudioStreams .isEmpty ());
289+
290+ for (final VideoAudioStream stream : videoAudioStreams ) {
291+ assertNotNull (stream .mediaFormat ());
292+ assertNotNull (stream .videoQualityData ());
293+ checkDeliveryData (stream .deliveryData ());
282294 }
283295 } else {
284- assertTrue (videoStreams .isEmpty ());
296+ assertTrue (videoAudioStreams .isEmpty ());
285297 }
286298 }
287299
@@ -295,17 +307,8 @@ public void testAudioStreams() throws Exception {
295307 assertFalse (audioStreams .isEmpty ());
296308
297309 for (final AudioStream stream : audioStreams ) {
298- if (stream .isUrl ()) {
299- assertIsSecureUrl (stream .getContent ());
300- }
301-
302- // The media format can be unknown on some audio streams
303- if (stream .getFormat () != null ) {
304- final int formatId = stream .getFormat ().id ;
305- // see MediaFormat: audio stream formats range from 0x100 to 0x1000
306- assertTrue (0x100 <= formatId && formatId < 0x1000 ,
307- "Format id does not fit an audio stream: " + formatId );
308- }
310+ assertNotNull (stream .mediaFormat ());
311+ checkDeliveryData (stream .deliveryData ());
309312 }
310313 } else {
311314 assertTrue (audioStreams .isEmpty ());
@@ -315,32 +318,29 @@ public void testAudioStreams() throws Exception {
315318 @ Test
316319 @ Override
317320 public void testSubtitles () throws Exception {
318- final List <SubtitlesStream > subtitles = extractor ().getSubtitlesDefault ();
321+ final List <SubtitleStream > subtitles = extractor ().getSubtitles ();
319322 assertNotNull (subtitles );
320323
321324 if (expectedHasSubtitles ()) {
322325 assertFalse (subtitles .isEmpty ());
323326
324- for (final SubtitlesStream stream : subtitles ) {
325- if (stream .isUrl ()) {
326- assertIsSecureUrl (stream .getContent ());
327- }
328-
329- final int formatId = stream .getFormatId ();
330- // see MediaFormat: video stream formats range from 0x1000 to 0x10000
331- assertTrue (0x1000 <= formatId && formatId < 0x10000 ,
332- "Format id does not fit a subtitles stream: " + formatId );
327+ for (final SubtitleStream stream : subtitles ) {
328+ assertNotNull (stream .languageCode ());
329+ assertNotNull (stream .mediaFormat ());
330+ checkDeliveryData (stream .deliveryData ());
333331 }
334332 } else {
335333 assertTrue (subtitles .isEmpty ());
334+ }
335+ }
336336
337- final MediaFormat [] formats = { MediaFormat . VTT , MediaFormat . TTML , MediaFormat . SRT ,
338- MediaFormat . TRANSCRIPT1 , MediaFormat . TRANSCRIPT2 , MediaFormat . TRANSCRIPT3 };
339- for ( final MediaFormat format : formats ) {
340- final List < SubtitlesStream > formatSubtitles = extractor (). getSubtitles ( format );
341- assertNotNull ( formatSubtitles );
342- assertTrue ( formatSubtitles . isEmpty ()) ;
343- }
337+ private void checkDeliveryData ( final DeliveryData deliveryData ) {
338+ if ( deliveryData instanceof UrlBasedDeliveryData ) {
339+ assertIsSecureUrl ((( UrlBasedDeliveryData ) deliveryData ). url ());
340+ } else if ( deliveryData instanceof DASHManifestDeliveryData ) {
341+ final DASHManifestDeliveryData dashManifestDD =
342+ ( DASHManifestDeliveryData ) deliveryData ;
343+ assertNotNull ( dashManifestDD . getDashManifestCreator ());
344344 }
345345 }
346346
@@ -455,6 +455,15 @@ public void testMetaInfo() throws Exception {
455455 assertTrue (urls .contains (expectedUrl ));
456456 }
457457 }
458+ }
459+
460+ @ Test
461+ public void testIsLive () throws Exception {
462+ assertEquals (expectedIsLive (), extractor ().isLive ());
463+ }
458464
465+ @ Test
466+ public void testIsAudioOnly () throws Exception {
467+ assertEquals (expectedIsAudioOnly (), extractor ().isAudioOnly ());
459468 }
460469}
0 commit comments