Skip to content

Commit 66e4eb2

Browse files
committed
extract whether the comment is pinned
1 parent 69f155d commit 66e4eb2

7 files changed

Lines changed: 74 additions & 0 deletions

File tree

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public class CommentsInfoItem extends InfoItem {
1717
private DateWrapper uploadDate;
1818
private int likeCount;
1919
private boolean heartedByUploader;
20+
private boolean pinned;
2021

2122
public CommentsInfoItem(int serviceId, String url, String name) {
2223
super(InfoType.COMMENT, serviceId, url, name);
@@ -94,4 +95,12 @@ public void setHeartedByUploader(boolean isHeartedByUploader) {
9495
public boolean getHeartedByUploader() {
9596
return this.heartedByUploader;
9697
}
98+
99+
public boolean getPinned() {
100+
return pinned;
101+
}
102+
103+
public void setPinned(boolean pinned) {
104+
this.pinned = pinned;
105+
}
97106
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ public interface CommentsInfoItemExtractor extends InfoItemExtractor {
1111

1212
/**
1313
* Return the like count of the comment, or -1 if it's unavailable
14+
*
1415
* @see StreamExtractor#getLikeCount()
1516
*/
1617
int getLikeCount() throws ParsingException;
@@ -22,12 +23,14 @@ public interface CommentsInfoItemExtractor extends InfoItemExtractor {
2223

2324
/**
2425
* The upload date given by the service, unmodified
26+
*
2527
* @see StreamExtractor#getTextualUploadDate()
2628
*/
2729
String getTextualUploadDate() throws ParsingException;
2830

2931
/**
3032
* The upload date wrapped with DateWrapper class
33+
*
3134
* @see StreamExtractor#getUploadDate()
3235
*/
3336
@Nullable
@@ -45,4 +48,9 @@ public interface CommentsInfoItemExtractor extends InfoItemExtractor {
4548
* Whether the comment has been hearted by the uploader
4649
*/
4750
boolean getHeartedByUploader() throws ParsingException;
51+
52+
/**
53+
* Whether the comment is pinned
54+
*/
55+
boolean getPinned() throws ParsingException;
4856
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@ public CommentsInfoItem extract(CommentsInfoItemExtractor extractor) throws Pars
7676
addError(e);
7777
}
7878

79+
try {
80+
resultItem.setPinned(extractor.getPinned());
81+
} catch (Exception e) {
82+
addError(e);
83+
}
84+
7985
return resultItem;
8086
}
8187

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ public boolean getHeartedByUploader() throws ParsingException {
9393
return false;
9494
}
9595

96+
@Override
97+
public boolean getPinned() throws ParsingException {
98+
return false;
99+
}
100+
96101
@Override
97102
public String getUploaderName() throws ParsingException {
98103
return JsonUtils.getString(item, "account.name") + "@" + JsonUtils.getString(item, "account.host");

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ public boolean getHeartedByUploader() throws ParsingException {
4444
return false;
4545
}
4646

47+
@Override
48+
public boolean getPinned() throws ParsingException {
49+
return false;
50+
}
51+
4752
@Override
4853
public String getUploaderUrl() {
4954
return json.getObject("user").getString("permalink_url");

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,11 @@ public boolean getHeartedByUploader() throws ParsingException {
120120
return json.has("creatorHeart");
121121
}
122122

123+
@Override
124+
public boolean getPinned() {
125+
return json.has("pinnedCommentBadge");
126+
}
127+
123128
@Override
124129
public String getUploaderName() throws ParsingException {
125130
try {

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,4 +189,40 @@ public void testGetCommentsAllData() throws IOException, ExtractionException {
189189

190190
}
191191
}
192+
193+
public static class Pinned {
194+
private final static String url = "https://www.youtube.com/watch?v=bjFtFMilb34";
195+
private static YoutubeCommentsExtractor extractor;
196+
197+
@BeforeClass
198+
public static void setUp() throws Exception {
199+
NewPipe.init(DownloaderTestImpl.getInstance());
200+
extractor = (YoutubeCommentsExtractor) YouTube
201+
.getCommentsExtractor(url);
202+
extractor.fetchPage();
203+
}
204+
205+
@Test
206+
public void testGetCommentsAllData() throws IOException, ExtractionException {
207+
final InfoItemsPage<CommentsInfoItem> comments = extractor.getInitialPage();
208+
209+
DefaultTests.defaultTestListOfItems(YouTube, comments.getItems(), comments.getErrors());
210+
211+
for (CommentsInfoItem c : comments.getItems()) {
212+
assertFalse(Utils.isBlank(c.getUploaderUrl()));
213+
assertFalse(Utils.isBlank(c.getUploaderName()));
214+
assertFalse(Utils.isBlank(c.getUploaderAvatarUrl()));
215+
assertFalse(Utils.isBlank(c.getCommentId()));
216+
assertFalse(Utils.isBlank(c.getName()));
217+
assertFalse(Utils.isBlank(c.getTextualUploadDate()));
218+
assertNotNull(c.getUploadDate());
219+
assertFalse(Utils.isBlank(c.getThumbnailUrl()));
220+
assertFalse(Utils.isBlank(c.getUrl()));
221+
assertFalse(c.getLikeCount() < 0);
222+
assertFalse(Utils.isBlank(c.getCommentText()));
223+
}
224+
225+
assertTrue("First comment isn't pinned", comments.getItems().get(0).getPinned());
226+
}
227+
}
192228
}

0 commit comments

Comments
 (0)