From 11c932c080ffd1b6e6401ad5aad760d5fe996aa2 Mon Sep 17 00:00:00 2001 From: chunky programmer <78101139+ChunkyProgrammer@users.noreply.github.com> Date: Wed, 19 Apr 2023 22:14:54 -0400 Subject: [PATCH] Fix live and upcoming community videos --- src/invidious/channels/community.cr | 30 +++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/src/invidious/channels/community.cr b/src/invidious/channels/community.cr index ce34ff82..a5ae1c55 100644 --- a/src/invidious/channels/community.cr +++ b/src/invidious/channels/community.cr @@ -146,7 +146,11 @@ def fetch_channel_community(ucid, continuation, locale, format, thin_mode) Invidious::JSONify::APIv1.thumbnails(json, video_id) end - json.field "lengthSeconds", decode_length_seconds(attachment["lengthText"]["simpleText"].as_s) + if length_text = attachment.dig?("lengthText", "simpleText").try &.as_s + json.field "lengthSeconds", decode_length_seconds(length_text) + else + json.field "lengthSeconds", 0 + end author_info = attachment["ownerText"]["runs"][0].as_h @@ -155,14 +159,28 @@ def fetch_channel_community(ucid, continuation, locale, format, thin_mode) json.field "authorUrl", author_info["navigationEndpoint"]["commandMetadata"]["webCommandMetadata"]["url"] # TODO: json.field "authorThumbnails", "channelThumbnailSupportedRenderers" - # TODO: json.field "authorVerified", "ownerBadges" + json.field "authorVerified", has_verified_badge?(attachment["ownerBadges"]?).to_s - published = decode_date(attachment["publishedTimeText"]["simpleText"].as_s) + if published_time_text = attachment.dig?("publishedTimeText", "simpleText").try &.as_s + published = decode_date(published_time_text) + json.field "published", published.to_unix + json.field "publishedText", translate(locale, "`x` ago", recode_date(published, locale)) + else + json.field "published", 0 + json.field "publishedText", "" + end - json.field "published", published.to_unix - json.field "publishedText", translate(locale, "`x` ago", recode_date(published, locale)) + if thumbnail_overlay = attachment.dig?("thumbnailOverlays", 0, "thumbnailOverlayTimeStatusRenderer") + overlay_style = thumbnail_overlay["style"].as_s + json.field "liveNow", overlay_style == "LIVE" + json.field "isUpcoming", overlay_style == "UPCOMING" + else + json.field "liveNow", false + json.field "isUpcoming", false + end - view_count = attachment["viewCountText"]?.try &.["simpleText"].as_s.gsub(/\D/, "").to_i64? || 0_i64 + view_count = attachment.dig?("viewCountText", "simpleText").try &.as_s.gsub(/\D/, "").to_i64? + view_count ||= attachment.dig?("viewCountText", "runs", 0, "text").try &.as_s.gsub(/\D/, "").to_i64? || 0_i64 json.field "viewCount", view_count json.field "viewCountText", translate_count(locale, "generic_views_count", view_count, NumberFormatting::Short)