Merge pull request #523 from B0pol/pinned

Extract whether the comment is pinned
This commit is contained in:
Tobias Groza 2021-01-23 12:35:13 +01:00 committed by GitHub
commit 10e8c543e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 74 additions and 0 deletions

View File

@ -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;
}
}

View File

@ -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;
}

View File

@ -76,6 +76,12 @@ public class CommentsInfoItemsCollector extends InfoItemsCollector<CommentsInfoI
addError(e);
}
try {
resultItem.setPinned(extractor.getPinned());
} catch (Exception e) {
addError(e);
}
return resultItem;
}

View File

@ -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");

View File

@ -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");

View File

@ -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 {

View File

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