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 @@ -16,6 +16,7 @@ public class CommentsInfoItem extends InfoItem {
@Nullable
private DateWrapper uploadDate;
private int likeCount;
private boolean heartedByUploader;

public CommentsInfoItem(int serviceId, String url, String name) {
super(InfoType.COMMENT, serviceId, url, name);
Expand Down Expand Up @@ -85,4 +86,12 @@ public int getLikeCount() {
public void setLikeCount(int likeCount) {
this.likeCount = likeCount;
}

public void setHeartedByUploader(boolean isHeartedByUploader) {
this.heartedByUploader = isHeartedByUploader;
}

public boolean getHeartedByUploader() {
return this.heartedByUploader;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,9 @@ public interface CommentsInfoItemExtractor extends InfoItemExtractor {
String getUploaderName() throws ParsingException;

String getUploaderAvatarUrl() throws ParsingException;

/**
* Whether the comment has been hearted by the uploader
*/
boolean getHeartedByUploader() throws ParsingException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ public CommentsInfoItem extract(CommentsInfoItemExtractor extractor) throws Pars
addError(e);
}

try {
resultItem.setHeartedByUploader(extractor.getHeartedByUploader());
} catch (Exception e) {
addError(e);
}

return resultItem;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ public String getUploaderAvatarUrl() {
return baseUrl + value;
}

@Override
public boolean getHeartedByUploader() 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 @@ -39,6 +39,11 @@ public String getUploaderAvatarUrl() {
return json.getObject("user").getString("avatar_url");
}

@Override
public boolean getHeartedByUploader() 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 @@ -115,6 +115,11 @@ public String getUploaderAvatarUrl() throws ParsingException {
}
}

@Override
public boolean getHeartedByUploader() throws ParsingException {
return json.has("creatorHeart");
}

@Override
public String getUploaderName() throws ParsingException {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@
import java.io.IOException;
import java.util.List;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.*;
import static org.schabi.newpipe.extractor.ServiceList.YouTube;

public class YoutubeCommentsExtractorTest {
Expand All @@ -28,9 +25,8 @@ public class YoutubeCommentsExtractorTest {
*/
public static class Thomas {
private static final String url = "https://www.youtube.com/watch?v=D00Au7k3i6o";
private static YoutubeCommentsExtractor extractor;

private static final String commentContent = "Category: Education";
private static YoutubeCommentsExtractor extractor;

@BeforeClass
public static void setUp() throws Exception {
Expand Down Expand Up @@ -116,8 +112,8 @@ private boolean findInComments(List<CommentsInfoItem> comments, String comment)
* Test a video with an empty comment
*/
public static class EmptyComment {
private static YoutubeCommentsExtractor extractor;
private final static String url = "https://www.youtube.com/watch?v=VM_6n762j6M";
private static YoutubeCommentsExtractor extractor;

@BeforeClass
public static void setUp() throws Exception {
Expand Down Expand Up @@ -152,4 +148,45 @@ public void testGetCommentsAllData() throws IOException, ExtractionException {
}

}

public static class HeartedByCreator {
private final static String url = "https://www.youtube.com/watch?v=tR11b7uh17Y";
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());

boolean heartedByUploader = false;

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()));
if (c.getHeartedByUploader()) {
heartedByUploader = true;
}
}
assertTrue("No comments was hearted by uploader", heartedByUploader);

}
}
}