Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -94,4 +95,12 @@ public void setHeartedByUploader(boolean isHeartedByUploader) {
public boolean getHeartedByUploader() {
return this.heartedByUploader;
}

public boolean getPinned() {
return pinned;
}

public void setPinned(boolean pinned) {
this.pinned = pinned;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ public CommentsInfoItem extract(CommentsInfoItemExtractor extractor) throws Pars
addError(e);
}

try {
resultItem.setPinned(extractor.getPinned());
} catch (Exception e) {
addError(e);
}

return resultItem;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ public boolean getHeartedByUploader() throws ParsingException {
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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ public boolean getHeartedByUploader() throws ParsingException {
return false;
}

@Override
public boolean getPinned() throws ParsingException {
return false;
}

@Override
public String getUploaderUrl() {
return json.getObject("user").getString("permalink_url");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ public boolean getHeartedByUploader() throws ParsingException {
return json.has("creatorHeart");
}

@Override
public boolean getPinned() {
return json.has("pinnedCommentBadge");
}

@Override
public String getUploaderName() throws ParsingException {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,4 +189,40 @@ public void testGetCommentsAllData() throws IOException, ExtractionException {

}
}

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());
}
}
}