diff --git a/src/invidious/channels/channels.cr b/src/invidious/channels/channels.cr index 4fb92a502..b0a3084e8 100644 --- a/src/invidious/channels/channels.cr +++ b/src/invidious/channels/channels.cr @@ -199,7 +199,7 @@ private def update_all_channel_videos(ucid : String, channel : InvidiousChannel, videos = items.select(SearchVideo) update_channel_videos(ucid, videos, skip_recent: true) - break if videos.size < 25 + break if continuation.nil? sleep 500.milliseconds end end @@ -212,7 +212,7 @@ private def update_all_channel_shorts(ucid : String, channel : AboutChannel, con videos = items.select(SearchVideo) update_channel_videos(ucid, videos, skip_recent: true) - break if videos.size < 25 + break if continuation.nil? sleep 500.milliseconds end end @@ -225,7 +225,7 @@ private def update_all_channel_livestreams(ucid : String, channel : AboutChannel videos = items.select(SearchVideo) update_channel_videos(ucid, videos, skip_recent: true) - break if videos.size < 25 + break if continuation.nil? sleep 500.milliseconds end end @@ -281,17 +281,14 @@ private def fetch_video_published_at(video_id : String) : Time? return parse_video_published_at(published) end - date_text = response.dig?( - "contents", "twoColumnWatchNextResults", "results", "results", "contents", 0, - "videoPrimaryInfoRenderer", "dateText", "simpleText" - ).try(&.as_s) + date_text = response.dig?("contents", "twoColumnWatchNextResults", "results", "results", "contents") + .try &.as_a.find(&.["videoPrimaryInfoRenderer"]?) + .try &.dig?("videoPrimaryInfoRenderer", "dateText", "simpleText") + .try &.as_s return date_text.try do |text| - Time.parse(text.lchop("Scheduled for "), "%b %-d, %Y", Time::Location::UTC) + parse_video_published_date(text.lchop("Scheduled for ")) end -rescue ex - LOGGER.debug("fetch_video_published_at: #{video_id}: #{ex.message}") - return nil end private def parse_video_published_at(published : String) : Time @@ -299,3 +296,9 @@ private def parse_video_published_at(published : String) : Time rescue return Time.parse(published, "%Y-%m-%d", Time::Location::UTC) end + +private def parse_video_published_date(published : String) : Time? + return Time.parse(published, "%b %-d, %Y", Time::Location::UTC) +rescue + return nil +end diff --git a/src/invidious/database/channels.cr b/src/invidious/database/channels.cr index 0ff97fa07..79029d2ae 100644 --- a/src/invidious/database/channels.cr +++ b/src/invidious/database/channels.cr @@ -108,7 +108,7 @@ module Invidious::Database::ChannelVideos if preserve_timestamps_on_conflict published_on_conflict = "published = COALESCE(channel_videos.published, EXCLUDED.published)" views_on_conflict = "views = CASE WHEN EXCLUDED.views = 0 AND channel_videos.views > 0 THEN channel_videos.views ELSE EXCLUDED.views END" - updated_on_conflict = "updated = CASE WHEN channel_videos.title IS DISTINCT FROM EXCLUDED.title OR channel_videos.ucid IS DISTINCT FROM EXCLUDED.ucid OR channel_videos.author IS DISTINCT FROM EXCLUDED.author OR channel_videos.length_seconds IS DISTINCT FROM EXCLUDED.length_seconds OR channel_videos.live_now IS DISTINCT FROM EXCLUDED.live_now OR channel_videos.views IS DISTINCT FROM CASE WHEN EXCLUDED.views = 0 AND channel_videos.views > 0 THEN channel_videos.views ELSE EXCLUDED.views END THEN EXCLUDED.updated ELSE channel_videos.updated END" + updated_on_conflict = "updated = CASE WHEN channel_videos.title IS DISTINCT FROM EXCLUDED.title OR channel_videos.ucid IS DISTINCT FROM EXCLUDED.ucid OR channel_videos.author IS DISTINCT FROM EXCLUDED.author OR channel_videos.length_seconds IS DISTINCT FROM EXCLUDED.length_seconds OR channel_videos.live_now IS DISTINCT FROM EXCLUDED.live_now THEN EXCLUDED.updated ELSE channel_videos.updated END" else published_on_conflict = "published = $3" updated_on_conflict = "updated = $4"