Skip to content

Commit da2c562

Browse files
mauriciocolliTobiGr
authored andcommitted
[YouTube] Take into account videos that have their views hidden
Also remove catch because it may hide bugs when the page changes.
1 parent f66c20d commit da2c562

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,11 +194,16 @@ public long getViewCount() throws ParsingException {
194194
if (videoInfo.getObject("topStandaloneBadge") != null || isPremium()) {
195195
return -1;
196196
}
197-
String viewCount = getTextFromObject(videoInfo.getObject("viewCountText"));
197+
198+
final JsonObject viewCountObject = videoInfo.getObject("viewCountText");
199+
if (viewCountObject == null) {
200+
// This object is null when a video has its views hidden.
201+
return -1;
202+
}
203+
204+
final String viewCount = getTextFromObject(viewCountObject);
198205

199206
return Long.parseLong(Utils.removeNonDigitCharacters(viewCount));
200-
} catch (NumberFormatException e) {
201-
return -1;
202207
} catch (Exception e) {
203208
throw new ParsingException("Could not get view count", e);
204209
}

0 commit comments

Comments
 (0)