feat: Add a new donation field. Test passed under mock mode.
This commit is contained in:
parent
3be76a6406
commit
6890cf5894
|
@ -30,6 +30,7 @@ public class CommentsInfoItem extends InfoItem {
|
||||||
private int replyCount;
|
private int replyCount;
|
||||||
@Nullable
|
@Nullable
|
||||||
private Page replies;
|
private Page replies;
|
||||||
|
private String donation;
|
||||||
|
|
||||||
public static final int NO_LIKE_COUNT = -1;
|
public static final int NO_LIKE_COUNT = -1;
|
||||||
public static final int NO_STREAM_POSITION = -1;
|
public static final int NO_STREAM_POSITION = -1;
|
||||||
|
@ -172,4 +173,12 @@ public class CommentsInfoItem extends InfoItem {
|
||||||
public Page getReplies() {
|
public Page getReplies() {
|
||||||
return this.replies;
|
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 {
|
default Page getReplies() throws ParsingException {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
default String getDonation() throws ParsingException {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -101,6 +101,12 @@ public final class CommentsInfoItemsCollector
|
||||||
addError(e);
|
addError(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
resultItem.setDonation(extractor.getDonation());
|
||||||
|
} catch (final Exception e) {
|
||||||
|
addError(e);
|
||||||
|
}
|
||||||
|
|
||||||
return resultItem;
|
return resultItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -277,4 +277,14 @@ public class YoutubeCommentsInfoItemExtractor implements CommentsInfoItemExtract
|
||||||
return null;
|
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 {
|
public static class FormattingTest {
|
||||||
|
|
||||||
private final static String url = "https://www.youtube.com/watch?v=zYpyS2HaZHM";
|
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