From 66e4eb2f9644dc41d2a6bdb46045a85cbe85d231 Mon Sep 17 00:00:00 2001 From: bopol Date: Fri, 22 Jan 2021 23:59:22 +0100 Subject: [PATCH] extract whether the comment is pinned --- .../extractor/comments/CommentsInfoItem.java | 9 +++++ .../comments/CommentsInfoItemExtractor.java | 8 +++++ .../comments/CommentsInfoItemsCollector.java | 6 ++++ .../PeertubeCommentsInfoItemExtractor.java | 5 +++ .../SoundcloudCommentsInfoItemExtractor.java | 5 +++ .../YoutubeCommentsInfoItemExtractor.java | 5 +++ .../youtube/YoutubeCommentsExtractorTest.java | 36 +++++++++++++++++++ 7 files changed, 74 insertions(+) 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 06ce84c4..965a5575 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 @@ -17,6 +17,7 @@ public class CommentsInfoItem extends InfoItem { private DateWrapper uploadDate; private int likeCount; private boolean heartedByUploader; + private boolean pinned; public CommentsInfoItem(int serviceId, String url, String name) { super(InfoType.COMMENT, serviceId, url, name); @@ -94,4 +95,12 @@ public class CommentsInfoItem extends InfoItem { public boolean getHeartedByUploader() { return this.heartedByUploader; } + + public boolean getPinned() { + return pinned; + } + + public void setPinned(boolean pinned) { + this.pinned = pinned; + } } 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 ff56204f..ae93ac89 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 @@ -11,6 +11,7 @@ public interface CommentsInfoItemExtractor extends InfoItemExtractor { /** * Return the like count of the comment, or -1 if it's unavailable + * * @see StreamExtractor#getLikeCount() */ int getLikeCount() throws ParsingException; @@ -22,12 +23,14 @@ public interface CommentsInfoItemExtractor extends InfoItemExtractor { /** * The upload date given by the service, unmodified + * * @see StreamExtractor#getTextualUploadDate() */ String getTextualUploadDate() throws ParsingException; /** * The upload date wrapped with DateWrapper class + * * @see StreamExtractor#getUploadDate() */ @Nullable @@ -45,4 +48,9 @@ public interface CommentsInfoItemExtractor extends InfoItemExtractor { * Whether the comment has been hearted by the uploader */ boolean getHeartedByUploader() throws ParsingException; + + /** + * Whether the comment is pinned + */ + boolean getPinned() 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 3323f00b..c84c2fa7 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 @@ -76,6 +76,12 @@ public class CommentsInfoItemsCollector extends InfoItemsCollector comments = extractor.getInitialPage(); + + DefaultTests.defaultTestListOfItems(YouTube, comments.getItems(), comments.getErrors()); + + 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())); + } + + assertTrue("First comment isn't pinned", comments.getItems().get(0).getPinned()); + } + } }