Skip to content

Commit 8bfbae9

Browse files
committed
Cache getVideo(Primary|Secondary)InfoRenderer()
1 parent 0b940f5 commit 8bfbae9

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ public class DecryptException extends ParsingException {
9595
private final Map<String, String> videoInfoPage = new HashMap<>();
9696
private JsonObject playerResponse;
9797
private JsonObject initialData;
98+
private JsonObject videoPrimaryInfoRenderer;
99+
private JsonObject videoSecondaryInfoRenderer;
98100

99101
@Nonnull
100102
private List<SubtitlesInfo> subtitlesInfos = new ArrayList<>();
@@ -843,6 +845,8 @@ public SubtitlesStream getSubtitle(final MediaFormat format) {
843845
//////////////////////////////////////////////////////////////////////////*/
844846

845847
private JsonObject getVideoPrimaryInfoRenderer() throws ParsingException {
848+
if (this.videoPrimaryInfoRenderer != null) return this.videoPrimaryInfoRenderer;
849+
846850
JsonArray contents = initialData.getObject("contents").getObject("twoColumnWatchNextResults")
847851
.getObject("results").getObject("results").getArray("contents");
848852
JsonObject videoPrimaryInfoRenderer = null;
@@ -858,10 +862,13 @@ private JsonObject getVideoPrimaryInfoRenderer() throws ParsingException {
858862
throw new ParsingException("Could not find videoPrimaryInfoRenderer");
859863
}
860864

865+
this.videoPrimaryInfoRenderer = videoPrimaryInfoRenderer;
861866
return videoPrimaryInfoRenderer;
862867
}
863868

864869
private JsonObject getVideoSecondaryInfoRenderer() throws ParsingException {
870+
if (this.videoSecondaryInfoRenderer != null) return this.videoSecondaryInfoRenderer;
871+
865872
JsonArray contents = initialData.getObject("contents").getObject("twoColumnWatchNextResults")
866873
.getObject("results").getObject("results").getArray("contents");
867874
JsonObject videoSecondaryInfoRenderer = null;
@@ -877,6 +884,7 @@ private JsonObject getVideoSecondaryInfoRenderer() throws ParsingException {
877884
throw new ParsingException("Could not find videoSecondaryInfoRenderer");
878885
}
879886

887+
this.videoSecondaryInfoRenderer = videoSecondaryInfoRenderer;
880888
return videoSecondaryInfoRenderer;
881889
}
882890

0 commit comments

Comments
 (0)