Skip to content

Commit 10cf081

Browse files
committed
Removed likeCount and added textualVoteCount
1 parent 3a3ade2 commit 10cf081

10 files changed

Lines changed: 44 additions & 36 deletions

File tree

extractor/src/main/java/org/schabi/newpipe/extractor/comments/CommentsInfoItem.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class CommentsInfoItem extends InfoItem {
1616
private String textualUploadDate;
1717
@Nullable
1818
private DateWrapper uploadDate;
19-
private int likeCount;
19+
private String textualVoteCount;
2020
private boolean heartedByUploader;
2121
private boolean pinned;
2222

@@ -81,12 +81,12 @@ public void setUploadDate(@Nullable DateWrapper uploadDate) {
8181
this.uploadDate = uploadDate;
8282
}
8383

84-
public int getLikeCount() {
85-
return likeCount;
84+
public String getTextualVoteCount() {
85+
return textualVoteCount;
8686
}
8787

88-
public void setLikeCount(int likeCount) {
89-
this.likeCount = likeCount;
88+
public void setTextualVoteCount(String textualVoteCount) {
89+
this.textualVoteCount = textualVoteCount;
9090
}
9191

9292
public void setHeartedByUploader(boolean isHeartedByUploader) {

extractor/src/main/java/org/schabi/newpipe/extractor/comments/CommentsInfoItemExtractor.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,19 @@
44
import org.schabi.newpipe.extractor.exceptions.ParsingException;
55
import org.schabi.newpipe.extractor.localization.DateWrapper;
66
import org.schabi.newpipe.extractor.stream.StreamExtractor;
7+
import org.schabi.newpipe.extractor.utils.Utils;
78

89
import javax.annotation.Nullable;
910

1011
public interface CommentsInfoItemExtractor extends InfoItemExtractor {
11-
1212
/**
13-
* Return the like count of the comment, or -1 if it's unavailable
13+
* The formatted text (e.g. 420, 4K, 4.2M) of the votes
1414
*
15-
* @see StreamExtractor#getLikeCount()
15+
* May be language dependent
1616
*/
17-
int getLikeCount() throws ParsingException;
17+
default String getTextualVoteCount() throws ParsingException {
18+
return Utils.EMPTY_STRING;
19+
}
1820

1921
/**
2022
* The text of the comment

extractor/src/main/java/org/schabi/newpipe/extractor/comments/CommentsInfoItemsCollector.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
import java.util.ArrayList;
88
import java.util.List;
9-
import java.util.Vector;
109

1110
public class CommentsInfoItemsCollector extends InfoItemsCollector<CommentsInfoItem, CommentsInfoItemExtractor> {
1211

@@ -61,7 +60,7 @@ public CommentsInfoItem extract(CommentsInfoItemExtractor extractor) throws Pars
6160
addError(e);
6261
}
6362
try {
64-
resultItem.setLikeCount(extractor.getLikeCount());
63+
resultItem.setTextualVoteCount(extractor.getTextualVoteCount());
6564
} catch (Exception e) {
6665
addError(e);
6766
}

extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampCommentsInfoItemExtractor.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import org.schabi.newpipe.extractor.comments.CommentsInfoItemExtractor;
55
import org.schabi.newpipe.extractor.exceptions.ParsingException;
66
import org.schabi.newpipe.extractor.localization.DateWrapper;
7+
import org.schabi.newpipe.extractor.utils.Utils;
78

89
import javax.annotation.Nullable;
910

@@ -32,11 +33,6 @@ public String getThumbnailUrl() throws ParsingException {
3233
return writing.getElementsByClass("thumb").attr("src");
3334
}
3435

35-
@Override
36-
public int getLikeCount() {
37-
return -1;
38-
}
39-
4036
@Override
4137
public String getCommentText() {
4238
return writing.getElementsByClass("text").first().ownText();

extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubeCommentsInfoItemExtractor.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,6 @@ public DateWrapper getUploadDate() throws ParsingException {
5757
return new DateWrapper(PeertubeParsingHelper.parseDateFrom(textualUploadDate));
5858
}
5959

60-
@Override
61-
public int getLikeCount() {
62-
return -1;
63-
}
64-
6560
@Override
6661
public String getCommentText() throws ParsingException {
6762
final String htmlText = JsonUtils.getString(item, "text");

extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudCommentsInfoItemExtractor.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,6 @@ public DateWrapper getUploadDate() throws ParsingException {
6969
return new DateWrapper(SoundcloudParsingHelper.parseDateFrom(getTextualUploadDate()));
7070
}
7171

72-
@Override
73-
public int getLikeCount() {
74-
return -1;
75-
}
76-
7772
@Override
7873
public String getName() throws ParsingException {
7974
return json.getObject("user").getString("permalink");

extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeCommentsInfoItemExtractor.java

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,33 @@ public DateWrapper getUploadDate() throws ParsingException {
7171
}
7272

7373
@Override
74-
public int getLikeCount() throws ParsingException {
74+
public String getTextualVoteCount() throws ParsingException {
75+
/**
76+
* Example results are as of 2021-05-20:
77+
* Language = English
78+
* 3.3M
79+
* 48K
80+
* 1.4K
81+
* 270K
82+
* 19
83+
* 6
84+
*
85+
* Language = German
86+
* 3,3 Mio
87+
* 48.189
88+
* 1419
89+
* 270.984
90+
* 19
91+
* 6
92+
*/
7593
try {
76-
return json.getInt("likeCount");
94+
final JsonObject voteCountObj = JsonUtils.getObject(json, "voteCount");
95+
if(voteCountObj.isEmpty()) {
96+
return EMPTY_STRING;
97+
}
98+
return getTextFromObject(voteCountObj);
7799
} catch (Exception e) {
78-
throw new ParsingException("Could not get like count", e);
100+
throw new ParsingException("Could not get vote count", e);
79101
}
80102
}
81103

extractor/src/test/java/org/schabi/newpipe/extractor/services/bandcamp/BandcampCommentsExtractorTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import static org.junit.Assert.*;
1717
import static org.junit.Assert.assertFalse;
1818
import static org.schabi.newpipe.extractor.ServiceList.Bandcamp;
19-
import static org.schabi.newpipe.extractor.ServiceList.YouTube;
2019

2120
public class BandcampCommentsExtractorTest {
2221

@@ -46,7 +45,7 @@ public void testGetCommentsAllData() throws IOException, ExtractionException {
4645
assertFalse(Utils.isBlank(c.getName()));
4746
assertFalse(Utils.isBlank(c.getThumbnailUrl()));
4847
assertFalse(Utils.isBlank(c.getUrl()));
49-
assertEquals(-1, c.getLikeCount());
48+
assertTrue(Utils.isBlank(c.getTextualVoteCount()));
5049
}
5150
}
5251
}

extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubeCommentsExtractorTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public void testGetCommentsAllData() throws IOException, ExtractionException {
7575
assertFalse(Utils.isBlank(c.getTextualUploadDate()));
7676
assertFalse(Utils.isBlank(c.getThumbnailUrl()));
7777
assertFalse(Utils.isBlank(c.getUrl()));
78-
assertFalse(c.getLikeCount() != -1);
78+
assertTrue(Utils.isBlank(c.getTextualVoteCount()));
7979
}
8080
}
8181

extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeCommentsExtractorTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public void testGetCommentsAllData() throws IOException, ExtractionException {
9898
assertNotNull(c.getUploadDate());
9999
assertFalse(Utils.isBlank(c.getThumbnailUrl()));
100100
assertFalse(Utils.isBlank(c.getUrl()));
101-
assertFalse(c.getLikeCount() < 0);
101+
assertFalse(Utils.isBlank(c.getTextualVoteCount()));
102102
}
103103
}
104104

@@ -148,7 +148,7 @@ public void testGetCommentsAllData() throws IOException, ExtractionException {
148148
assertNotNull(c.getUploadDate());
149149
assertFalse(Utils.isBlank(c.getThumbnailUrl()));
150150
assertFalse(Utils.isBlank(c.getUrl()));
151-
assertFalse(c.getLikeCount() < 0);
151+
assertFalse(Utils.isBlank(c.getTextualVoteCount()));
152152
if (c.getCommentId().equals("Ugga_h1-EXdHB3gCoAEC")) { // comment without text
153153
assertTrue(Utils.isBlank(c.getCommentText()));
154154
} else {
@@ -191,7 +191,7 @@ public void testGetCommentsAllData() throws IOException, ExtractionException {
191191
assertNotNull(c.getUploadDate());
192192
assertFalse(Utils.isBlank(c.getThumbnailUrl()));
193193
assertFalse(Utils.isBlank(c.getUrl()));
194-
assertFalse(c.getLikeCount() < 0);
194+
assertFalse(Utils.isBlank(c.getTextualVoteCount()));
195195
assertFalse(Utils.isBlank(c.getCommentText()));
196196
if (c.isHeartedByUploader()) {
197197
heartedByUploader = true;
@@ -232,7 +232,7 @@ public void testGetCommentsAllData() throws IOException, ExtractionException {
232232
assertNotNull(c.getUploadDate());
233233
assertFalse(Utils.isBlank(c.getThumbnailUrl()));
234234
assertFalse(Utils.isBlank(c.getUrl()));
235-
assertFalse(c.getLikeCount() < 0);
235+
assertFalse(Utils.isBlank(c.getTextualVoteCount()));
236236
assertFalse(Utils.isBlank(c.getCommentText()));
237237
}
238238

0 commit comments

Comments
 (0)