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 385ee6eb8..84e6c3e1e 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 @@ -66,10 +66,15 @@ public class YoutubeCommentsExtractor extends CommentsExtractor { * @return the continuation token or null if none was found */ @Nullable - private String findInitialCommentsToken(final JsonObject nextResponse) - throws ExtractionException { - final String token = JsonUtils.getArray(nextResponse, - "contents.twoColumnWatchNextResults.results.results.contents") + private String findInitialCommentsToken(final JsonObject nextResponse) { + final JsonArray contents = getJsonContents(nextResponse); + + // For videos where comments are unavailable, this would be null + if (contents == null) { + return null; + } + + final String token = contents .stream() // Only use JsonObjects .filter(JsonObject.class::isInstance) @@ -105,6 +110,16 @@ public class YoutubeCommentsExtractor extends CommentsExtractor { return token; } + @Nullable + private JsonArray getJsonContents(final JsonObject nextResponse) { + try { + return JsonUtils.getArray(nextResponse, + "contents.twoColumnWatchNextResults.results.results.contents"); + } catch (final ParsingException e) { + return null; + } + } + @Nonnull private InfoItemsPage getInfoItemsPageForDisabledComments() { return new InfoItemsPage<>(Collections.emptyList(), null, Collections.emptyList());