[YouTube] Fix ParsingException when comments are unavailable in a video (#1040)
Co-authored-by: bjs <bjs@elect-it.com> Co-authored-by: Audric V. <74829229+AudricV@users.noreply.github.com> Co-authored-by: Kavin <20838718+FireMasterK@users.noreply.github.com>
This commit is contained in:
parent
8d1303e18f
commit
1b6fe5edd6
|
@ -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<CommentsInfoItem> getInfoItemsPageForDisabledComments() {
|
||||
return new InfoItemsPage<>(Collections.emptyList(), null, Collections.emptyList());
|
||||
|
|
Loading…
Reference in New Issue