Check if null instead of iterating an empty Collection.
This commit is contained in:
parent
4c1af8cb6d
commit
7686c85fe7
|
@ -68,7 +68,14 @@ public class YoutubeCommentsExtractor extends CommentsExtractor {
|
||||||
@Nullable
|
@Nullable
|
||||||
private String findInitialCommentsToken(final JsonObject nextResponse)
|
private String findInitialCommentsToken(final JsonObject nextResponse)
|
||||||
throws ExtractionException {
|
throws ExtractionException {
|
||||||
final String token = getJsonContents(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()
|
.stream()
|
||||||
// Only use JsonObjects
|
// Only use JsonObjects
|
||||||
.filter(JsonObject.class::isInstance)
|
.filter(JsonObject.class::isInstance)
|
||||||
|
@ -104,13 +111,13 @@ public class YoutubeCommentsExtractor extends CommentsExtractor {
|
||||||
return token;
|
return token;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nullable
|
||||||
private JsonArray getJsonContents(final JsonObject nextResponse) {
|
private JsonArray getJsonContents(final JsonObject nextResponse) {
|
||||||
try {
|
try {
|
||||||
return JsonUtils.getArray(nextResponse,
|
return JsonUtils.getArray(nextResponse,
|
||||||
"contents.twoColumnWatchNextResults.results.results.contents");
|
"contents.twoColumnWatchNextResults.results.results.contents");
|
||||||
} catch (final ParsingException e) {
|
} catch (final ParsingException e) {
|
||||||
return new JsonArray(Collections.emptyList());
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue