Skip to content

Commit 9621175

Browse files
committed
extractors: Add helper for short view count text
1 parent e6ddd6d commit 9621175

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/invidious/yt_backend/extractors.cr

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,20 @@ module HelperExtractors
519519
end
520520
end
521521

522+
# Retrieves the amount of views/viewers a video has.
523+
# Seems to be used on related videos only
524+
#
525+
# Returns "0" when unable to parse
526+
def self.get_short_view_count(container : JSON::Any) : String
527+
box = container["shortViewCountText"]?
528+
return "0" if !box
529+
530+
# Simpletext: "4M views"
531+
# runs: {"text": "1.1K"},{"text":" watching"}
532+
return box["simpleText"]?.try &.as_s.sub(" views", "") ||
533+
box.dig?("runs", 0, "text").try &.as_s || "0"
534+
end
535+
522536
# Retrieve lowest quality thumbnail from InnerTube data
523537
#
524538
# TODO allow configuration of image quality (-1 is highest)

0 commit comments

Comments
 (0)