Update sub_count extractor

This commit is contained in:
Omar Roth
2019-09-12 21:09:23 -04:00
parent 50d793e49b
commit b1fc80b79a
7 changed files with 16 additions and 34 deletions

View File

@@ -415,13 +415,8 @@ def extract_items(nodeset, ucid = nil, author_name = nil)
author_thumbnail ||= ""
subscriber_count_text = node.xpath_node(%q(.//span[contains(@class, "yt-subscriber-count")])).try &.["title"]
begin
subscriber_count = subscriber_count_text.try { |text| short_text_to_number(text) }
rescue ex
subscriber_count = subscriber_count_text.try &.gsub(/\D/, "").to_i?
end
subscriber_count ||= 0
subscriber_count = node.xpath_node(%q(.//span[contains(@class, "subscriber-count")]))
.try &.["title"].try { |text| short_text_to_number(text) } || 0
video_count = node.xpath_node(%q(.//ul[@class="yt-lockup-meta-info"]/li)).try &.content.split(" ")[0].gsub(/\D/, "").to_i?

View File

@@ -157,7 +157,7 @@ def number_with_separator(number)
number.to_s.reverse.gsub(/(\d{3})(?=\d)/, "\\1,").reverse
end
def short_text_to_number(short_text)
def short_text_to_number(short_text : String) : Int32
case short_text
when .ends_with? "M"
number = short_text.rstrip(" mM").to_f