|
| 1 | +package org.schabi.newpipe.extractor.services.youtube.stream; |
| 2 | + |
| 3 | +import org.junit.BeforeClass; |
| 4 | +import org.junit.Test; |
| 5 | +import org.schabi.newpipe.Downloader; |
| 6 | +import org.schabi.newpipe.extractor.MediaFormat; |
| 7 | +import org.schabi.newpipe.extractor.NewPipe; |
| 8 | +import org.schabi.newpipe.extractor.exceptions.ExtractionException; |
| 9 | +import org.schabi.newpipe.extractor.exceptions.ParsingException; |
| 10 | +import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeStreamExtractor; |
| 11 | +import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector; |
| 12 | +import org.schabi.newpipe.extractor.stream.StreamType; |
| 13 | +import org.schabi.newpipe.extractor.stream.VideoStream; |
| 14 | +import org.schabi.newpipe.extractor.utils.Localization; |
| 15 | +import org.schabi.newpipe.extractor.utils.Utils; |
| 16 | + |
| 17 | +import java.io.IOException; |
| 18 | + |
| 19 | +import static org.junit.Assert.*; |
| 20 | +import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsSecureUrl; |
| 21 | +import static org.schabi.newpipe.extractor.ServiceList.YouTube; |
| 22 | + |
| 23 | +public class YoutubeStreamExtractorLivestreamTest { |
| 24 | + private static YoutubeStreamExtractor extractor; |
| 25 | + |
| 26 | + @BeforeClass |
| 27 | + public static void setUp() throws Exception { |
| 28 | + NewPipe.init(Downloader.getInstance(), new Localization("GB", "en")); |
| 29 | + extractor = (YoutubeStreamExtractor) YouTube |
| 30 | + .getStreamExtractor("https://www.youtube.com/watch?v=EcEMX-63PKY"); |
| 31 | + extractor.fetchPage(); |
| 32 | + } |
| 33 | + |
| 34 | + @Test |
| 35 | + public void testGetInvalidTimeStamp() throws ParsingException { |
| 36 | + assertTrue(extractor.getTimeStamp() + "", |
| 37 | + extractor.getTimeStamp() <= 0); |
| 38 | + } |
| 39 | + |
| 40 | + @Test |
| 41 | + public void testGetTitle() throws ParsingException { |
| 42 | + assertFalse(extractor.getName().isEmpty()); |
| 43 | + } |
| 44 | + |
| 45 | + @Test |
| 46 | + public void testGetDescription() throws ParsingException { |
| 47 | + assertNotNull(extractor.getDescription()); |
| 48 | + assertFalse(extractor.getDescription().isEmpty()); |
| 49 | + } |
| 50 | + |
| 51 | + @Test |
| 52 | + public void testGetFullLinksInDescription() throws ParsingException { |
| 53 | + assertTrue(extractor.getDescription().contains("https://www.instagram.com/nathalie.baraton/")); |
| 54 | + assertFalse(extractor.getDescription().contains("https://www.instagram.com/nathalie.ba...")); |
| 55 | + } |
| 56 | + |
| 57 | + @Test |
| 58 | + public void testGetUploaderName() throws ParsingException { |
| 59 | + assertNotNull(extractor.getUploaderName()); |
| 60 | + assertFalse(extractor.getUploaderName().isEmpty()); |
| 61 | + } |
| 62 | + |
| 63 | + |
| 64 | + @Test |
| 65 | + public void testGetLength() throws ParsingException { |
| 66 | + assertEquals(0, extractor.getLength()); |
| 67 | + } |
| 68 | + |
| 69 | + @Test |
| 70 | + public void testGetViewCount() throws ParsingException { |
| 71 | + long count = extractor.getViewCount(); |
| 72 | + assertTrue(Long.toString(count), count >= 7148995); |
| 73 | + } |
| 74 | + |
| 75 | + @Test |
| 76 | + public void testGetUploadDate() throws ParsingException { |
| 77 | + assertTrue(extractor.getUploadDate().length() > 0); |
| 78 | + } |
| 79 | + |
| 80 | + @Test |
| 81 | + public void testGetUploaderUrl() throws ParsingException { |
| 82 | + assertEquals("https://www.youtube.com/channel/UCSJ4gkVC6NrvII8umztf0Ow", extractor.getUploaderUrl()); |
| 83 | + } |
| 84 | + |
| 85 | + @Test |
| 86 | + public void testGetThumbnailUrl() throws ParsingException { |
| 87 | + assertIsSecureUrl(extractor.getThumbnailUrl()); |
| 88 | + } |
| 89 | + |
| 90 | + @Test |
| 91 | + public void testGetUploaderAvatarUrl() throws ParsingException { |
| 92 | + assertIsSecureUrl(extractor.getUploaderAvatarUrl()); |
| 93 | + } |
| 94 | + |
| 95 | + @Test |
| 96 | + public void testGetAudioStreams() throws ExtractionException { |
| 97 | + assertFalse(extractor.getAudioStreams().isEmpty()); |
| 98 | + } |
| 99 | + |
| 100 | + @Test |
| 101 | + public void testGetVideoStreams() throws ExtractionException { |
| 102 | + for (VideoStream s : extractor.getVideoStreams()) { |
| 103 | + assertIsSecureUrl(s.url); |
| 104 | + assertTrue(s.resolution.length() > 0); |
| 105 | + assertTrue(Integer.toString(s.getFormatId()), |
| 106 | + 0 <= s.getFormatId() && s.getFormatId() <= 0x100); |
| 107 | + } |
| 108 | + } |
| 109 | + |
| 110 | + @Test |
| 111 | + public void testStreamType() throws ParsingException { |
| 112 | + assertSame(extractor.getStreamType(), StreamType.LIVE_STREAM); |
| 113 | + } |
| 114 | + |
| 115 | + @Test |
| 116 | + public void testGetDashMpd() throws ParsingException { |
| 117 | + // we dont expect this particular video to have a DASH file. For this purpouse we use a different test class. |
| 118 | + assertTrue(extractor.getDashMpdUrl(), extractor.getDashMpdUrl().isEmpty()); |
| 119 | + } |
| 120 | + |
| 121 | + @Test |
| 122 | + public void testGetRelatedVideos() throws ExtractionException, IOException { |
| 123 | + StreamInfoItemsCollector relatedVideos = extractor.getRelatedStreams(); |
| 124 | + Utils.printErrors(relatedVideos.getErrors()); |
| 125 | + assertFalse(relatedVideos.getItems().isEmpty()); |
| 126 | + assertTrue(relatedVideos.getErrors().isEmpty()); |
| 127 | + } |
| 128 | + |
| 129 | + @Test |
| 130 | + public void testGetSubtitlesListDefault() throws IOException, ExtractionException { |
| 131 | + assertTrue(extractor.getSubtitlesDefault().isEmpty()); |
| 132 | + } |
| 133 | + |
| 134 | + @Test |
| 135 | + public void testGetSubtitlesList() throws IOException, ExtractionException { |
| 136 | + assertTrue(extractor.getSubtitles(MediaFormat.TTML).isEmpty()); |
| 137 | + } |
| 138 | +} |
0 commit comments