mirror of
https://github.com/TeamNewPipe/NewPipeExtractor.git
synced 2025-04-28 07:50:34 +05:30
Removed likeCount and added textualVoteCount
This commit is contained in:
parent
3a3ade20f4
commit
10cf081145
@ -16,7 +16,7 @@ public class CommentsInfoItem extends InfoItem {
|
|||||||
private String textualUploadDate;
|
private String textualUploadDate;
|
||||||
@Nullable
|
@Nullable
|
||||||
private DateWrapper uploadDate;
|
private DateWrapper uploadDate;
|
||||||
private int likeCount;
|
private String textualVoteCount;
|
||||||
private boolean heartedByUploader;
|
private boolean heartedByUploader;
|
||||||
private boolean pinned;
|
private boolean pinned;
|
||||||
|
|
||||||
@ -81,12 +81,12 @@ public class CommentsInfoItem extends InfoItem {
|
|||||||
this.uploadDate = uploadDate;
|
this.uploadDate = uploadDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getLikeCount() {
|
public String getTextualVoteCount() {
|
||||||
return likeCount;
|
return textualVoteCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLikeCount(int likeCount) {
|
public void setTextualVoteCount(String textualVoteCount) {
|
||||||
this.likeCount = likeCount;
|
this.textualVoteCount = textualVoteCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setHeartedByUploader(boolean isHeartedByUploader) {
|
public void setHeartedByUploader(boolean isHeartedByUploader) {
|
||||||
|
@ -4,17 +4,19 @@ import org.schabi.newpipe.extractor.InfoItemExtractor;
|
|||||||
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
||||||
import org.schabi.newpipe.extractor.localization.DateWrapper;
|
import org.schabi.newpipe.extractor.localization.DateWrapper;
|
||||||
import org.schabi.newpipe.extractor.stream.StreamExtractor;
|
import org.schabi.newpipe.extractor.stream.StreamExtractor;
|
||||||
|
import org.schabi.newpipe.extractor.utils.Utils;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
public interface CommentsInfoItemExtractor extends InfoItemExtractor {
|
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
|
* The text of the comment
|
||||||
|
@ -6,7 +6,6 @@ import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Vector;
|
|
||||||
|
|
||||||
public class CommentsInfoItemsCollector extends InfoItemsCollector<CommentsInfoItem, CommentsInfoItemExtractor> {
|
public class CommentsInfoItemsCollector extends InfoItemsCollector<CommentsInfoItem, CommentsInfoItemExtractor> {
|
||||||
|
|
||||||
@ -61,7 +60,7 @@ public class CommentsInfoItemsCollector extends InfoItemsCollector<CommentsInfoI
|
|||||||
addError(e);
|
addError(e);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
resultItem.setLikeCount(extractor.getLikeCount());
|
resultItem.setTextualVoteCount(extractor.getTextualVoteCount());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
addError(e);
|
addError(e);
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import org.jsoup.nodes.Element;
|
|||||||
import org.schabi.newpipe.extractor.comments.CommentsInfoItemExtractor;
|
import org.schabi.newpipe.extractor.comments.CommentsInfoItemExtractor;
|
||||||
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
||||||
import org.schabi.newpipe.extractor.localization.DateWrapper;
|
import org.schabi.newpipe.extractor.localization.DateWrapper;
|
||||||
|
import org.schabi.newpipe.extractor.utils.Utils;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
@ -32,11 +33,6 @@ public class BandcampCommentsInfoItemExtractor implements CommentsInfoItemExtrac
|
|||||||
return writing.getElementsByClass("thumb").attr("src");
|
return writing.getElementsByClass("thumb").attr("src");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getLikeCount() {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getCommentText() {
|
public String getCommentText() {
|
||||||
return writing.getElementsByClass("text").first().ownText();
|
return writing.getElementsByClass("text").first().ownText();
|
||||||
|
@ -57,11 +57,6 @@ public class PeertubeCommentsInfoItemExtractor implements CommentsInfoItemExtrac
|
|||||||
return new DateWrapper(PeertubeParsingHelper.parseDateFrom(textualUploadDate));
|
return new DateWrapper(PeertubeParsingHelper.parseDateFrom(textualUploadDate));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getLikeCount() {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getCommentText() throws ParsingException {
|
public String getCommentText() throws ParsingException {
|
||||||
final String htmlText = JsonUtils.getString(item, "text");
|
final String htmlText = JsonUtils.getString(item, "text");
|
||||||
|
@ -69,11 +69,6 @@ public class SoundcloudCommentsInfoItemExtractor implements CommentsInfoItemExtr
|
|||||||
return new DateWrapper(SoundcloudParsingHelper.parseDateFrom(getTextualUploadDate()));
|
return new DateWrapper(SoundcloudParsingHelper.parseDateFrom(getTextualUploadDate()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getLikeCount() {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() throws ParsingException {
|
public String getName() throws ParsingException {
|
||||||
return json.getObject("user").getString("permalink");
|
return json.getObject("user").getString("permalink");
|
||||||
|
@ -71,11 +71,33 @@ public class YoutubeCommentsInfoItemExtractor implements CommentsInfoItemExtract
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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 {
|
try {
|
||||||
return json.getInt("likeCount");
|
final JsonObject voteCountObj = JsonUtils.getObject(json, "voteCount");
|
||||||
|
if(voteCountObj.isEmpty()) {
|
||||||
|
return EMPTY_STRING;
|
||||||
|
}
|
||||||
|
return getTextFromObject(voteCountObj);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new ParsingException("Could not get like count", e);
|
throw new ParsingException("Could not get vote count", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,7 +16,6 @@ import java.io.IOException;
|
|||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.schabi.newpipe.extractor.ServiceList.Bandcamp;
|
import static org.schabi.newpipe.extractor.ServiceList.Bandcamp;
|
||||||
import static org.schabi.newpipe.extractor.ServiceList.YouTube;
|
|
||||||
|
|
||||||
public class BandcampCommentsExtractorTest {
|
public class BandcampCommentsExtractorTest {
|
||||||
|
|
||||||
@ -46,7 +45,7 @@ public class BandcampCommentsExtractorTest {
|
|||||||
assertFalse(Utils.isBlank(c.getName()));
|
assertFalse(Utils.isBlank(c.getName()));
|
||||||
assertFalse(Utils.isBlank(c.getThumbnailUrl()));
|
assertFalse(Utils.isBlank(c.getThumbnailUrl()));
|
||||||
assertFalse(Utils.isBlank(c.getUrl()));
|
assertFalse(Utils.isBlank(c.getUrl()));
|
||||||
assertEquals(-1, c.getLikeCount());
|
assertTrue(Utils.isBlank(c.getTextualVoteCount()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -75,7 +75,7 @@ public class PeertubeCommentsExtractorTest {
|
|||||||
assertFalse(Utils.isBlank(c.getTextualUploadDate()));
|
assertFalse(Utils.isBlank(c.getTextualUploadDate()));
|
||||||
assertFalse(Utils.isBlank(c.getThumbnailUrl()));
|
assertFalse(Utils.isBlank(c.getThumbnailUrl()));
|
||||||
assertFalse(Utils.isBlank(c.getUrl()));
|
assertFalse(Utils.isBlank(c.getUrl()));
|
||||||
assertFalse(c.getLikeCount() != -1);
|
assertTrue(Utils.isBlank(c.getTextualVoteCount()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,7 +98,7 @@ public class YoutubeCommentsExtractorTest {
|
|||||||
assertNotNull(c.getUploadDate());
|
assertNotNull(c.getUploadDate());
|
||||||
assertFalse(Utils.isBlank(c.getThumbnailUrl()));
|
assertFalse(Utils.isBlank(c.getThumbnailUrl()));
|
||||||
assertFalse(Utils.isBlank(c.getUrl()));
|
assertFalse(Utils.isBlank(c.getUrl()));
|
||||||
assertFalse(c.getLikeCount() < 0);
|
assertFalse(Utils.isBlank(c.getTextualVoteCount()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -148,7 +148,7 @@ public class YoutubeCommentsExtractorTest {
|
|||||||
assertNotNull(c.getUploadDate());
|
assertNotNull(c.getUploadDate());
|
||||||
assertFalse(Utils.isBlank(c.getThumbnailUrl()));
|
assertFalse(Utils.isBlank(c.getThumbnailUrl()));
|
||||||
assertFalse(Utils.isBlank(c.getUrl()));
|
assertFalse(Utils.isBlank(c.getUrl()));
|
||||||
assertFalse(c.getLikeCount() < 0);
|
assertFalse(Utils.isBlank(c.getTextualVoteCount()));
|
||||||
if (c.getCommentId().equals("Ugga_h1-EXdHB3gCoAEC")) { // comment without text
|
if (c.getCommentId().equals("Ugga_h1-EXdHB3gCoAEC")) { // comment without text
|
||||||
assertTrue(Utils.isBlank(c.getCommentText()));
|
assertTrue(Utils.isBlank(c.getCommentText()));
|
||||||
} else {
|
} else {
|
||||||
@ -191,7 +191,7 @@ public class YoutubeCommentsExtractorTest {
|
|||||||
assertNotNull(c.getUploadDate());
|
assertNotNull(c.getUploadDate());
|
||||||
assertFalse(Utils.isBlank(c.getThumbnailUrl()));
|
assertFalse(Utils.isBlank(c.getThumbnailUrl()));
|
||||||
assertFalse(Utils.isBlank(c.getUrl()));
|
assertFalse(Utils.isBlank(c.getUrl()));
|
||||||
assertFalse(c.getLikeCount() < 0);
|
assertFalse(Utils.isBlank(c.getTextualVoteCount()));
|
||||||
assertFalse(Utils.isBlank(c.getCommentText()));
|
assertFalse(Utils.isBlank(c.getCommentText()));
|
||||||
if (c.isHeartedByUploader()) {
|
if (c.isHeartedByUploader()) {
|
||||||
heartedByUploader = true;
|
heartedByUploader = true;
|
||||||
@ -232,7 +232,7 @@ public class YoutubeCommentsExtractorTest {
|
|||||||
assertNotNull(c.getUploadDate());
|
assertNotNull(c.getUploadDate());
|
||||||
assertFalse(Utils.isBlank(c.getThumbnailUrl()));
|
assertFalse(Utils.isBlank(c.getThumbnailUrl()));
|
||||||
assertFalse(Utils.isBlank(c.getUrl()));
|
assertFalse(Utils.isBlank(c.getUrl()));
|
||||||
assertFalse(c.getLikeCount() < 0);
|
assertFalse(Utils.isBlank(c.getTextualVoteCount()));
|
||||||
assertFalse(Utils.isBlank(c.getCommentText()));
|
assertFalse(Utils.isBlank(c.getCommentText()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user