|
9 | 9 | import org.schabi.newpipe.extractor.comments.CommentsInfo; |
10 | 10 | import org.schabi.newpipe.extractor.comments.CommentsInfoItem; |
11 | 11 | import org.schabi.newpipe.extractor.exceptions.ExtractionException; |
| 12 | +import org.schabi.newpipe.extractor.localization.Localization; |
12 | 13 | import org.schabi.newpipe.extractor.services.DefaultTests; |
13 | 14 | import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeCommentsExtractor; |
14 | 15 | import org.schabi.newpipe.extractor.utils.Utils; |
15 | 16 |
|
16 | 17 | import java.io.IOException; |
17 | 18 | import java.util.List; |
| 19 | +import java.util.Locale; |
18 | 20 | import java.util.Random; |
19 | 21 |
|
20 | 22 | import static org.junit.Assert.assertEquals; |
@@ -99,7 +101,6 @@ public void testGetCommentsAllData() throws IOException, ExtractionException { |
99 | 101 | assertFalse(Utils.isBlank(c.getThumbnailUrl())); |
100 | 102 | assertFalse(Utils.isBlank(c.getUrl())); |
101 | 103 | assertTrue(c.getLikeCount() >= 0); |
102 | | - assertFalse(Utils.isBlank(c.getTextualVoteCount())); |
103 | 104 | } |
104 | 105 | } |
105 | 106 |
|
@@ -150,7 +151,6 @@ public void testGetCommentsAllData() throws IOException, ExtractionException { |
150 | 151 | assertFalse(Utils.isBlank(c.getThumbnailUrl())); |
151 | 152 | assertFalse(Utils.isBlank(c.getUrl())); |
152 | 153 | assertTrue(c.getLikeCount() >= 0); |
153 | | - assertFalse(Utils.isBlank(c.getTextualVoteCount())); |
154 | 154 | if (c.getCommentId().equals("Ugga_h1-EXdHB3gCoAEC")) { // comment without text |
155 | 155 | assertTrue(Utils.isBlank(c.getCommentText())); |
156 | 156 | } else { |
@@ -194,7 +194,6 @@ public void testGetCommentsAllData() throws IOException, ExtractionException { |
194 | 194 | assertFalse(Utils.isBlank(c.getThumbnailUrl())); |
195 | 195 | assertFalse(Utils.isBlank(c.getUrl())); |
196 | 196 | assertTrue(c.getLikeCount() >= 0); |
197 | | - assertFalse(Utils.isBlank(c.getTextualVoteCount())); |
198 | 197 | assertFalse(Utils.isBlank(c.getCommentText())); |
199 | 198 | if (c.isHeartedByUploader()) { |
200 | 199 | heartedByUploader = true; |
@@ -235,12 +234,76 @@ public void testGetCommentsAllData() throws IOException, ExtractionException { |
235 | 234 | assertNotNull(c.getUploadDate()); |
236 | 235 | assertFalse(Utils.isBlank(c.getThumbnailUrl())); |
237 | 236 | assertFalse(Utils.isBlank(c.getUrl())); |
238 | | - assertFalse(Utils.isBlank(c.getTextualVoteCount())); |
239 | 237 | assertTrue(c.getLikeCount() >= 0); |
240 | 238 | assertFalse(Utils.isBlank(c.getCommentText())); |
241 | 239 | } |
242 | 240 |
|
243 | 241 | assertTrue("First comment isn't pinned", comments.getItems().get(0).isPinned()); |
244 | 242 | } |
245 | 243 | } |
| 244 | + |
| 245 | + /** |
| 246 | + * Checks if the likes/votes are handled correctly<br/> |
| 247 | + * A pinned comment with >15K likes is used for the test |
| 248 | + */ |
| 249 | + public static class LikesVotes { |
| 250 | + private final static String url = "https://www.youtube.com/watch?v=QqsLTNkzvaY"; |
| 251 | + private static YoutubeCommentsExtractor extractor; |
| 252 | + |
| 253 | + @BeforeClass |
| 254 | + public static void setUp() throws Exception { |
| 255 | + YoutubeParsingHelper.resetClientVersionAndKey(); |
| 256 | + YoutubeParsingHelper.setNumberGenerator(new Random(1)); |
| 257 | + NewPipe.init(new DownloaderFactory().getDownloader(RESOURCE_PATH + "likes")); |
| 258 | + extractor = (YoutubeCommentsExtractor) YouTube |
| 259 | + .getCommentsExtractor(url); |
| 260 | + extractor.fetchPage(); |
| 261 | + } |
| 262 | + |
| 263 | + @Test |
| 264 | + public void testGetCommentsFirst() throws IOException, ExtractionException { |
| 265 | + final InfoItemsPage<CommentsInfoItem> comments = extractor.getInitialPage(); |
| 266 | + |
| 267 | + DefaultTests.defaultTestListOfItems(YouTube, comments.getItems(), comments.getErrors()); |
| 268 | + |
| 269 | + CommentsInfoItem pinnedComment = comments.getItems().get(0); |
| 270 | + |
| 271 | + assertTrue("First comment isn't pinned", pinnedComment.isPinned()); |
| 272 | + assertTrue("The first pinned comment has no likes", pinnedComment.getLikeCount() > 0); |
| 273 | + assertTrue("The first pinned comment has no vote count", !Utils.isBlank(pinnedComment.getTextualVoteCount())); |
| 274 | + } |
| 275 | + } |
| 276 | + |
| 277 | + /** |
| 278 | + * Checks if the vote count works localized<br/> |
| 279 | + * A pinned comment with >15K likes is used for the test |
| 280 | + */ |
| 281 | + public static class LocalizedVoteCount { |
| 282 | + private final static String url = "https://www.youtube.com/watch?v=QqsLTNkzvaY"; |
| 283 | + private static YoutubeCommentsExtractor extractor; |
| 284 | + |
| 285 | + @BeforeClass |
| 286 | + public static void setUp() throws Exception { |
| 287 | + YoutubeParsingHelper.resetClientVersionAndKey(); |
| 288 | + YoutubeParsingHelper.setNumberGenerator(new Random(1)); |
| 289 | + NewPipe.init(new DownloaderFactory().getDownloader(RESOURCE_PATH + "localized_vote_count")); |
| 290 | + extractor = (YoutubeCommentsExtractor) YouTube |
| 291 | + .getCommentsExtractor(url); |
| 292 | + // Force non english local here |
| 293 | + extractor.forceLocalization(Localization.fromLocale(Locale.GERMANY)); |
| 294 | + extractor.fetchPage(); |
| 295 | + } |
| 296 | + |
| 297 | + @Test |
| 298 | + public void testGetCommentsFirst() throws IOException, ExtractionException { |
| 299 | + final InfoItemsPage<CommentsInfoItem> comments = extractor.getInitialPage(); |
| 300 | + |
| 301 | + DefaultTests.defaultTestListOfItems(YouTube, comments.getItems(), comments.getErrors()); |
| 302 | + |
| 303 | + CommentsInfoItem pinnedComment = comments.getItems().get(0); |
| 304 | + |
| 305 | + assertTrue("First comment isn't pinned", pinnedComment.isPinned()); |
| 306 | + assertTrue("The first pinned comment has no vote count", !Utils.isBlank(pinnedComment.getTextualVoteCount())); |
| 307 | + } |
| 308 | + } |
246 | 309 | } |
0 commit comments