From f3c22da618289eea560136a0a87b79a8ba79c760 Mon Sep 17 00:00:00 2001 From: bopol Date: Mon, 11 Jan 2021 18:38:54 +0100 Subject: [PATCH] comments: add heartedByCreator and extract it for youtube --- .../extractor/comments/CommentsInfoItem.java | 9 ++++ .../comments/CommentsInfoItemExtractor.java | 5 ++ .../comments/CommentsInfoItemsCollector.java | 6 +++ .../PeertubeCommentsInfoItemExtractor.java | 5 ++ .../SoundcloudCommentsInfoItemExtractor.java | 5 ++ .../YoutubeCommentsInfoItemExtractor.java | 5 ++ .../youtube/YoutubeCommentsExtractorTest.java | 51 ++++++++++++++++--- 7 files changed, 79 insertions(+), 7 deletions(-) diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/comments/CommentsInfoItem.java b/extractor/src/main/java/org/schabi/newpipe/extractor/comments/CommentsInfoItem.java index e8871118a..06ce84c44 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/comments/CommentsInfoItem.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/comments/CommentsInfoItem.java @@ -16,6 +16,7 @@ public class CommentsInfoItem extends InfoItem { @Nullable private DateWrapper uploadDate; private int likeCount; + private boolean heartedByUploader; public CommentsInfoItem(int serviceId, String url, String name) { super(InfoType.COMMENT, serviceId, url, name); @@ -85,4 +86,12 @@ public class CommentsInfoItem extends InfoItem { public void setLikeCount(int likeCount) { this.likeCount = likeCount; } + + public void setHeartedByUploader(boolean isHeartedByUploader) { + this.heartedByUploader = isHeartedByUploader; + } + + public boolean getHeartedByUploader() { + return this.heartedByUploader; + } } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/comments/CommentsInfoItemExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/comments/CommentsInfoItemExtractor.java index cf1501a22..ff56204f2 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/comments/CommentsInfoItemExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/comments/CommentsInfoItemExtractor.java @@ -40,4 +40,9 @@ public interface CommentsInfoItemExtractor extends InfoItemExtractor { String getUploaderName() throws ParsingException; String getUploaderAvatarUrl() throws ParsingException; + + /** + * Whether the comment has been hearted by the uploader + */ + boolean getHeartedByUploader() throws ParsingException; } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/comments/CommentsInfoItemsCollector.java b/extractor/src/main/java/org/schabi/newpipe/extractor/comments/CommentsInfoItemsCollector.java index 126d7b183..3323f00b8 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/comments/CommentsInfoItemsCollector.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/comments/CommentsInfoItemsCollector.java @@ -70,6 +70,12 @@ public class CommentsInfoItemsCollector extends InfoItemsCollector comments = extractor.getInitialPage(); + + DefaultTests.defaultTestListOfItems(YouTube, comments.getItems(), comments.getErrors()); + + boolean heartedByUploader = false; + + for (CommentsInfoItem c : comments.getItems()) { + assertFalse(Utils.isBlank(c.getUploaderUrl())); + assertFalse(Utils.isBlank(c.getUploaderName())); + assertFalse(Utils.isBlank(c.getUploaderAvatarUrl())); + assertFalse(Utils.isBlank(c.getCommentId())); + assertFalse(Utils.isBlank(c.getName())); + assertFalse(Utils.isBlank(c.getTextualUploadDate())); + assertNotNull(c.getUploadDate()); + assertFalse(Utils.isBlank(c.getThumbnailUrl())); + assertFalse(Utils.isBlank(c.getUrl())); + assertFalse(c.getLikeCount() < 0); + assertFalse(Utils.isBlank(c.getCommentText())); + if (c.getHeartedByUploader()) { + heartedByUploader = true; + } + } + assertTrue("No comments was hearted by uploader", heartedByUploader); + + } + } }