From e96ad036ca7f69edbf0936922afb15e9c32f642e Mon Sep 17 00:00:00 2001 From: Fijxu Date: Sat, 30 May 2026 15:49:21 -0400 Subject: [PATCH] fix: Do not append query params `quality=medium` to videos that are about to premiere (#5755) * fix: Do not append query params `quality=medium` to videos that are about to premiere Video premieres do not have `audio_streams` and they aren't `video.live_now == true` either, therefore we skip the checks that are made for older videos (`if audio_streams.empty? && !video.live_now` closure) if the video is a premiere. This commit also adds the `microformat` field to the `info` instance variable of the `Video` struct, since it's needed for the function `Video#premiere_timestamp : Time?`. This is more like a quick fix than a proper fix because in `Invidious::Videos::Parser#parse_video_info`, `premiere_timestamp` is gathered from the `microformat` JSON Object but is used to set the `published` hash key for the `params` variable. The parsers and structs really need a rework :/ * Revert "fix: Do not append query params `quality=medium` to videos that are about to premiere" This reverts commit 5cfc8dace82590ea6a41c849c9c39b1b7ba95fe7. * chore: build premiere_timestamp using video_type and published time --- src/invidious/routes/watch.cr | 25 ++++++++++++++----------- src/invidious/videos.cr | 7 ++++--- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/invidious/routes/watch.cr b/src/invidious/routes/watch.cr index 8f244e92..7a68a145 100644 --- a/src/invidious/routes/watch.cr +++ b/src/invidious/routes/watch.cr @@ -129,17 +129,20 @@ module Invidious::Routes::Watch video_streams = video.video_streams audio_streams = video.audio_streams - # Older videos may not have audio sources available. - # We redirect here so they're not unplayable - if audio_streams.empty? && !video.live_now - if params.quality == "dash" - env.params.query.delete_all("quality") - env.params.query["quality"] = "medium" - return env.redirect "/watch?#{env.params.query}" - elsif params.listen - env.params.query.delete_all("listen") - env.params.query["listen"] = "0" - return env.redirect "/watch?#{env.params.query}" + # Videos that are a premiere do not have audio streams. + if video.premiere_timestamp.nil? + # Older videos may not have audio sources available. + # We redirect here so they're not unplayable + if audio_streams.empty? && !video.live_now + if params.quality == "dash" + env.params.query.delete_all("quality") + env.params.query["quality"] = "medium" + return env.redirect "/watch?#{env.params.query}" + elsif params.listen + env.params.query.delete_all("listen") + env.params.query["listen"] = "0" + return env.redirect "/watch?#{env.params.query}" + end end end diff --git a/src/invidious/videos.cr b/src/invidious/videos.cr index 5b778725..99713d18 100644 --- a/src/invidious/videos.cr +++ b/src/invidious/videos.cr @@ -81,9 +81,10 @@ struct Video end def premiere_timestamp : Time? - info - .dig?("microformat", "playerMicroformatRenderer", "liveBroadcastDetails", "startTimestamp") - .try { |t| Time.parse_rfc3339(t.as_s) } + if self.video_type == VideoType::Scheduled + return info["published"]? + .try { |t| Time.parse_rfc3339(t.as_s) } + end end def related_videos