diff options
| author | Samantaz Fox <coding@samantaz.fr> | 2022-02-03 00:57:44 +0100 |
|---|---|---|
| committer | Samantaz Fox <coding@samantaz.fr> | 2022-02-03 01:37:30 +0100 |
| commit | 9621175dc91d8f410dbc14d09bc0132e6a33ae6d (patch) | |
| tree | 1795b0afbec3f5d8fb43618c74b7a15410fc7b39 /src | |
| parent | e6ddd6d6c1f649f43c5906f1090d800f619f37fd (diff) | |
| download | invidious-9621175dc91d8f410dbc14d09bc0132e6a33ae6d.tar.gz invidious-9621175dc91d8f410dbc14d09bc0132e6a33ae6d.tar.bz2 invidious-9621175dc91d8f410dbc14d09bc0132e6a33ae6d.zip | |
extractors: Add helper for short view count text
Diffstat (limited to 'src')
| -rw-r--r-- | src/invidious/yt_backend/extractors.cr | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/invidious/yt_backend/extractors.cr b/src/invidious/yt_backend/extractors.cr index 27ce550b..41d95962 100644 --- a/src/invidious/yt_backend/extractors.cr +++ b/src/invidious/yt_backend/extractors.cr @@ -519,6 +519,20 @@ module HelperExtractors end end + # Retrieves the amount of views/viewers a video has. + # Seems to be used on related videos only + # + # Returns "0" when unable to parse + def self.get_short_view_count(container : JSON::Any) : String + box = container["shortViewCountText"]? + return "0" if !box + + # Simpletext: "4M views" + # runs: {"text": "1.1K"},{"text":" watching"} + return box["simpleText"]?.try &.as_s.sub(" views", "") || + box.dig?("runs", 0, "text").try &.as_s || "0" + end + # Retrieve lowest quality thumbnail from InnerTube data # # TODO allow configuration of image quality (-1 is highest) |
