Invidious is an alternative front-end to YouTube
Fix 0 view count on related videos section (#5446)
shiny-comic5cfe294063c9
diff --git a/spec/invidious/videos/regular_videos_extract_spec.cr b/spec/invidious/videos/regular_videos_extract_spec.crindex f96703f6..b82a08ee 100644--- a/spec/invidious/videos/regular_videos_extract_spec.cr+++ b/spec/invidious/videos/regular_videos_extract_spec.cr@@ -52,7 +52,6 @@ Spectator.describe "parse_video_info" doexpect(info["relatedVideos"][0]["title"]).to eq("$1 vs $250,000,000 Private Island!")expect(info["relatedVideos"][0]["author"]).to eq("MrBeast")expect(info["relatedVideos"][0]["ucid"]).to eq("UCX6OQ3DkcsbYNE6H8uQQuVA")- expect(info["relatedVideos"][0]["view_count"]).to eq("230617484")expect(info["relatedVideos"][0]["short_view_count"]).to eq("230M")expect(info["relatedVideos"][0]["author_verified"]).to eq("true")@@ -138,7 +137,6 @@ Spectator.describe "parse_video_info" doexpect(info["relatedVideos"][0]["title"]).to eq("Chris Rea - The Road To Hell 1989 Full Version")expect(info["relatedVideos"][0]["author"]).to eq("NEA ZIXNH")expect(info["relatedVideos"][0]["ucid"]).to eq("UCYMEOGcvav3gCgImK2J07CQ")- expect(info["relatedVideos"][0]["view_count"]).to eq("53298661")expect(info["relatedVideos"][0]["short_view_count"]).to eq("53M")expect(info["relatedVideos"][0]["author_verified"]).to eq("false")diff --git a/spec/invidious/videos/scheduled_live_extract_spec.cr b/spec/invidious/videos/scheduled_live_extract_spec.crindex c3a9b228..6bb03e42 100644--- a/spec/invidious/videos/scheduled_live_extract_spec.cr+++ b/spec/invidious/videos/scheduled_live_extract_spec.cr@@ -75,7 +75,6 @@ Spectator.describe "parse_video_info" doexpect(info["relatedVideos"][0]["id"]).to eq("j7jPzzjbVuk")expect(info["relatedVideos"][0]["author"]).to eq("Democracy Now!")expect(info["relatedVideos"][0]["ucid"]).to eq("UCzuqE7-t13O4NIDYJfakrhw")- expect(info["relatedVideos"][0]["view_count"]).to eq("7576")expect(info["relatedVideos"][0]["short_view_count"]).to eq("7.5K")expect(info["relatedVideos"][0]["author_verified"]).to eq("true")diff --git a/src/invidious/jsonify/api_v1/video_json.cr b/src/invidious/jsonify/api_v1/video_json.crindex 58805af2..ff9ea70a 100644--- a/src/invidious/jsonify/api_v1/video_json.cr+++ b/src/invidious/jsonify/api_v1/video_json.cr@@ -266,7 +266,6 @@ module Invidious::JSONify::APIv1json.field "lengthSeconds", rv["length_seconds"]?.try &.to_ijson.field "viewCountText", rv["short_view_count"]?- json.field "viewCount", rv["view_count"]?.try &.empty? ? nil : rv["view_count"].to_i64json.field "published", rv["published"]?if rv["published"]?.try &.presencejson.field "publishedText", translate(locale, "`x` ago", recode_date(Time.parse_rfc3339(rv["published"].to_s), locale))diff --git a/src/invidious/videos/parser.cr b/src/invidious/videos/parser.crindex 6b1dedd6..6038dfcf 100644--- a/src/invidious/videos/parser.cr+++ b/src/invidious/videos/parser.cr@@ -25,11 +25,6 @@ def parse_related_video(related : JSON::Any) : Hash(String, JSON::Any)?ucid = channel_info.try { |ci| HelperExtractors.get_browse_id(ci) }- # "4,088,033 views", only available on compact renderer- # and when video is not a livestream- view_count = related.dig?("viewCountText", "simpleText")- .try &.as_s.gsub(/\D/, "")-short_view_count = related.try do |r|HelperExtractors.get_short_view_count(r).to_send@@ -51,7 +46,6 @@ def parse_related_video(related : JSON::Any) : Hash(String, JSON::Any)?"author" => author || JSON::Any.new(""),"ucid" => JSON::Any.new(ucid || ""),"length_seconds" => JSON::Any.new(length || "0"),- "view_count" => JSON::Any.new(view_count || "0"),"short_view_count" => JSON::Any.new(short_view_count || "0"),"author_verified" => JSON::Any.new(author_verified),"published" => JSON::Any.new(published || ""),diff --git a/src/invidious/views/watch.ecr b/src/invidious/views/watch.ecrindex 59b9a167..89632dc5 100644--- a/src/invidious/views/watch.ecr+++ b/src/invidious/views/watch.ecr@@ -355,9 +355,8 @@ we're going to need to do it here in order to allow for translations.<div class="pure-u-10-24" style="text-align:right"><b class="width:100%"><%=- views = rv["view_count"]?.try &.to_i?- views ||= rv["view_count_short"]?.try { |x| short_text_to_number(x) }- translate_count(locale, "generic_views_count", views || 0, NumberFormatting::Short)+ views = short_text_to_number(rv["short_view_count"]? || "0")+ translate_count(locale, "generic_views_count", views, NumberFormatting::Short)%></b></div></h5>