[YouTube] Do not get twice runs array in YoutubeParsingHelper

The runs object was computed twice in getTextFromObject and getUrlFromObject
methods, leading to unneeded search costs. This has been avoided by storing the
array in method variables.
This commit is contained in:
AudricV 2024-03-23 21:36:25 +01:00
parent 2d36945b39
commit c99d94b615
No known key found for this signature in database
GPG Key ID: DA92EC7905614198
1 changed files with 6 additions and 4 deletions

View File

@ -887,12 +887,13 @@ public final class YoutubeParsingHelper {
return textObject.getString("simpleText");
}
if (textObject.getArray("runs").isEmpty()) {
final JsonArray runs = textObject.getArray("runs");
if (runs.isEmpty()) {
return null;
}
final StringBuilder textBuilder = new StringBuilder();
for (final Object o : textObject.getArray("runs")) {
for (final Object o : runs) {
final JsonObject run = (JsonObject) o;
String text = run.getString("text");
@ -970,11 +971,12 @@ public final class YoutubeParsingHelper {
return null;
}
if (textObject.getArray("runs").isEmpty()) {
final JsonArray runs = textObject.getArray("runs");
if (runs.isEmpty()) {
return null;
}
for (final Object textPart : textObject.getArray("runs")) {
for (final Object textPart : runs) {
final String url = getUrlFromNavigationEndpoint(((JsonObject) textPart)
.getObject("navigationEndpoint"));
if (!isNullOrEmpty(url)) {