[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
|
* @return the continuation token or null if none was found
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
private String findInitialCommentsToken(final JsonObject nextResponse)
|
private String findInitialCommentsToken(final JsonObject nextResponse) {
|
||||||
throws ExtractionException {
|
final JsonArray contents = getJsonContents(nextResponse);
|
||||||
final String token = JsonUtils.getArray(nextResponse,
|
|
||||||
"contents.twoColumnWatchNextResults.results.results.contents")
|
// 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)
|
||||||
|
@ -105,6 +110,16 @@ public class YoutubeCommentsExtractor extends CommentsExtractor {
|
||||||
return token;
|
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
|
@Nonnull
|
||||||
private InfoItemsPage<CommentsInfoItem> getInfoItemsPageForDisabledComments() {
|
private InfoItemsPage<CommentsInfoItem> getInfoItemsPageForDisabledComments() {
|
||||||
return new InfoItemsPage<>(Collections.emptyList(), null, Collections.emptyList());
|
return new InfoItemsPage<>(Collections.emptyList(), null, Collections.emptyList());
|
||||||
|
|
Loading…
Reference in New Issue