mirror of
https://github.com/iv-org/invidious.git
synced 2024-10-01 01:35:38 -04:00
Search: Fix ArithmeticOverflow + wrong subs count issues (#3535)
This commit is contained in:
commit
dbee027ed9
@ -162,7 +162,7 @@ def number_with_separator(number)
|
|||||||
end
|
end
|
||||||
|
|
||||||
def short_text_to_number(short_text : String) : Int64
|
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
|
number = matches.try &.["number"].to_f || 0.0
|
||||||
|
|
||||||
case matches.try &.["suffix"].downcase
|
case matches.try &.["suffix"].downcase
|
||||||
|
@ -172,7 +172,17 @@ private module Parsers
|
|||||||
# When public subscriber count is disabled, the subscriberCountText isn't sent by InnerTube.
|
# When public subscriber count is disabled, the subscriberCountText isn't sent by InnerTube.
|
||||||
# Always simpleText
|
# Always simpleText
|
||||||
# TODO change default value to nil
|
# TODO change default value to nil
|
||||||
|
|
||||||
subscriber_count = item_contents.dig?("subscriberCountText", "simpleText")
|
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
|
.try { |s| short_text_to_number(s.as_s.split(" ")[0]).to_i32 } || 0
|
||||||
|
|
||||||
# Auto-generated channels doesn't have videoCountText
|
# Auto-generated channels doesn't have videoCountText
|
||||||
@ -682,7 +692,11 @@ module HelperExtractors
|
|||||||
# Returns a 0 when it's unable to do so
|
# Returns a 0 when it's unable to do so
|
||||||
def self.get_video_count(container : JSON::Any) : Int32
|
def self.get_video_count(container : JSON::Any) : Int32
|
||||||
if box = container["videoCountText"]?
|
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"]?
|
elsif box = container["videoCount"]?
|
||||||
return box.as_s.to_i
|
return box.as_s.to_i
|
||||||
else
|
else
|
||||||
|
Loading…
Reference in New Issue
Block a user