diff options
| author | Omar Roth <omarroth@hotmail.com> | 2019-03-27 05:28:53 -0500 |
|---|---|---|
| committer | Omar Roth <omarroth@hotmail.com> | 2019-03-27 05:28:53 -0500 |
| commit | 9239cfb3c1f35ddc2ee4f3ce7c4259cb7e2b23c2 (patch) | |
| tree | ff2f19632c128a57200017c12870ba74c97d5e7b | |
| parent | 6fd24ad54fc39ced6d76bcc01cfbcfc6563bb81e (diff) | |
| download | invidious-9239cfb3c1f35ddc2ee4f3ce7c4259cb7e2b23c2.tar.gz invidious-9239cfb3c1f35ddc2ee4f3ce7c4259cb7e2b23c2.tar.bz2 invidious-9239cfb3c1f35ddc2ee4f3ce7c4259cb7e2b23c2.zip | |
Fix redirect for shortened video urls
| -rw-r--r-- | src/invidious.cr | 36 |
1 files changed, 16 insertions, 20 deletions
diff --git a/src/invidious.cr b/src/invidious.cr index b5823513..98f9bc66 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(/^\/(?<id>[a-zA-Z0-9_-]{11})$/) + if md = env.request.path.match(/^\/(?<id>([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(/^\/(?<name>\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 |
