Reimplemented likeCount

This commit is contained in:
litetex 2021-05-21 19:40:51 +02:00
parent 01cfb55505
commit 2174685c5c
4 changed files with 49 additions and 1 deletions

View File

@ -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;
}

View File

@ -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<br/>
* 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<br/>
* May be language dependent
*/
default String getTextualVoteCount() throws ParsingException {

View File

@ -59,6 +59,11 @@ public class CommentsInfoItemsCollector extends InfoItemsCollector<CommentsInfoI
} catch (Exception e) {
addError(e);
}
try {
resultItem.setLikeCount(extractor.getLikeCount());
} catch (Exception e) {
addError(e);
}
try {
resultItem.setTextualVoteCount(extractor.getTextualVoteCount());
} catch (Exception e) {

View File

@ -70,6 +70,29 @@ public class YoutubeCommentsInfoItemExtractor implements CommentsInfoItemExtract
}
}
/**
* @implNote The method is parsing internally a localized string.<br/>
* 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.<br/>
* 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 {
/*