[YouTube] Fix potential NullPointerException in YoutubeSearchExtractor.getSearchSuggestion

This commit is contained in:
AudricV 2023-10-07 21:02:28 +02:00
parent 9dc1eab28c
commit 56ab35423e
No known key found for this signature in database
GPG Key ID: DA92EC7905614198
1 changed files with 7 additions and 7 deletions

View File

@ -36,6 +36,7 @@ import org.schabi.newpipe.extractor.utils.JsonUtils;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Objects;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
@ -124,18 +125,17 @@ public class YoutubeSearchExtractor extends SearchExtractor {
final JsonObject didYouMeanRenderer = itemSectionRenderer.getArray("contents")
.getObject(0)
.getObject("didYouMeanRenderer");
final JsonObject showingResultsForRenderer = itemSectionRenderer.getArray("contents")
.getObject(0)
.getObject("showingResultsForRenderer");
if (!didYouMeanRenderer.isEmpty()) {
return JsonUtils.getString(didYouMeanRenderer,
"correctedQueryEndpoint.searchEndpoint.query");
} else if (showingResultsForRenderer != null) {
return getTextFromObject(showingResultsForRenderer.getObject("correctedQuery"));
} else {
return "";
}
return Objects.requireNonNullElse(
getTextFromObject(itemSectionRenderer.getArray("contents")
.getObject(0)
.getObject("showingResultsForRenderer")
.getObject("correctedQuery")), "");
}
@Override