From 80a567bf1ecaa4dc141294c426bf0a92638a1fd1 Mon Sep 17 00:00:00 2001 From: Omar Roth Date: Fri, 12 Apr 2019 16:37:35 -0500 Subject: [PATCH] Fix video count in playlist extractor --- src/invidious/helpers/helpers.cr | 8 ++++---- src/invidious/playlists.cr | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/invidious/helpers/helpers.cr b/src/invidious/helpers/helpers.cr index 574f1184..a2ea9f7a 100644 --- a/src/invidious/helpers/helpers.cr +++ b/src/invidious/helpers/helpers.cr @@ -241,7 +241,7 @@ def extract_items(nodeset, ucid = nil, author_name = nil) video_count = video_count.rchop("+") end - video_count = video_count.to_i? + video_count = video_count.gsub(/\D/, "").to_i? end video_count ||= 0 @@ -301,10 +301,10 @@ def extract_items(nodeset, ucid = nil, author_name = nil) author_thumbnail ||= "" - subscriber_count = node.xpath_node(%q(.//span[contains(@class, "yt-subscriber-count")])).try &.["title"].delete(",").to_i? + subscriber_count = node.xpath_node(%q(.//span[contains(@class, "yt-subscriber-count")])).try &.["title"].gsub(/\D/, "").to_i? subscriber_count ||= 0 - video_count = node.xpath_node(%q(.//ul[@class="yt-lockup-meta-info"]/li)).try &.content.split(" ")[0].delete(",").to_i? + video_count = node.xpath_node(%q(.//ul[@class="yt-lockup-meta-info"]/li)).try &.content.split(" ")[0].gsub(/\D/, "").to_i? video_count ||= 0 items << SearchChannel.new( @@ -466,7 +466,7 @@ def extract_shelf_items(nodeset, ucid = nil, author_name = nil) video_count_label = child_node.xpath_node(%q(.//span[@class="formatted-video-count-label"])) if video_count_label - video_count = video_count_label.content.strip.match(/^\d+/).try &.[0].to_i? + video_count = video_count_label.content.gsub(/\D/, "").to_i? end video_count ||= 50 diff --git a/src/invidious/playlists.cr b/src/invidious/playlists.cr index d04a5942..73c9ac69 100644 --- a/src/invidious/playlists.cr +++ b/src/invidious/playlists.cr @@ -196,7 +196,7 @@ def fetch_playlist(plid, locale) author_thumbnail ||= "" ucid = anchor.xpath_node(%q(.//li[1]/a)).not_nil!["href"].split("/")[-1] - video_count = anchor.xpath_node(%q(.//li[2])).not_nil!.content.delete("videos, ").to_i + video_count = anchor.xpath_node(%q(.//li[2])).not_nil!.content.gsub(/\D/, "").to_i views = anchor.xpath_node(%q(.//li[3])).not_nil!.content.delete("No views, ") if views.empty? views = 0_i64