mirror of
https://github.com/TeamNewPipe/NewPipeExtractor.git
synced 2024-12-13 22:00:32 +05:30
extract whether the comment is pinned
This commit is contained in:
parent
69f155d292
commit
66e4eb2f96
@ -17,6 +17,7 @@ public class CommentsInfoItem extends InfoItem {
|
||||
private DateWrapper uploadDate;
|
||||
private int likeCount;
|
||||
private boolean heartedByUploader;
|
||||
private boolean pinned;
|
||||
|
||||
public CommentsInfoItem(int serviceId, String url, String name) {
|
||||
super(InfoType.COMMENT, serviceId, url, name);
|
||||
@ -94,4 +95,12 @@ public class CommentsInfoItem extends InfoItem {
|
||||
public boolean getHeartedByUploader() {
|
||||
return this.heartedByUploader;
|
||||
}
|
||||
|
||||
public boolean getPinned() {
|
||||
return pinned;
|
||||
}
|
||||
|
||||
public void setPinned(boolean pinned) {
|
||||
this.pinned = pinned;
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ public interface CommentsInfoItemExtractor extends InfoItemExtractor {
|
||||
|
||||
/**
|
||||
* Return the like count of the comment, or -1 if it's unavailable
|
||||
*
|
||||
* @see StreamExtractor#getLikeCount()
|
||||
*/
|
||||
int getLikeCount() throws ParsingException;
|
||||
@ -22,12 +23,14 @@ public interface CommentsInfoItemExtractor extends InfoItemExtractor {
|
||||
|
||||
/**
|
||||
* The upload date given by the service, unmodified
|
||||
*
|
||||
* @see StreamExtractor#getTextualUploadDate()
|
||||
*/
|
||||
String getTextualUploadDate() throws ParsingException;
|
||||
|
||||
/**
|
||||
* The upload date wrapped with DateWrapper class
|
||||
*
|
||||
* @see StreamExtractor#getUploadDate()
|
||||
*/
|
||||
@Nullable
|
||||
@ -45,4 +48,9 @@ public interface CommentsInfoItemExtractor extends InfoItemExtractor {
|
||||
* Whether the comment has been hearted by the uploader
|
||||
*/
|
||||
boolean getHeartedByUploader() throws ParsingException;
|
||||
|
||||
/**
|
||||
* Whether the comment is pinned
|
||||
*/
|
||||
boolean getPinned() throws ParsingException;
|
||||
}
|
||||
|
@ -76,6 +76,12 @@ public class CommentsInfoItemsCollector extends InfoItemsCollector<CommentsInfoI
|
||||
addError(e);
|
||||
}
|
||||
|
||||
try {
|
||||
resultItem.setPinned(extractor.getPinned());
|
||||
} catch (Exception e) {
|
||||
addError(e);
|
||||
}
|
||||
|
||||
return resultItem;
|
||||
}
|
||||
|
||||
|
@ -93,6 +93,11 @@ public class PeertubeCommentsInfoItemExtractor implements CommentsInfoItemExtrac
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getPinned() throws ParsingException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUploaderName() throws ParsingException {
|
||||
return JsonUtils.getString(item, "account.name") + "@" + JsonUtils.getString(item, "account.host");
|
||||
|
@ -44,6 +44,11 @@ public class SoundcloudCommentsInfoItemExtractor implements CommentsInfoItemExtr
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getPinned() throws ParsingException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUploaderUrl() {
|
||||
return json.getObject("user").getString("permalink_url");
|
||||
|
@ -120,6 +120,11 @@ public class YoutubeCommentsInfoItemExtractor implements CommentsInfoItemExtract
|
||||
return json.has("creatorHeart");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getPinned() {
|
||||
return json.has("pinnedCommentBadge");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUploaderName() throws ParsingException {
|
||||
try {
|
||||
|
@ -189,4 +189,40 @@ public class YoutubeCommentsExtractorTest {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static class Pinned {
|
||||
private final static String url = "https://www.youtube.com/watch?v=bjFtFMilb34";
|
||||
private static YoutubeCommentsExtractor extractor;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUp() throws Exception {
|
||||
NewPipe.init(DownloaderTestImpl.getInstance());
|
||||
extractor = (YoutubeCommentsExtractor) YouTube
|
||||
.getCommentsExtractor(url);
|
||||
extractor.fetchPage();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetCommentsAllData() throws IOException, ExtractionException {
|
||||
final InfoItemsPage<CommentsInfoItem> comments = extractor.getInitialPage();
|
||||
|
||||
DefaultTests.defaultTestListOfItems(YouTube, comments.getItems(), comments.getErrors());
|
||||
|
||||
for (CommentsInfoItem c : comments.getItems()) {
|
||||
assertFalse(Utils.isBlank(c.getUploaderUrl()));
|
||||
assertFalse(Utils.isBlank(c.getUploaderName()));
|
||||
assertFalse(Utils.isBlank(c.getUploaderAvatarUrl()));
|
||||
assertFalse(Utils.isBlank(c.getCommentId()));
|
||||
assertFalse(Utils.isBlank(c.getName()));
|
||||
assertFalse(Utils.isBlank(c.getTextualUploadDate()));
|
||||
assertNotNull(c.getUploadDate());
|
||||
assertFalse(Utils.isBlank(c.getThumbnailUrl()));
|
||||
assertFalse(Utils.isBlank(c.getUrl()));
|
||||
assertFalse(c.getLikeCount() < 0);
|
||||
assertFalse(Utils.isBlank(c.getCommentText()));
|
||||
}
|
||||
|
||||
assertTrue("First comment isn't pinned", comments.getItems().get(0).getPinned());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user