Invidious is an alternative front-end to YouTube
Moved code around and fixed a problem
RadoslavL68611482906f
diff --git a/src/invidious/jsonify/api_v1/video_json.cr b/src/invidious/jsonify/api_v1/video_json.crindex f5450f3f..622641ee 100644--- a/src/invidious/jsonify/api_v1/video_json.cr+++ b/src/invidious/jsonify/api_v1/video_json.cr@@ -246,7 +246,7 @@ module Invidious::JSONify::APIv1json.field "viewCountText", rv["short_view_count"]?json.field "viewCount", rv["view_count"]?.try &.empty? ? nil : rv["view_count"].to_i64json.field "published", rv["published"]?- json.field "publishedTimeText", translate(locale, "`x` ago", rv["publishedText"].to_s)+ json.field "publishedTimeText", translate(locale, "`x` ago", rv["publishedText"].to_s.gsub(" ago", ""))endendenddiff --git a/src/invidious/videos/parser.cr b/src/invidious/videos/parser.crindex 279daf37..9275b1bb 100644--- a/src/invidious/videos/parser.cr+++ b/src/invidious/videos/parser.cr@@ -6,7 +6,7 @@ require "json"## TODO: "compactRadioRenderer" (Mix) and# TODO: Use a proper struct/class instead of a hacky JSON object-def parse_related_video(related : JSON::Any, published : String? = nil) : Hash(String, JSON::Any)?+def parse_related_video(related : JSON::Any) : Hash(String, JSON::Any)?return nil if !related["videoId"]?# The compact renderer has video length in seconds, where the end@@ -36,11 +36,12 @@ def parse_related_video(related : JSON::Any, published : String? = nil) : Hash(SLOGGER.trace("parse_related_video: Found \"watchNextEndScreenRenderer\" container")- publishedText = related["publishedTimeText"]?- if !publishedText.nil?- publishedSimpleText = publishedText["simpleText"].to_s+ if published_time_text = related["publishedTimeText"]?+ decoded_time = decode_date(published_time_text["simpleText"].to_s)+ published = decoded_time.to_unix.to_s+ published_time_text = published_time_text["simpleText"].to_selse- publishedSimpleText = nil+ published = nilend# TODO: when refactoring video types, make a struct for related videos@@ -55,7 +56,7 @@ def parse_related_video(related : JSON::Any, published : String? = nil) : Hash(S"short_view_count" => JSON::Any.new(short_view_count || "0"),"author_verified" => JSON::Any.new(author_verified),"published" => JSON::Any.new(published || ""),- "publishedText" => JSON::Any.new(publishedSimpleText || ""),+ "publishedText" => JSON::Any.new(published_time_text || ""),}end@@ -244,13 +245,7 @@ def parse_video_info(video_id : String, player_response : Hash(String, JSON::Any.dig?("secondaryResults", "secondaryResults", "results")secondary_results.try &.as_a.each do |element|if item = element["compactVideoRenderer"]?- if rv_published_time_text = item["publishedTimeText"]?- rv_decoded_time = decode_date(rv_published_time_text["simpleText"].to_s)- rv_published_timestamp = rv_decoded_time.to_unix.to_s- else- rv_published_timestamp = nil- end- related_video = parse_related_video(item, published: rv_published_timestamp)+ related_video = parse_related_video(item)related << JSON::Any.new(related_video) if related_videoendend