mirror of
https://github.com/TeamNewPipe/NewPipeExtractor.git
synced 2024-12-14 14:20:33 +05:30
Fix LiveStream view count
This commit is contained in:
parent
127c4d5893
commit
10e9c16d8c
@ -323,7 +323,23 @@ public class YoutubeStreamExtractor extends StreamExtractor {
|
|||||||
assertPageFetched();
|
assertPageFetched();
|
||||||
try {
|
try {
|
||||||
if (getStreamType().equals(StreamType.LIVE_STREAM)) {
|
if (getStreamType().equals(StreamType.LIVE_STREAM)) {
|
||||||
return getLiveStreamWatchingCount();
|
// The array index is variable, therefore we loop throw the complete array.
|
||||||
|
// videoPrimaryInfoRenderer is often stored at index 1
|
||||||
|
JsonArray contents = ytInitialData.getObject("contents").getObject("twoColumnWatchNextResults")
|
||||||
|
.getObject("results").getObject("results").getArray("contents");
|
||||||
|
for (Object c : contents) {
|
||||||
|
try {
|
||||||
|
// this gets current view count, but there is also an overall view count which is stored here:
|
||||||
|
// contents.twoColumnWatchNextResults.secondaryResults.secondaryResults.results[0]
|
||||||
|
// .compactAutoplayRenderer.contents[0].compactVideoRenderer.viewCountText.simpleText
|
||||||
|
String views = ((JsonObject) c).getObject("videoPrimaryInfoRenderer")
|
||||||
|
.getObject("viewCount").getObject("videoViewCountRenderer").getObject("viewCount")
|
||||||
|
.getArray("runs").getObject(0).getString("text");
|
||||||
|
return Long.parseLong(Utils.removeNonDigitCharacters(views));
|
||||||
|
} catch (Exception ignored) {}
|
||||||
|
}
|
||||||
|
throw new ParsingException("Could not get view count from live stream");
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
return Long.parseLong(playerResponse.getObject("videoDetails").getString("viewCount"));
|
return Long.parseLong(playerResponse.getObject("videoDetails").getString("viewCount"));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user