This commit is contained in:
kkLNan 2023-10-05 16:39:05 +02:00 committed by GitHub
commit f25b141a8b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 58 additions and 2 deletions

View File

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

View File

@ -134,4 +134,8 @@ public interface CommentsInfoItemExtractor extends InfoItemExtractor {
default Page getReplies() throws ParsingException {
return null;
}
default String getDonation() throws ParsingException {
return "";
}
}

View File

@ -101,6 +101,12 @@ public final class CommentsInfoItemsCollector
addError(e);
}
try {
resultItem.setDonation(extractor.getDonation());
} catch (final Exception e) {
addError(e);
}
return resultItem;
}

View File

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

View File

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