From 318bc46a8c6da418ed58501f3cbcb9312d5cac8e Mon Sep 17 00:00:00 2001 From: TiA4f8R <74829229+TiA4f8R@users.noreply.github.com> Date: Wed, 2 Jun 2021 18:46:35 +0200 Subject: [PATCH] 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. --- .../extractors/YoutubeStreamExtractor.java | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java index 77e888219..2b2a00ff8 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java @@ -320,9 +320,22 @@ public class YoutubeStreamExtractor extends StreamExtractor { @Override public long getViewCount() throws ParsingException { - assertPageFetched(); - final String views = playerResponse.getObject("videoDetails").getString("viewCount"); - if (isNullOrEmpty(views)) throw new ParsingException("Could not get view count"); + String views = null; + + try { + views = getTextFromObject(getVideoPrimaryInfoRenderer().getObject("viewCount") + .getObject("videoViewCountRenderer").getObject("viewCount")); + } catch (final ParsingException ignored) { + // Age-restricted videos cause a ParsingException here + } + + if (isNullOrEmpty(views)) { + views = playerResponse.getObject("videoDetails").getString("viewCount"); + + if (isNullOrEmpty(views)) throw new ParsingException("Could not get view count"); + } + + if (views.toLowerCase().contains("no views")) return 0; return Long.parseLong(Utils.removeNonDigitCharacters(views)); }