From 6f9056fd8473cf227b1ab572c3d75cbbb79c094e Mon Sep 17 00:00:00 2001 From: Omar Roth Date: Sat, 6 Oct 2018 22:19:36 -0500 Subject: [PATCH] Add extra handling for shortened video URLs --- src/invidious.cr | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/invidious.cr b/src/invidious.cr index 5526b089..e6130f34 100644 --- a/src/invidious.cr +++ b/src/invidious.cr @@ -3437,6 +3437,24 @@ get "/vi/:id/:name" do |env| end error 404 do |env| + if md = env.request.path.match(/^\/(?[a-zA-Z0-9_-]{11})/) + id = md["id"] + + params = [] of String + env.params.query.each do |k, v| + params << "#{k}=#{v}" + end + params = params.join("&") + + url = "/watch?v=#{id}" + if !params.empty? + url += "&#{params}" + end + + env.response.headers["Location"] = url + halt env, status_code: 302 + end + error_message = "404 Page not found" templated "error" end