Skip to content

Commit 70abd57

Browse files
committed
[YouTube] Cache commonly used stream type result
1 parent 1ef706f commit 70abd57

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public class YoutubeStreamInfoItemExtractor implements StreamInfoItemExtractor {
4040

4141
private JsonObject videoInfo;
4242
private final TimeAgoParser timeAgoParser;
43+
private StreamType cachedStreamType;
4344

4445
/**
4546
* Creates an extractor of StreamInfoItems from a YouTube page.
@@ -54,11 +55,15 @@ public YoutubeStreamInfoItemExtractor(JsonObject videoInfoItem, @Nullable TimeAg
5455

5556
@Override
5657
public StreamType getStreamType() {
58+
if (cachedStreamType != null) {
59+
return cachedStreamType;
60+
}
61+
5762
try {
5863
JsonArray badges = videoInfo.getArray("badges");
5964
for (Object badge : badges) {
6065
if (((JsonObject) badge).getObject("metadataBadgeRenderer").getString("label").equals("LIVE NOW")) {
61-
return StreamType.LIVE_STREAM;
66+
return cachedStreamType = StreamType.LIVE_STREAM;
6267
}
6368
}
6469

@@ -68,11 +73,11 @@ public StreamType getStreamType() {
6873
final String style = videoInfo.getArray("thumbnailOverlays").getObject(0)
6974
.getObject("thumbnailOverlayTimeStatusRenderer").getString("style");
7075
if (style.equalsIgnoreCase("LIVE")) {
71-
return StreamType.LIVE_STREAM;
76+
return cachedStreamType = StreamType.LIVE_STREAM;
7277
}
7378
} catch (Exception ignored) {}
7479

75-
return StreamType.VIDEO_STREAM;
80+
return cachedStreamType = StreamType.VIDEO_STREAM;
7681
}
7782

7883
@Override

0 commit comments

Comments
 (0)