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 0d7c7e12c..fd66b0053 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 { private String textualUploadDate; @Nullable private DateWrapper uploadDate; + private int likeCount; private String textualVoteCount; private boolean heartedByUploader; private boolean pinned; @@ -81,6 +82,14 @@ public class CommentsInfoItem extends InfoItem { this.uploadDate = uploadDate; } + public int getLikeCount() { + return likeCount; + } + + public void setLikeCount(int likeCount) { + this.likeCount = likeCount; + } + public String getTextualVoteCount() { return textualVoteCount; } 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 db5ce2c70..31e6736b6 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 @@ -3,6 +3,7 @@ package org.schabi.newpipe.extractor.comments; import org.schabi.newpipe.extractor.InfoItemExtractor; import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.localization.DateWrapper; +import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeCommentsInfoItemExtractor; import org.schabi.newpipe.extractor.stream.StreamExtractor; import org.schabi.newpipe.extractor.utils.Utils; @@ -11,8 +12,18 @@ import javax.annotation.Nullable; public interface CommentsInfoItemExtractor extends InfoItemExtractor { /** - * The formatted text (e.g. 420, 4K, 4.2M) of the votes + * Return the like count of the comment, or -1 if it's unavailable
+ * NOTE: Currently only implemented for YT {@link YoutubeCommentsInfoItemExtractor#getLikeCount()} + * with limitations * + * @see StreamExtractor#getLikeCount() + */ + default int getLikeCount() throws ParsingException { + return -1; + } + + /** + * The formatted text (e.g. 420, 4K, 4.2M) of the votes
* May be language dependent */ default String getTextualVoteCount() 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 9ba03921c..d87ea0a11 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 @@ -59,6 +59,11 @@ public class CommentsInfoItemsCollector extends InfoItemsCollector + * This will fail for other languages than English. + * However as long as the Extractor only uses "en-GB" + * (as seen in {@link org.schabi.newpipe.extractor.services.youtube.YoutubeService#SUPPORTED_LANGUAGES}) + * everything will work fine.
+ * Consider using {@link #getTextualVoteCount()} + */ + @Override + public int getLikeCount() throws ParsingException { + // This may return a language dependent version, e.g. in German: 3,3 Mio + String voteCount = getTextualVoteCount(); + try { + if (Utils.isBlank(voteCount)) { + return 0; + } + + return (int) Utils.mixedNumberWordToLong(voteCount); + } catch (Exception e) { + throw new ParsingException("Unexpected error while converting vote count", e); + } + } + @Override public String getTextualVoteCount() throws ParsingException { /*