diff --git a/src/invidious.cr b/src/invidious.cr index b58235132..98f9bc663 100644 --- a/src/invidious.cr +++ b/src/invidious.cr @@ -4368,9 +4368,24 @@ get "/vi/:id/:name" do |env| end error 404 do |env| - if md = env.request.path.match(/^\/(?[a-zA-Z0-9_-]{11})$/) + if md = env.request.path.match(/^\/(?([a-zA-Z0-9_-]{11})|(\w+))$/) id = md["id"] + client = make_client(YT_URL) + response = client.get("/#{id}") + + if response.status_code == 301 + response = client.get(response.headers["Location"]) + end + + html = XML.parse_html(response.body) + ucid = html.xpath_node(%q(//meta[@itemprop="channelId"])) + + if ucid + env.response.headers["Location"] = "/channel/#{ucid["content"]}" + halt env, status_code: 302 + end + params = [] of String env.params.query.each do |k, v| params << "#{k}=#{v}" @@ -4389,25 +4404,6 @@ error 404 do |env| end end - if md = env.request.path.match(/^\/(?\w+)$/) - name = md["name"] - - client = make_client(YT_URL) - response = client.get("/#{name}") - - if response.status_code == 301 - response = client.get(response.headers["Location"]) - end - - html = XML.parse_html(response.body) - ucid = html.xpath_node(%q(//meta[@itemprop="channelId"])) - - if ucid - env.response.headers["Location"] = "/channel/#{ucid["content"]}" - halt env, status_code: 302 - end - end - env.response.headers["Location"] = "/" halt env, status_code: 302 end