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); + } } }