Skip to content

Commit f6d054e

Browse files
committed
Add test for comments.
1 parent ed84658 commit f6d054e

2 files changed

Lines changed: 35 additions & 1 deletion

File tree

extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeCommentsInfoItemExtractor.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,13 @@ public YoutubeCommentsInfoItemExtractor(final JsonObject json,
3333
}
3434

3535
private JsonObject getCommentRenderer() throws ParsingException {
36-
return commentRenderer != null ? commentRenderer : (commentRenderer = JsonUtils.getObject(json, "comment.commentRenderer"));
36+
if(commentRenderer == null) {
37+
if(!json.has("comment"))
38+
commentRenderer = json;
39+
else
40+
commentRenderer = JsonUtils.getObject(json, "comment.commentRenderer");
41+
}
42+
return commentRenderer;
3743
}
3844

3945
@Override

extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeCommentsExtractorTest.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,4 +306,32 @@ public void testGetCommentsFirst() throws IOException, ExtractionException {
306306
assertTrue("The first pinned comment has no vote count", !Utils.isBlank(pinnedComment.getTextualLikeCount()));
307307
}
308308
}
309+
310+
public static class RepliesTest {
311+
private final static String url = "https://www.youtube.com/watch?v=--yeOvJGZQk";
312+
private static YoutubeCommentsExtractor extractor;
313+
314+
@BeforeClass
315+
public static void setUp() throws Exception {
316+
YoutubeParsingHelper.resetClientVersionAndKey();
317+
YoutubeParsingHelper.setNumberGenerator(new Random(1));
318+
NewPipe.init(new DownloaderFactory().getDownloader(RESOURCE_PATH + "likes"));
319+
extractor = (YoutubeCommentsExtractor) YouTube
320+
.getCommentsExtractor(url);
321+
extractor.fetchPage();
322+
}
323+
324+
@Test
325+
public void testGetCommentsFirstReplies() throws IOException, ExtractionException {
326+
final InfoItemsPage<CommentsInfoItem> comments = extractor.getInitialPage();
327+
328+
DefaultTests.defaultTestListOfItems(YouTube, comments.getItems(), comments.getErrors());
329+
330+
CommentsInfoItem pinnedComment = comments.getItems().get(0);
331+
332+
InfoItemsPage<CommentsInfoItem> replies = extractor.getPage(pinnedComment.getReplies());
333+
334+
assertEquals("First reply comment did not match", "Lol", replies.getItems().get(0).getCommentText());
335+
}
336+
}
309337
}

0 commit comments

Comments
 (0)