summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/invidious/helpers/utils.cr2
-rw-r--r--src/invidious/yt_backend/extractors.cr16
2 files changed, 16 insertions, 2 deletions
diff --git a/src/invidious/helpers/utils.cr b/src/invidious/helpers/utils.cr
index ed0cca38..72fdb187 100644
--- a/src/invidious/helpers/utils.cr
+++ b/src/invidious/helpers/utils.cr
@@ -162,7 +162,7 @@ def number_with_separator(number)
end
def short_text_to_number(short_text : String) : Int64
- matches = /(?<number>\d+(\.\d+)?)\s?(?<suffix>[mMkKbB])?/.match(short_text)
+ matches = /(?<number>\d+(\.\d+)?)\s?(?<suffix>[mMkKbB]?)/.match(short_text)
number = matches.try &.["number"].to_f || 0.0
case matches.try &.["suffix"].downcase
diff --git a/src/invidious/yt_backend/extractors.cr b/src/invidious/yt_backend/extractors.cr
index 65d107b2..b14ad7b9 100644
--- a/src/invidious/yt_backend/extractors.cr
+++ b/src/invidious/yt_backend/extractors.cr
@@ -172,7 +172,17 @@ private module Parsers
# When public subscriber count is disabled, the subscriberCountText isn't sent by InnerTube.
# Always simpleText
# TODO change default value to nil
+
subscriber_count = item_contents.dig?("subscriberCountText", "simpleText")
+
+ # Since youtube added channel handles, `VideoCountText` holds the number of
+ # subscribers and `subscriberCountText` holds the handle, except when the
+ # channel doesn't have a handle (e.g: some topic music channels).
+ # See https://github.com/iv-org/invidious/issues/3394#issuecomment-1321261688
+ if !subscriber_count || !subscriber_count.as_s.includes? " subscriber"
+ subscriber_count = item_contents.dig?("videoCountText", "simpleText")
+ end
+ subscriber_count = subscriber_count
.try { |s| short_text_to_number(s.as_s.split(" ")[0]).to_i32 } || 0
# Auto-generated channels doesn't have videoCountText
@@ -682,7 +692,11 @@ module HelperExtractors
# Returns a 0 when it's unable to do so
def self.get_video_count(container : JSON::Any) : Int32
if box = container["videoCountText"]?
- return extract_text(box).try &.gsub(/\D/, "").to_i || 0
+ if (extracted_text = extract_text(box)) && !extracted_text.includes? " subscriber"
+ return extracted_text.gsub(/\D/, "").to_i
+ else
+ return 0
+ end
elsif box = container["videoCount"]?
return box.as_s.to_i
else