Made published be an optional parameter

This commit is contained in:
RadoslavL 2023-11-08 19:09:16 +02:00
parent 76369eb599
commit a0d24190b8

View File

@ -6,7 +6,7 @@ require "json"
# #
# TODO: "compactRadioRenderer" (Mix) and # TODO: "compactRadioRenderer" (Mix) and
# TODO: Use a proper struct/class instead of a hacky JSON object # TODO: Use a proper struct/class instead of a hacky JSON object
def parse_related_video(related : JSON::Any, published) : Hash(String, JSON::Any)? def parse_related_video(related : JSON::Any, published : String? = nil) : Hash(String, JSON::Any)?
return nil if !related["videoId"]? return nil if !related["videoId"]?
# The compact renderer has video length in seconds, where the end # The compact renderer has video length in seconds, where the end
@ -47,7 +47,7 @@ def parse_related_video(related : JSON::Any, published) : Hash(String, JSON::Any
"view_count" => JSON::Any.new(view_count || "0"), "view_count" => JSON::Any.new(view_count || "0"),
"short_view_count" => JSON::Any.new(short_view_count || "0"), "short_view_count" => JSON::Any.new(short_view_count || "0"),
"author_verified" => JSON::Any.new(author_verified), "author_verified" => JSON::Any.new(author_verified),
"published" => published, "published" => JSON::Any.new(published || ""),
} }
end end
@ -238,11 +238,11 @@ def parse_video_info(video_id : String, player_response : Hash(String, JSON::Any
if item = element["compactVideoRenderer"]? if item = element["compactVideoRenderer"]?
if item["publishedTimeText"]? if item["publishedTimeText"]?
rv_decoded_time = decode_date(item["publishedTimeText"].to_s) rv_decoded_time = decode_date(item["publishedTimeText"].to_s)
rv_published_timestamp = JSON::Any.new(rv_decoded_time.to_unix.to_s) rv_published_timestamp = rv_decoded_time.to_unix.to_s
else else
rv_published_timestamp = JSON::Any.new("") rv_published_timestamp = nil
end end
related_video = parse_related_video(item, rv_published_timestamp) related_video = parse_related_video(item, published: rv_published_timestamp)
related << JSON::Any.new(related_video) if related_video related << JSON::Any.new(related_video) if related_video
end end
end end
@ -257,7 +257,7 @@ def parse_video_info(video_id : String, player_response : Hash(String, JSON::Any
player_overlays.try &.as_a.each do |element| player_overlays.try &.as_a.each do |element|
if item = element["endScreenVideoRenderer"]? if item = element["endScreenVideoRenderer"]?
related_video = parse_related_video(item, JSON::Any.new("")) related_video = parse_related_video(item)
related << JSON::Any.new(related_video) if related_video related << JSON::Any.new(related_video) if related_video
end end
end end