Tweaked code
This commit is contained in:
parent
8c96545e57
commit
e81b0e2885
|
@ -17,7 +17,7 @@ public class CommentsInfoItem extends InfoItem {
|
|||
@Nullable
|
||||
private DateWrapper uploadDate;
|
||||
private int likeCount;
|
||||
private String textualVoteCount;
|
||||
private String textualLikeCount;
|
||||
private boolean heartedByUploader;
|
||||
private boolean pinned;
|
||||
|
||||
|
@ -90,12 +90,12 @@ public class CommentsInfoItem extends InfoItem {
|
|||
this.likeCount = likeCount;
|
||||
}
|
||||
|
||||
public String getTextualVoteCount() {
|
||||
return textualVoteCount;
|
||||
public String getTextualLikeCount() {
|
||||
return textualLikeCount;
|
||||
}
|
||||
|
||||
public void setTextualVoteCount(String textualVoteCount) {
|
||||
this.textualVoteCount = textualVoteCount;
|
||||
public void setTextualLikeCount(String textualLikeCount) {
|
||||
this.textualLikeCount = textualLikeCount;
|
||||
}
|
||||
|
||||
public void setHeartedByUploader(boolean isHeartedByUploader) {
|
||||
|
|
|
@ -12,9 +12,10 @@ import javax.annotation.Nullable;
|
|||
public interface CommentsInfoItemExtractor extends InfoItemExtractor {
|
||||
|
||||
/**
|
||||
* Return the (approximate) like count of the comment, or -1 if it's unavailable<br/>
|
||||
* 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
|
||||
* with limitations (only approximate like count is returned)
|
||||
*
|
||||
* @see StreamExtractor#getLikeCount()
|
||||
*/
|
||||
|
@ -23,10 +24,11 @@ public interface CommentsInfoItemExtractor extends InfoItemExtractor {
|
|||
}
|
||||
|
||||
/**
|
||||
* The formatted text (e.g. 420, 4K, 4.2M) of the votes<br/>
|
||||
* May be language dependent
|
||||
* The unmodified like count given by the service<br/>
|
||||
*
|
||||
* It may be language dependent
|
||||
*/
|
||||
default String getTextualVoteCount() throws ParsingException {
|
||||
default String getTextualLikeCount() throws ParsingException {
|
||||
return Utils.EMPTY_STRING;
|
||||
}
|
||||
|
||||
|
|
|
@ -65,7 +65,7 @@ public class CommentsInfoItemsCollector extends InfoItemsCollector<CommentsInfoI
|
|||
addError(e);
|
||||
}
|
||||
try {
|
||||
resultItem.setTextualVoteCount(extractor.getTextualVoteCount());
|
||||
resultItem.setTextualLikeCount(extractor.getTextualLikeCount());
|
||||
} catch (Exception e) {
|
||||
addError(e);
|
||||
}
|
||||
|
|
|
@ -85,25 +85,26 @@ public class YoutubeCommentsInfoItemExtractor implements CommentsInfoItemExtract
|
|||
* </li>
|
||||
* </ul>
|
||||
* <br/>
|
||||
* Consider using {@link #getTextualVoteCount()}
|
||||
* Consider using {@link #getTextualLikeCount()}
|
||||
*/
|
||||
@Override
|
||||
public int getLikeCount() throws ParsingException {
|
||||
json.getInt("");
|
||||
// This may return a language dependent version, e.g. in German: 3,3 Mio
|
||||
String voteCount = getTextualVoteCount();
|
||||
final String textualLikeCount = getTextualLikeCount();
|
||||
try {
|
||||
if (Utils.isBlank(voteCount)) {
|
||||
if (Utils.isBlank(textualLikeCount)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (int) Utils.mixedNumberWordToLong(voteCount);
|
||||
return (int) Utils.mixedNumberWordToLong(textualLikeCount);
|
||||
} catch (Exception e) {
|
||||
throw new ParsingException("Unexpected error while converting vote count to like count", e);
|
||||
throw new ParsingException("Unexpected error while converting textual like count to like count", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTextualVoteCount() throws ParsingException {
|
||||
public String getTextualLikeCount() throws ParsingException {
|
||||
/*
|
||||
* Example results as of 2021-05-20:
|
||||
* Language = English
|
||||
|
|
|
@ -47,7 +47,7 @@ public class BandcampCommentsExtractorTest {
|
|||
assertFalse(Utils.isBlank(c.getThumbnailUrl()));
|
||||
assertFalse(Utils.isBlank(c.getUrl()));
|
||||
assertEquals(-1, c.getLikeCount());
|
||||
assertTrue(Utils.isBlank(c.getTextualVoteCount()));
|
||||
assertTrue(Utils.isBlank(c.getTextualLikeCount()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -76,7 +76,7 @@ public class PeertubeCommentsExtractorTest {
|
|||
assertFalse(Utils.isBlank(c.getThumbnailUrl()));
|
||||
assertFalse(Utils.isBlank(c.getUrl()));
|
||||
assertEquals(-1, c.getLikeCount());
|
||||
assertTrue(Utils.isBlank(c.getTextualVoteCount()));
|
||||
assertTrue(Utils.isBlank(c.getTextualLikeCount()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -270,7 +270,7 @@ public class YoutubeCommentsExtractorTest {
|
|||
|
||||
assertTrue("First comment isn't pinned", pinnedComment.isPinned());
|
||||
assertTrue("The first pinned comment has no likes", pinnedComment.getLikeCount() > 0);
|
||||
assertTrue("The first pinned comment has no vote count", !Utils.isBlank(pinnedComment.getTextualVoteCount()));
|
||||
assertTrue("The first pinned comment has no vote count", !Utils.isBlank(pinnedComment.getTextualLikeCount()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -303,7 +303,7 @@ public class YoutubeCommentsExtractorTest {
|
|||
CommentsInfoItem pinnedComment = comments.getItems().get(0);
|
||||
|
||||
assertTrue("First comment isn't pinned", pinnedComment.isPinned());
|
||||
assertTrue("The first pinned comment has no vote count", !Utils.isBlank(pinnedComment.getTextualVoteCount()));
|
||||
assertTrue("The first pinned comment has no vote count", !Utils.isBlank(pinnedComment.getTextualLikeCount()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue