Use pre-generated playerResponse field everywhere in YtStreamExtractor
This commit is contained in:
parent
63a37c48e3
commit
d9570d8634
|
@ -254,20 +254,6 @@ public class YoutubeStreamExtractor extends StreamExtractor {
|
||||||
public long getLength() throws ParsingException {
|
public long getLength() throws ParsingException {
|
||||||
assertPageFetched();
|
assertPageFetched();
|
||||||
|
|
||||||
final JsonObject playerResponse;
|
|
||||||
try {
|
|
||||||
final String pr;
|
|
||||||
if(playerArgs != null) {
|
|
||||||
pr = playerArgs.getString("player_response");
|
|
||||||
} else {
|
|
||||||
pr = videoInfoPage.get("player_response");
|
|
||||||
}
|
|
||||||
playerResponse = JsonParser.object()
|
|
||||||
.from(pr);
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new ParsingException("Could not get playerResponse", e);
|
|
||||||
}
|
|
||||||
|
|
||||||
// try getting duration from playerargs
|
// try getting duration from playerargs
|
||||||
try {
|
try {
|
||||||
String durationMs = playerResponse
|
String durationMs = playerResponse
|
||||||
|
@ -859,19 +845,13 @@ public class YoutubeStreamExtractor extends StreamExtractor {
|
||||||
} catch (IOException | ExtractionException e) {
|
} catch (IOException | ExtractionException e) {
|
||||||
throw new SubtitlesException("Unable to download player configs", e);
|
throw new SubtitlesException("Unable to download player configs", e);
|
||||||
}
|
}
|
||||||
final String playerResponse = playerConfig.getObject("args", new JsonObject())
|
|
||||||
.getString("player_response");
|
|
||||||
|
|
||||||
final JsonObject captions;
|
final JsonObject captions;
|
||||||
try {
|
if (!playerResponse.has("captions")) {
|
||||||
if (playerResponse == null || !JsonParser.object().from(playerResponse).has("captions")) {
|
|
||||||
// Captions does not exist
|
// Captions does not exist
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
captions = JsonParser.object().from(playerResponse).getObject("captions");
|
captions = playerResponse.getObject("captions");
|
||||||
} catch (JsonParserException e) {
|
|
||||||
throw new SubtitlesException("Unable to parse subtitles listing", e);
|
|
||||||
}
|
|
||||||
|
|
||||||
final JsonObject renderer = captions.getObject("playerCaptionsTracklistRenderer", new JsonObject());
|
final JsonObject renderer = captions.getObject("playerCaptionsTracklistRenderer", new JsonObject());
|
||||||
final JsonArray captionsArray = renderer.getArray("captionTracks", new JsonArray());
|
final JsonArray captionsArray = renderer.getArray("captionTracks", new JsonArray());
|
||||||
|
|
Loading…
Reference in New Issue