Fixed an issue

This commit is contained in:
RadoslavL 2023-11-14 09:43:52 +02:00
parent 50da6cf3e7
commit 2a6a32e667
2 changed files with 8 additions and 7 deletions

View File

@ -246,7 +246,7 @@ module Invidious::JSONify::APIv1
json.field "viewCountText", rv["short_view_count"]?
json.field "viewCount", rv["view_count"]?.try &.empty? ? nil : rv["view_count"].to_i64
json.field "published", rv["published"]?
json.field "publishedTimeText", rv["publishedText"]?
json.field "publishedTimeText", translate(locale, "`x` ago", rv["publishedText"].to_s)
end
end
end

View File

@ -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, publishedText : String? = nil) : Hash(String, JSON::Any)?
def parse_related_video(related : JSON::Any, published : String? = nil) : Hash(String, JSON::Any)?
return nil if !related["videoId"]?
# The compact renderer has video length in seconds, where the end
@ -36,6 +36,8 @@ def parse_related_video(related : JSON::Any, published : String? = nil, publishe
LOGGER.trace("parse_related_video: Found \"watchNextEndScreenRenderer\" container")
publishedText = related["publishedTimeText"]["simpleText"].to_s
# TODO: when refactoring video types, make a struct for related videos
# or reuse an existing type, if that fits.
return {
@ -48,7 +50,7 @@ def parse_related_video(related : JSON::Any, published : String? = nil, publishe
"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(translate(locale, "`x` ago", recode_date(video.published, locale)) || ""),
"publishedText" => JSON::Any.new(publishedText || ""),
}
end
@ -237,14 +239,13 @@ 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_published_time_text = rv_published_time_text.as_s
rv_decoded_time = decode_date(rv_published_time_text)
if rv_published_time_text = item["publishedTimeText"]["simpleText"]?
rv_decoded_time = decode_date(rv_published_time_text.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, publishedText: rv_published_time_text)
related_video = parse_related_video(item, published: rv_published_timestamp)
related << JSON::Any.new(related_video) if related_video
end
end