Skip to content

Commit 1b6fe5e

Browse files
bjoernlsbjsAudricVFireMasterK
authored
[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>
1 parent 8d1303e commit 1b6fe5e

1 file changed

Lines changed: 19 additions & 4 deletions

File tree

extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeCommentsExtractor.java

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,15 @@ public InfoItemsPage<CommentsInfoItem> getInitialPage()
6666
* @return the continuation token or null if none was found
6767
*/
6868
@Nullable
69-
private String findInitialCommentsToken(final JsonObject nextResponse)
70-
throws ExtractionException {
71-
final String token = JsonUtils.getArray(nextResponse,
72-
"contents.twoColumnWatchNextResults.results.results.contents")
69+
private String findInitialCommentsToken(final JsonObject nextResponse) {
70+
final JsonArray contents = getJsonContents(nextResponse);
71+
72+
// For videos where comments are unavailable, this would be null
73+
if (contents == null) {
74+
return null;
75+
}
76+
77+
final String token = contents
7378
.stream()
7479
// Only use JsonObjects
7580
.filter(JsonObject.class::isInstance)
@@ -105,6 +110,16 @@ private String findInitialCommentsToken(final JsonObject nextResponse)
105110
return token;
106111
}
107112

113+
@Nullable
114+
private JsonArray getJsonContents(final JsonObject nextResponse) {
115+
try {
116+
return JsonUtils.getArray(nextResponse,
117+
"contents.twoColumnWatchNextResults.results.results.contents");
118+
} catch (final ParsingException e) {
119+
return null;
120+
}
121+
}
122+
108123
@Nonnull
109124
private InfoItemsPage<CommentsInfoItem> getInfoItemsPageForDisabledComments() {
110125
return new InfoItemsPage<>(Collections.emptyList(), null, Collections.emptyList());

0 commit comments

Comments
 (0)