Tweaked code

This commit is contained in:
litetex 2021-05-27 19:48:31 +02:00
parent 8c96545e57
commit e81b0e2885
7 changed files with 24 additions and 21 deletions

View file

@ -17,7 +17,7 @@ public class CommentsInfoItem extends InfoItem {
@Nullable @Nullable
private DateWrapper uploadDate; private DateWrapper uploadDate;
private int likeCount; private int likeCount;
private String textualVoteCount; private String textualLikeCount;
private boolean heartedByUploader; private boolean heartedByUploader;
private boolean pinned; private boolean pinned;
@ -90,12 +90,12 @@ public class CommentsInfoItem extends InfoItem {
this.likeCount = likeCount; this.likeCount = likeCount;
} }
public String getTextualVoteCount() { public String getTextualLikeCount() {
return textualVoteCount; return textualLikeCount;
} }
public void setTextualVoteCount(String textualVoteCount) { public void setTextualLikeCount(String textualLikeCount) {
this.textualVoteCount = textualVoteCount; this.textualLikeCount = textualLikeCount;
} }
public void setHeartedByUploader(boolean isHeartedByUploader) { public void setHeartedByUploader(boolean isHeartedByUploader) {

View file

@ -12,9 +12,10 @@ import javax.annotation.Nullable;
public interface CommentsInfoItemExtractor extends InfoItemExtractor { 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()} * NOTE: Currently only implemented for YT {@link YoutubeCommentsInfoItemExtractor#getLikeCount()}
* with limitations * with limitations (only approximate like count is returned)
* *
* @see StreamExtractor#getLikeCount() * @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/> * The unmodified like count given by the service<br/>
* May be language dependent *
* It may be language dependent
*/ */
default String getTextualVoteCount() throws ParsingException { default String getTextualLikeCount() throws ParsingException {
return Utils.EMPTY_STRING; return Utils.EMPTY_STRING;
} }

View file

@ -65,7 +65,7 @@ public class CommentsInfoItemsCollector extends InfoItemsCollector<CommentsInfoI
addError(e); addError(e);
} }
try { try {
resultItem.setTextualVoteCount(extractor.getTextualVoteCount()); resultItem.setTextualLikeCount(extractor.getTextualLikeCount());
} catch (Exception e) { } catch (Exception e) {
addError(e); addError(e);
} }

View file

@ -85,25 +85,26 @@ public class YoutubeCommentsInfoItemExtractor implements CommentsInfoItemExtract
* </li> * </li>
* </ul> * </ul>
* <br/> * <br/>
* Consider using {@link #getTextualVoteCount()} * Consider using {@link #getTextualLikeCount()}
*/ */
@Override @Override
public int getLikeCount() throws ParsingException { public int getLikeCount() throws ParsingException {
json.getInt("");
// This may return a language dependent version, e.g. in German: 3,3 Mio // This may return a language dependent version, e.g. in German: 3,3 Mio
String voteCount = getTextualVoteCount(); final String textualLikeCount = getTextualLikeCount();
try { try {
if (Utils.isBlank(voteCount)) { if (Utils.isBlank(textualLikeCount)) {
return 0; return 0;
} }
return (int) Utils.mixedNumberWordToLong(voteCount); return (int) Utils.mixedNumberWordToLong(textualLikeCount);
} catch (Exception e) { } 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 @Override
public String getTextualVoteCount() throws ParsingException { public String getTextualLikeCount() throws ParsingException {
/* /*
* Example results as of 2021-05-20: * Example results as of 2021-05-20:
* Language = English * Language = English

View file

@ -47,7 +47,7 @@ public class BandcampCommentsExtractorTest {
assertFalse(Utils.isBlank(c.getThumbnailUrl())); assertFalse(Utils.isBlank(c.getThumbnailUrl()));
assertFalse(Utils.isBlank(c.getUrl())); assertFalse(Utils.isBlank(c.getUrl()));
assertEquals(-1, c.getLikeCount()); assertEquals(-1, c.getLikeCount());
assertTrue(Utils.isBlank(c.getTextualVoteCount())); assertTrue(Utils.isBlank(c.getTextualLikeCount()));
} }
} }
} }

View file

@ -76,7 +76,7 @@ public class PeertubeCommentsExtractorTest {
assertFalse(Utils.isBlank(c.getThumbnailUrl())); assertFalse(Utils.isBlank(c.getThumbnailUrl()));
assertFalse(Utils.isBlank(c.getUrl())); assertFalse(Utils.isBlank(c.getUrl()));
assertEquals(-1, c.getLikeCount()); assertEquals(-1, c.getLikeCount());
assertTrue(Utils.isBlank(c.getTextualVoteCount())); assertTrue(Utils.isBlank(c.getTextualLikeCount()));
} }
} }

View file

@ -270,7 +270,7 @@ public class YoutubeCommentsExtractorTest {
assertTrue("First comment isn't pinned", pinnedComment.isPinned()); 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 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); CommentsInfoItem pinnedComment = comments.getItems().get(0);
assertTrue("First comment isn't pinned", pinnedComment.isPinned()); 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()));
} }
} }
} }