Removed likeCount and added textualVoteCount

This commit is contained in:
litetex 2021-05-20 20:10:14 +02:00
parent 3a3ade20f4
commit 10cf081145
No known key found for this signature in database
GPG Key ID: 4E362E77AA7E82DF
10 changed files with 44 additions and 36 deletions

View File

@ -16,7 +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,12 +81,12 @@ public class CommentsInfoItem extends InfoItem {
this.uploadDate = uploadDate;
}
public int getLikeCount() {
return likeCount;
public String getTextualVoteCount() {
return textualVoteCount;
}
public void setLikeCount(int likeCount) {
this.likeCount = likeCount;
public void setTextualVoteCount(String textualVoteCount) {
this.textualVoteCount = textualVoteCount;
}
public void setHeartedByUploader(boolean isHeartedByUploader) {

View File

@ -4,17 +4,19 @@ 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.stream.StreamExtractor;
import org.schabi.newpipe.extractor.utils.Utils;
import javax.annotation.Nullable;
public interface CommentsInfoItemExtractor extends InfoItemExtractor {
/**
* Return the like count of the comment, or -1 if it's unavailable
* The formatted text (e.g. 420, 4K, 4.2M) of the votes
*
* @see StreamExtractor#getLikeCount()
* May be language dependent
*/
int getLikeCount() throws ParsingException;
default String getTextualVoteCount() throws ParsingException {
return Utils.EMPTY_STRING;
}
/**
* The text of the comment

View File

@ -6,7 +6,6 @@ import org.schabi.newpipe.extractor.exceptions.ParsingException;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;
public class CommentsInfoItemsCollector extends InfoItemsCollector<CommentsInfoItem, CommentsInfoItemExtractor> {
@ -61,7 +60,7 @@ public class CommentsInfoItemsCollector extends InfoItemsCollector<CommentsInfoI
addError(e);
}
try {
resultItem.setLikeCount(extractor.getLikeCount());
resultItem.setTextualVoteCount(extractor.getTextualVoteCount());
} catch (Exception e) {
addError(e);
}

View File

@ -4,6 +4,7 @@ import org.jsoup.nodes.Element;
import org.schabi.newpipe.extractor.comments.CommentsInfoItemExtractor;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.localization.DateWrapper;
import org.schabi.newpipe.extractor.utils.Utils;
import javax.annotation.Nullable;
@ -32,11 +33,6 @@ public class BandcampCommentsInfoItemExtractor implements CommentsInfoItemExtrac
return writing.getElementsByClass("thumb").attr("src");
}
@Override
public int getLikeCount() {
return -1;
}
@Override
public String getCommentText() {
return writing.getElementsByClass("text").first().ownText();

View File

@ -57,11 +57,6 @@ public class PeertubeCommentsInfoItemExtractor implements CommentsInfoItemExtrac
return new DateWrapper(PeertubeParsingHelper.parseDateFrom(textualUploadDate));
}
@Override
public int getLikeCount() {
return -1;
}
@Override
public String getCommentText() throws ParsingException {
final String htmlText = JsonUtils.getString(item, "text");

View File

@ -69,11 +69,6 @@ public class SoundcloudCommentsInfoItemExtractor implements CommentsInfoItemExtr
return new DateWrapper(SoundcloudParsingHelper.parseDateFrom(getTextualUploadDate()));
}
@Override
public int getLikeCount() {
return -1;
}
@Override
public String getName() throws ParsingException {
return json.getObject("user").getString("permalink");

View File

@ -71,11 +71,33 @@ public class YoutubeCommentsInfoItemExtractor implements CommentsInfoItemExtract
}
@Override
public int getLikeCount() throws ParsingException {
public String getTextualVoteCount() throws ParsingException {
/**
* Example results are as of 2021-05-20:
* Language = English
* 3.3M
* 48K
* 1.4K
* 270K
* 19
* 6
*
* Language = German
* 3,3 Mio
* 48.189
* 1419
* 270.984
* 19
* 6
*/
try {
return json.getInt("likeCount");
final JsonObject voteCountObj = JsonUtils.getObject(json, "voteCount");
if(voteCountObj.isEmpty()) {
return EMPTY_STRING;
}
return getTextFromObject(voteCountObj);
} catch (Exception e) {
throw new ParsingException("Could not get like count", e);
throw new ParsingException("Could not get vote count", e);
}
}

View File

@ -16,7 +16,6 @@ import java.io.IOException;
import static org.junit.Assert.*;
import static org.junit.Assert.assertFalse;
import static org.schabi.newpipe.extractor.ServiceList.Bandcamp;
import static org.schabi.newpipe.extractor.ServiceList.YouTube;
public class BandcampCommentsExtractorTest {
@ -46,7 +45,7 @@ public class BandcampCommentsExtractorTest {
assertFalse(Utils.isBlank(c.getName()));
assertFalse(Utils.isBlank(c.getThumbnailUrl()));
assertFalse(Utils.isBlank(c.getUrl()));
assertEquals(-1, c.getLikeCount());
assertTrue(Utils.isBlank(c.getTextualVoteCount()));
}
}
}

View File

@ -75,7 +75,7 @@ public class PeertubeCommentsExtractorTest {
assertFalse(Utils.isBlank(c.getTextualUploadDate()));
assertFalse(Utils.isBlank(c.getThumbnailUrl()));
assertFalse(Utils.isBlank(c.getUrl()));
assertFalse(c.getLikeCount() != -1);
assertTrue(Utils.isBlank(c.getTextualVoteCount()));
}
}

View File

@ -98,7 +98,7 @@ public class YoutubeCommentsExtractorTest {
assertNotNull(c.getUploadDate());
assertFalse(Utils.isBlank(c.getThumbnailUrl()));
assertFalse(Utils.isBlank(c.getUrl()));
assertFalse(c.getLikeCount() < 0);
assertFalse(Utils.isBlank(c.getTextualVoteCount()));
}
}
@ -148,7 +148,7 @@ public class YoutubeCommentsExtractorTest {
assertNotNull(c.getUploadDate());
assertFalse(Utils.isBlank(c.getThumbnailUrl()));
assertFalse(Utils.isBlank(c.getUrl()));
assertFalse(c.getLikeCount() < 0);
assertFalse(Utils.isBlank(c.getTextualVoteCount()));
if (c.getCommentId().equals("Ugga_h1-EXdHB3gCoAEC")) { // comment without text
assertTrue(Utils.isBlank(c.getCommentText()));
} else {
@ -191,7 +191,7 @@ public class YoutubeCommentsExtractorTest {
assertNotNull(c.getUploadDate());
assertFalse(Utils.isBlank(c.getThumbnailUrl()));
assertFalse(Utils.isBlank(c.getUrl()));
assertFalse(c.getLikeCount() < 0);
assertFalse(Utils.isBlank(c.getTextualVoteCount()));
assertFalse(Utils.isBlank(c.getCommentText()));
if (c.isHeartedByUploader()) {
heartedByUploader = true;
@ -232,7 +232,7 @@ public class YoutubeCommentsExtractorTest {
assertNotNull(c.getUploadDate());
assertFalse(Utils.isBlank(c.getThumbnailUrl()));
assertFalse(Utils.isBlank(c.getUrl()));
assertFalse(c.getLikeCount() < 0);
assertFalse(Utils.isBlank(c.getTextualVoteCount()));
assertFalse(Utils.isBlank(c.getCommentText()));
}