[YouTube] Take into account videos that have their views hidden

Also remove catch because it may hide bugs when the page changes.
This commit is contained in:
Mauricio Colli 2020-02-29 18:01:43 -03:00 committed by TobiGr
parent f66c20de54
commit da2c562eb0

View file

@ -194,11 +194,16 @@ public class YoutubeStreamInfoItemExtractor implements StreamInfoItemExtractor {
if (videoInfo.getObject("topStandaloneBadge") != null || isPremium()) {
return -1;
}
String viewCount = getTextFromObject(videoInfo.getObject("viewCountText"));
final JsonObject viewCountObject = videoInfo.getObject("viewCountText");
if (viewCountObject == null) {
// This object is null when a video has its views hidden.
return -1;
}
final String viewCount = getTextFromObject(viewCountObject);
return Long.parseLong(Utils.removeNonDigitCharacters(viewCount));
} catch (NumberFormatException e) {
return -1;
} catch (Exception e) {
throw new ParsingException("Could not get view count", e);
}