Skip to content

Commit 318bc46

Browse files
committed
Readd the deleted code of views because watching count of livestreams was broken
The number shown was the total number of views that a livestream has. In order to fix this bug, the previous code is readded.
1 parent 947baec commit 318bc46

1 file changed

Lines changed: 16 additions & 3 deletions

File tree

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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -320,9 +320,22 @@ public long getTimeStamp() throws ParsingException {
320320

321321
@Override
322322
public long getViewCount() throws ParsingException {
323-
assertPageFetched();
324-
final String views = playerResponse.getObject("videoDetails").getString("viewCount");
325-
if (isNullOrEmpty(views)) throw new ParsingException("Could not get view count");
323+
String views = null;
324+
325+
try {
326+
views = getTextFromObject(getVideoPrimaryInfoRenderer().getObject("viewCount")
327+
.getObject("videoViewCountRenderer").getObject("viewCount"));
328+
} catch (final ParsingException ignored) {
329+
// Age-restricted videos cause a ParsingException here
330+
}
331+
332+
if (isNullOrEmpty(views)) {
333+
views = playerResponse.getObject("videoDetails").getString("viewCount");
334+
335+
if (isNullOrEmpty(views)) throw new ParsingException("Could not get view count");
336+
}
337+
338+
if (views.toLowerCase().contains("no views")) return 0;
326339

327340
return Long.parseLong(Utils.removeNonDigitCharacters(views));
328341
}

0 commit comments

Comments
 (0)