|
16 | 16 | import static org.junit.Assert.*; |
17 | 17 | import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsSecureUrl; |
18 | 18 | import static org.schabi.newpipe.extractor.ServiceList.YouTube; |
| 19 | +import static org.schabi.newpipe.extractor.services.youtube.YoutubeTrendingExtractorTest.extractor; |
19 | 20 |
|
20 | 21 | /* |
21 | 22 | * Created by Christian Schabesberger on 30.12.15. |
|
41 | 42 | * Test for {@link StreamExtractor} |
42 | 43 | */ |
43 | 44 | public class YoutubeStreamExtractorDefaultTest { |
44 | | - private static YoutubeStreamExtractor extractor; |
45 | | - |
46 | | - @BeforeClass |
47 | | - public static void setUp() throws Exception { |
48 | | - NewPipe.init(Downloader.getInstance()); |
49 | | - extractor = (YoutubeStreamExtractor) YouTube |
50 | | - .getStreamExtractor("https://www.youtube.com/watch?v=rYEDA3JcQqw"); |
51 | | - extractor.fetchPage(); |
52 | | - } |
53 | 45 |
|
54 | | - @Test |
55 | | - public void testGetInvalidTimeStamp() throws ParsingException { |
56 | | - assertTrue(extractor.getTimeStamp() + "", |
57 | | - extractor.getTimeStamp() <= 0); |
58 | | - } |
| 46 | + public static class AdeleHello { |
| 47 | + private static YoutubeStreamExtractor extractor; |
59 | 48 |
|
60 | | - @Test |
61 | | - public void testGetValidTimeStamp() throws ExtractionException { |
62 | | - StreamExtractor extractor = YouTube.getStreamExtractor("https://youtu.be/FmG385_uUys?t=174"); |
63 | | - assertEquals(extractor.getTimeStamp() + "", "174"); |
64 | | - } |
| 49 | + @BeforeClass |
| 50 | + public static void setUp() throws Exception { |
| 51 | + NewPipe.init(Downloader.getInstance()); |
| 52 | + extractor = (YoutubeStreamExtractor) YouTube |
| 53 | + .getStreamExtractor("https://www.youtube.com/watch?v=rYEDA3JcQqw"); |
| 54 | + extractor.fetchPage(); |
| 55 | + } |
65 | 56 |
|
66 | | - @Test |
67 | | - public void testGetTitle() throws ParsingException { |
68 | | - assertFalse(extractor.getName().isEmpty()); |
69 | | - } |
| 57 | + @Test |
| 58 | + public void testGetInvalidTimeStamp() throws ParsingException { |
| 59 | + assertTrue(extractor.getTimeStamp() + "", |
| 60 | + extractor.getTimeStamp() <= 0); |
| 61 | + } |
70 | 62 |
|
71 | | - @Test |
72 | | - public void testGetDescription() throws ParsingException { |
73 | | - assertNotNull(extractor.getDescription()); |
74 | | - assertFalse(extractor.getDescription().isEmpty()); |
75 | | - } |
| 63 | + @Test |
| 64 | + public void testGetValidTimeStamp() throws ExtractionException { |
| 65 | + StreamExtractor extractor = YouTube.getStreamExtractor("https://youtu.be/FmG385_uUys?t=174"); |
| 66 | + assertEquals(extractor.getTimeStamp() + "", "174"); |
| 67 | + } |
76 | 68 |
|
77 | | - @Test |
78 | | - public void testGetFullLinksInDescriptlion() throws ParsingException { |
79 | | - assertTrue(extractor.getDescription().contains("http://smarturl.it/SubscribeAdele?IQid=yt")); |
80 | | - assertFalse(extractor.getDescription().contains("http://smarturl.it/SubscribeAdele?IQi...")); |
81 | | - } |
| 69 | + @Test |
| 70 | + public void testGetTitle() throws ParsingException { |
| 71 | + assertFalse(extractor.getName().isEmpty()); |
| 72 | + } |
82 | 73 |
|
83 | | - @Test |
84 | | - public void testGetUploaderName() throws ParsingException { |
85 | | - assertNotNull(extractor.getUploaderName()); |
86 | | - assertFalse(extractor.getUploaderName().isEmpty()); |
87 | | - } |
| 74 | + @Test |
| 75 | + public void testGetDescription() throws ParsingException { |
| 76 | + assertNotNull(extractor.getDescription()); |
| 77 | + assertFalse(extractor.getDescription().isEmpty()); |
| 78 | + } |
88 | 79 |
|
| 80 | + @Test |
| 81 | + public void testGetFullLinksInDescriptlion() throws ParsingException { |
| 82 | + assertTrue(extractor.getDescription().contains("http://smarturl.it/SubscribeAdele?IQid=yt")); |
| 83 | + assertFalse(extractor.getDescription().contains("http://smarturl.it/SubscribeAdele?IQi...")); |
| 84 | + } |
89 | 85 |
|
90 | | - @Test |
91 | | - public void testGetLength() throws ParsingException { |
92 | | - assertTrue(extractor.getLength() > 0); |
93 | | - } |
| 86 | + @Test |
| 87 | + public void testGetUploaderName() throws ParsingException { |
| 88 | + assertNotNull(extractor.getUploaderName()); |
| 89 | + assertFalse(extractor.getUploaderName().isEmpty()); |
| 90 | + } |
94 | 91 |
|
95 | | - @Test |
96 | | - public void testGetViewCount() throws ParsingException { |
97 | | - Long count = extractor.getViewCount(); |
98 | | - assertTrue(Long.toString(count), count >= /* specific to that video */ 1220025784); |
99 | | - } |
100 | 92 |
|
101 | | - @Test |
102 | | - public void testGetUploadDate() throws ParsingException { |
103 | | - assertTrue(extractor.getUploadDate().length() > 0); |
104 | | - } |
| 93 | + @Test |
| 94 | + public void testGetLength() throws ParsingException { |
| 95 | + assertTrue(extractor.getLength() > 0); |
| 96 | + } |
105 | 97 |
|
106 | | - @Test |
107 | | - public void testGetUploaderUrl() throws ParsingException { |
108 | | - assertTrue(extractor.getUploaderUrl().length() > 0); |
109 | | - } |
| 98 | + @Test |
| 99 | + public void testGetViewCount() throws ParsingException { |
| 100 | + Long count = extractor.getViewCount(); |
| 101 | + assertTrue(Long.toString(count), count >= /* specific to that video */ 1220025784); |
| 102 | + } |
110 | 103 |
|
111 | | - @Test |
112 | | - public void testGetThumbnailUrl() throws ParsingException { |
113 | | - assertIsSecureUrl(extractor.getThumbnailUrl()); |
114 | | - } |
| 104 | + @Test |
| 105 | + public void testGetUploadDate() throws ParsingException { |
| 106 | + assertTrue(extractor.getUploadDate().length() > 0); |
| 107 | + } |
115 | 108 |
|
116 | | - @Test |
117 | | - public void testGetUploaderAvatarUrl() throws ParsingException { |
118 | | - assertIsSecureUrl(extractor.getUploaderAvatarUrl()); |
119 | | - } |
| 109 | + @Test |
| 110 | + public void testGetUploaderUrl() throws ParsingException { |
| 111 | + assertTrue(extractor.getUploaderUrl().length() > 0); |
| 112 | + } |
120 | 113 |
|
121 | | - @Test |
122 | | - public void testGetAudioStreams() throws IOException, ExtractionException { |
123 | | - assertFalse(extractor.getAudioStreams().isEmpty()); |
124 | | - } |
| 114 | + @Test |
| 115 | + public void testGetThumbnailUrl() throws ParsingException { |
| 116 | + assertIsSecureUrl(extractor.getThumbnailUrl()); |
| 117 | + } |
125 | 118 |
|
126 | | - @Test |
127 | | - public void testGetVideoStreams() throws IOException, ExtractionException { |
128 | | - for (VideoStream s : extractor.getVideoStreams()) { |
129 | | - assertIsSecureUrl(s.url); |
130 | | - assertTrue(s.resolution.length() > 0); |
131 | | - assertTrue(Integer.toString(s.getFormatId()), |
132 | | - 0 <= s.getFormatId() && s.getFormatId() <= 4); |
| 119 | + @Test |
| 120 | + public void testGetUploaderAvatarUrl() throws ParsingException { |
| 121 | + assertIsSecureUrl(extractor.getUploaderAvatarUrl()); |
133 | 122 | } |
134 | | - } |
135 | 123 |
|
136 | | - @Test |
137 | | - public void testStreamType() throws ParsingException { |
138 | | - assertTrue(extractor.getStreamType() == StreamType.VIDEO_STREAM); |
139 | | - } |
| 124 | + @Test |
| 125 | + public void testGetAudioStreams() throws IOException, ExtractionException { |
| 126 | + assertFalse(extractor.getAudioStreams().isEmpty()); |
| 127 | + } |
140 | 128 |
|
141 | | - @Test |
142 | | - public void testGetDashMpd() throws ParsingException { |
143 | | - // we dont expect this particular video to have a DASH file. For this purpouse we use a different test class. |
144 | | - assertTrue(extractor.getDashMpdUrl(), |
145 | | - extractor.getDashMpdUrl() != null && extractor.getDashMpdUrl().isEmpty()); |
146 | | - } |
| 129 | + @Test |
| 130 | + public void testGetVideoStreams() throws IOException, ExtractionException { |
| 131 | + for (VideoStream s : extractor.getVideoStreams()) { |
| 132 | + assertIsSecureUrl(s.url); |
| 133 | + assertTrue(s.resolution.length() > 0); |
| 134 | + assertTrue(Integer.toString(s.getFormatId()), |
| 135 | + 0 <= s.getFormatId() && s.getFormatId() <= 4); |
| 136 | + } |
| 137 | + } |
147 | 138 |
|
148 | | - @Test |
149 | | - public void testGetRelatedVideos() throws ExtractionException, IOException { |
150 | | - StreamInfoItemsCollector relatedVideos = extractor.getRelatedVideos(); |
151 | | - Utils.printErrors(relatedVideos.getErrors()); |
152 | | - assertFalse(relatedVideos.getItems().isEmpty()); |
153 | | - assertTrue(relatedVideos.getErrors().isEmpty()); |
154 | | - } |
| 139 | + @Test |
| 140 | + public void testStreamType() throws ParsingException { |
| 141 | + assertTrue(extractor.getStreamType() == StreamType.VIDEO_STREAM); |
| 142 | + } |
| 143 | + |
| 144 | + @Test |
| 145 | + public void testGetDashMpd() throws ParsingException { |
| 146 | + // we dont expect this particular video to have a DASH file. For this purpouse we use a different test class. |
| 147 | + assertTrue(extractor.getDashMpdUrl(), |
| 148 | + extractor.getDashMpdUrl() != null && extractor.getDashMpdUrl().isEmpty()); |
| 149 | + } |
155 | 150 |
|
156 | | - @Test |
157 | | - public void testGetSubtitlesListDefault() throws IOException, ExtractionException { |
158 | | - // Video (/view?v=YQHsXMglC9A) set in the setUp() method has no captions => null |
159 | | - assertTrue(extractor.getSubtitlesDefault().isEmpty()); |
| 151 | + @Test |
| 152 | + public void testGetRelatedVideos() throws ExtractionException, IOException { |
| 153 | + StreamInfoItemsCollector relatedVideos = extractor.getRelatedVideos(); |
| 154 | + Utils.printErrors(relatedVideos.getErrors()); |
| 155 | + assertFalse(relatedVideos.getItems().isEmpty()); |
| 156 | + assertTrue(relatedVideos.getErrors().isEmpty()); |
| 157 | + } |
| 158 | + |
| 159 | + @Test |
| 160 | + public void testGetSubtitlesListDefault() throws IOException, ExtractionException { |
| 161 | + // Video (/view?v=YQHsXMglC9A) set in the setUp() method has no captions => null |
| 162 | + assertTrue(extractor.getSubtitlesDefault().isEmpty()); |
| 163 | + } |
| 164 | + |
| 165 | + @Test |
| 166 | + public void testGetSubtitlesList() throws IOException, ExtractionException { |
| 167 | + // Video (/view?v=YQHsXMglC9A) set in the setUp() method has no captions => null |
| 168 | + assertTrue(extractor.getSubtitles(SubtitlesFormat.TTML).isEmpty()); |
| 169 | + } |
160 | 170 | } |
161 | 171 |
|
162 | | - @Test |
163 | | - public void testGetSubtitlesList() throws IOException, ExtractionException { |
164 | | - // Video (/view?v=YQHsXMglC9A) set in the setUp() method has no captions => null |
165 | | - assertTrue(extractor.getSubtitles(SubtitlesFormat.TTML).isEmpty()); |
| 172 | + public static class DescriptionTestPewdiepie { |
| 173 | + private static YoutubeStreamExtractor extractor; |
| 174 | + |
| 175 | + @BeforeClass |
| 176 | + public static void setUp() throws Exception { |
| 177 | + NewPipe.init(Downloader.getInstance()); |
| 178 | + extractor = (YoutubeStreamExtractor) YouTube |
| 179 | + .getStreamExtractor("https://www.youtube.com/watch?v=dJY8iT341F4"); |
| 180 | + extractor.fetchPage(); |
| 181 | + } |
| 182 | + |
| 183 | + @Test |
| 184 | + public void testGetDescription() throws ParsingException { |
| 185 | + assertNotNull(extractor.getDescription()); |
| 186 | + assertFalse(extractor.getDescription().isEmpty()); |
| 187 | + } |
| 188 | + |
| 189 | + @Test |
| 190 | + public void testGetFullLinksInDescriptlion() throws ParsingException { |
| 191 | + assertTrue(extractor.getDescription().contains("https://www.reddit.com/r/PewdiepieSubmissions/")); |
| 192 | + assertTrue(extractor.getDescription().contains("https://www.youtube.com/channel/UC3e8EMTOn4g6ZSKggHTnNng")); |
| 193 | + |
| 194 | + assertFalse(extractor.getDescription().contains("https://www.reddit.com/r/PewdiepieSub...")); |
| 195 | + assertFalse(extractor.getDescription().contains("https://usa.clutchchairz.com/product/...")); |
| 196 | + assertFalse(extractor.getDescription().contains("https://europe.clutchchairz.com/en/pr...")); |
| 197 | + assertFalse(extractor.getDescription().contains("https://canada.clutchchairz.com/produ...")); |
| 198 | + assertFalse(extractor.getDescription().contains("http://store.steampowered.com/app/703...")); |
| 199 | + assertFalse(extractor.getDescription().contains("https://www.youtube.com/channel/UC3e8...")); |
| 200 | + } |
166 | 201 | } |
167 | 202 | } |
0 commit comments