Skip to content

Commit e7be952

Browse files
authored
Merge pull request #281 from mauriciocolli/add-check-live
[YouTube] Add additional check for live videos
2 parents 6446abc + 70abd57 commit e7be952

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

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

Lines changed: 16 additions & 2 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,16 +55,29 @@ 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

6570
} catch (Exception ignored) {}
66-
return StreamType.VIDEO_STREAM;
71+
72+
try {
73+
final String style = videoInfo.getArray("thumbnailOverlays").getObject(0)
74+
.getObject("thumbnailOverlayTimeStatusRenderer").getString("style");
75+
if (style.equalsIgnoreCase("LIVE")) {
76+
return cachedStreamType = StreamType.LIVE_STREAM;
77+
}
78+
} catch (Exception ignored) {}
79+
80+
return cachedStreamType = StreamType.VIDEO_STREAM;
6781
}
6882

6983
@Override

0 commit comments

Comments
 (0)