When comments are unavailable in a video, we get a ParsingException

Issue #969. Parsing exception is handled when the JSON path does not exist in the case of disabled comments.
This commit is contained in:
bjs 2023-03-14 10:13:39 +00:00
parent 5a9b6ed2e3
commit 687fe4ec74
1 changed files with 11 additions and 2 deletions

View File

@ -68,8 +68,7 @@ public class YoutubeCommentsExtractor extends CommentsExtractor {
@Nullable
private String findInitialCommentsToken(final JsonObject nextResponse)
throws ExtractionException {
final String token = JsonUtils.getArray(nextResponse,
"contents.twoColumnWatchNextResults.results.results.contents")
final String token = getJsonContents(nextResponse)
.stream()
// Only use JsonObjects
.filter(JsonObject.class::isInstance)
@ -105,6 +104,16 @@ public class YoutubeCommentsExtractor extends CommentsExtractor {
return token;
}
@Nonnull
private JsonArray getJsonContents(final JsonObject nextResponse) {
try {
return JsonUtils.getArray(nextResponse,
"contents.twoColumnWatchNextResults.results.results.contents");
} catch (final ParsingException pe) {
return new JsonArray(Collections.emptyList());
}
}
@Nonnull
private InfoItemsPage<CommentsInfoItem> getInfoItemsPageForDisabledComments() {
return new InfoItemsPage<>(Collections.emptyList(), null, Collections.emptyList());