Merge pull request #281 from mauriciocolli/add-check-live
[YouTube] Add additional check for live videos
This commit is contained in:
commit
e7be952fbf
|
@ -40,6 +40,7 @@ public class YoutubeStreamInfoItemExtractor implements StreamInfoItemExtractor {
|
||||||
|
|
||||||
private JsonObject videoInfo;
|
private JsonObject videoInfo;
|
||||||
private final TimeAgoParser timeAgoParser;
|
private final TimeAgoParser timeAgoParser;
|
||||||
|
private StreamType cachedStreamType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an extractor of StreamInfoItems from a YouTube page.
|
* Creates an extractor of StreamInfoItems from a YouTube page.
|
||||||
|
@ -54,16 +55,29 @@ public class YoutubeStreamInfoItemExtractor implements StreamInfoItemExtractor {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public StreamType getStreamType() {
|
public StreamType getStreamType() {
|
||||||
|
if (cachedStreamType != null) {
|
||||||
|
return cachedStreamType;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
JsonArray badges = videoInfo.getArray("badges");
|
JsonArray badges = videoInfo.getArray("badges");
|
||||||
for (Object badge : badges) {
|
for (Object badge : badges) {
|
||||||
if (((JsonObject) badge).getObject("metadataBadgeRenderer").getString("label").equals("LIVE NOW")) {
|
if (((JsonObject) badge).getObject("metadataBadgeRenderer").getString("label").equals("LIVE NOW")) {
|
||||||
return StreamType.LIVE_STREAM;
|
return cachedStreamType = StreamType.LIVE_STREAM;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception ignored) {}
|
} catch (Exception ignored) {}
|
||||||
return StreamType.VIDEO_STREAM;
|
|
||||||
|
try {
|
||||||
|
final String style = videoInfo.getArray("thumbnailOverlays").getObject(0)
|
||||||
|
.getObject("thumbnailOverlayTimeStatusRenderer").getString("style");
|
||||||
|
if (style.equalsIgnoreCase("LIVE")) {
|
||||||
|
return cachedStreamType = StreamType.LIVE_STREAM;
|
||||||
|
}
|
||||||
|
} catch (Exception ignored) {}
|
||||||
|
|
||||||
|
return cachedStreamType = StreamType.VIDEO_STREAM;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue