Merge 6890cf5894
into bb132167d5
This commit is contained in:
commit
f25b141a8b
|
@ -30,6 +30,7 @@ public class CommentsInfoItem extends InfoItem {
|
|||
private int replyCount;
|
||||
@Nullable
|
||||
private Page replies;
|
||||
private String donation;
|
||||
|
||||
public static final int NO_LIKE_COUNT = -1;
|
||||
public static final int NO_STREAM_POSITION = -1;
|
||||
|
@ -172,4 +173,12 @@ public class CommentsInfoItem extends InfoItem {
|
|||
public Page getReplies() {
|
||||
return this.replies;
|
||||
}
|
||||
|
||||
public String getDonation() {
|
||||
return donation;
|
||||
}
|
||||
|
||||
public void setDonation(final String donation) {
|
||||
this.donation = donation;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -134,4 +134,8 @@ public interface CommentsInfoItemExtractor extends InfoItemExtractor {
|
|||
default Page getReplies() throws ParsingException {
|
||||
return null;
|
||||
}
|
||||
|
||||
default String getDonation() throws ParsingException {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -101,6 +101,12 @@ public final class CommentsInfoItemsCollector
|
|||
addError(e);
|
||||
}
|
||||
|
||||
try {
|
||||
resultItem.setDonation(extractor.getDonation());
|
||||
} catch (final Exception e) {
|
||||
addError(e);
|
||||
}
|
||||
|
||||
return resultItem;
|
||||
}
|
||||
|
||||
|
|
|
@ -277,4 +277,14 @@ public class YoutubeCommentsInfoItemExtractor implements CommentsInfoItemExtract
|
|||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDonation() {
|
||||
try {
|
||||
return getTextFromObject(JsonUtils.getObject(getCommentRenderer(),
|
||||
"paidCommentChipRenderer.pdgCommentChipRenderer.chipText"));
|
||||
} catch (final Exception e) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -352,6 +352,33 @@ public class YoutubeCommentsExtractorTest {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
public static class DonationTest {
|
||||
private final static String url = "https://www.youtube.com/watch?v=xaQJbozY_Is";
|
||||
private static YoutubeCommentsExtractor extractor;
|
||||
|
||||
@BeforeAll
|
||||
public static void setUp() throws Exception {
|
||||
YoutubeTestsUtils.ensureStateless();
|
||||
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "replies"));
|
||||
extractor = (YoutubeCommentsExtractor) YouTube
|
||||
.getCommentsExtractor(url);
|
||||
extractor.fetchPage();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetCommentsDonation() throws IOException, ExtractionException {
|
||||
final InfoItemsPage<CommentsInfoItem> comments = extractor.getInitialPage();
|
||||
|
||||
DefaultTests.defaultTestListOfItems(YouTube, comments.getItems(), comments.getErrors());
|
||||
|
||||
final CommentsInfoItem firstComment = comments.getItems().get(0);
|
||||
|
||||
assertNotEquals("", firstComment.getDonation(), "Could not get the donation of the first comment");
|
||||
assertEquals("US$100.00", firstComment.getDonation());
|
||||
}
|
||||
}
|
||||
|
||||
public static class FormattingTest {
|
||||
|
||||
private final static String url = "https://www.youtube.com/watch?v=zYpyS2HaZHM";
|
||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue