From 0779c33b14bbff53df5a002f8b78a5a84c61122d Mon Sep 17 00:00:00 2001 From: FireMasterK <20838718+FireMasterK@users.noreply.github.com> Date: Thu, 10 Feb 2022 15:43:02 +0000 Subject: [PATCH] Fix for requested changes. --- .../extractors/YoutubeCommentsExtractor.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeCommentsExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeCommentsExtractor.java index 1e5c39a995..7fad481d32 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeCommentsExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeCommentsExtractor.java @@ -45,6 +45,9 @@ public class YoutubeCommentsExtractor extends CommentsExtractor { */ @SuppressWarnings("OptionalUsedAsFieldOrParameterType") private Optional optCommentsDisabled = Optional.empty(); + /** + * The second ajax /next response. + */ private JsonObject ajaxJson; public YoutubeCommentsExtractor( @@ -260,14 +263,17 @@ public boolean isCommentsDisabled() throws ExtractionException { @Override public int getCommentsCount() throws ExtractionException { - final JsonObject commentsHeaderRenderer = ajaxJson + final JsonObject countText = ajaxJson .getArray("onResponseReceivedEndpoints").getObject(0) .getObject("reloadContinuationItemsCommand") .getArray("continuationItems").getObject(0) - .getObject("commentsHeaderRenderer"); - - final String text = getTextFromObject(commentsHeaderRenderer.getObject("countText")); + .getObject("commentsHeaderRenderer") + .getObject("countText"); - return Integer.parseInt(Utils.removeNonDigitCharacters(text)); + try { + return Integer.parseInt(Utils.removeNonDigitCharacters(getTextFromObject(countText))); + } catch (final Exception e) { + throw new ExtractionException("Unable to get comments count", e); + } } }