diff --git a/src/invidious/routes/video_playback.cr b/src/invidious/routes/video_playback.cr index 17b1022a..405e733b 100644 --- a/src/invidious/routes/video_playback.cr +++ b/src/invidious/routes/video_playback.cr @@ -253,7 +253,7 @@ module Invidious::Routes::VideoPlayback # YouTube /videoplayback links expire after 6 hours, # so we have a mechanism here to redirect to the latest version def self.latest_version(env) - if !CONFIG.invidious_companion.empty? && CONFIG.disabled?("downloads") + if !CONFIG.invidious_companion.empty? return error_template(403, "This endpoint is not permitted because it is handled by Invidious companion.") end @@ -298,9 +298,6 @@ module Invidious::Routes::VideoPlayback end if local - if (!CONFIG.invidious_companion.empty?) - return env.redirect "#{video.invidious_companion.not_nil!["baseUrl"].as_s}#{env.request.path}?#{env.request.query}" - end url = URI.parse(url).request_target.not_nil! url += "&title=#{URI.encode_www_form(title, space_to_plus: false)}" if title end diff --git a/src/invidious/routes/watch.cr b/src/invidious/routes/watch.cr index 69780d78..740a15b2 100644 --- a/src/invidious/routes/watch.cr +++ b/src/invidious/routes/watch.cr @@ -328,13 +328,20 @@ module Invidious::Routes::Watch return Invidious::Routes::API::V1::Videos.captions(env) elsif itag = download_widget["itag"]?.try &.as_i + itag = itag.to_s + # URL params specific to /latest_version env.params.query["id"] = video_id - env.params.query["itag"] = itag.to_s + env.params.query["itag"] = itag env.params.query["title"] = filename env.params.query["local"] = "true" - return Invidious::Routes::VideoPlayback.latest_version(env) + if (!CONFIG.invidious_companion.empty?) + video = get_video(video_id) + return env.redirect "#{video.invidious_companion.not_nil!["baseUrl"].as_s}/latest_version?id=#{video_id}&itag=#{itag}&local=true" + else + return Invidious::Routes::VideoPlayback.latest_version(env) + end else return error_template(400, "Invalid label or itag") end