Add test for comments.

This commit is contained in:
FireMasterK 2021-08-04 21:03:00 +05:30
parent ed84658055
commit f6d054e5da
No known key found for this signature in database
GPG Key ID: 49451E4482CC5BCD
2 changed files with 35 additions and 1 deletions

View File

@ -33,7 +33,13 @@ public class YoutubeCommentsInfoItemExtractor implements CommentsInfoItemExtract
}
private JsonObject getCommentRenderer() throws ParsingException {
return commentRenderer != null ? commentRenderer : (commentRenderer = JsonUtils.getObject(json, "comment.commentRenderer"));
if(commentRenderer == null) {
if(!json.has("comment"))
commentRenderer = json;
else
commentRenderer = JsonUtils.getObject(json, "comment.commentRenderer");
}
return commentRenderer;
}
@Override

View File

@ -306,4 +306,32 @@ public class YoutubeCommentsExtractorTest {
assertTrue("The first pinned comment has no vote count", !Utils.isBlank(pinnedComment.getTextualLikeCount()));
}
}
public static class RepliesTest {
private final static String url = "https://www.youtube.com/watch?v=--yeOvJGZQk";
private static YoutubeCommentsExtractor extractor;
@BeforeClass
public static void setUp() throws Exception {
YoutubeParsingHelper.resetClientVersionAndKey();
YoutubeParsingHelper.setNumberGenerator(new Random(1));
NewPipe.init(new DownloaderFactory().getDownloader(RESOURCE_PATH + "likes"));
extractor = (YoutubeCommentsExtractor) YouTube
.getCommentsExtractor(url);
extractor.fetchPage();
}
@Test
public void testGetCommentsFirstReplies() throws IOException, ExtractionException {
final InfoItemsPage<CommentsInfoItem> comments = extractor.getInitialPage();
DefaultTests.defaultTestListOfItems(YouTube, comments.getItems(), comments.getErrors());
CommentsInfoItem pinnedComment = comments.getItems().get(0);
InfoItemsPage<CommentsInfoItem> replies = extractor.getPage(pinnedComment.getReplies());
assertEquals("First reply comment did not match", "Lol", replies.getItems().get(0).getCommentText());
}
}
}