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..14075bea28 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 @@ -260,14 +260,18 @@ 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"); + .getObject("commentsHeaderRenderer") + .getObject("countText"); - final String text = getTextFromObject(commentsHeaderRenderer.getObject("countText")); - - return Integer.parseInt(Utils.removeNonDigitCharacters(text)); + try { + final String text = getTextFromObject(countText); + return Integer.parseInt(Utils.removeNonDigitCharacters(text)); + } catch (final Exception e) { + throw new ExtractionException("Unable to get comments count", e); + } } }