mirror of
https://github.com/iv-org/invidious.git
synced 2024-12-27 18:40:21 +05:30
Fix redirect for shortened video urls
This commit is contained in:
parent
6fd24ad54f
commit
9239cfb3c1
@ -4368,9 +4368,24 @@ get "/vi/:id/:name" do |env|
|
|||||||
end
|
end
|
||||||
|
|
||||||
error 404 do |env|
|
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"]
|
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
|
params = [] of String
|
||||||
env.params.query.each do |k, v|
|
env.params.query.each do |k, v|
|
||||||
params << "#{k}=#{v}"
|
params << "#{k}=#{v}"
|
||||||
@ -4389,25 +4404,6 @@ error 404 do |env|
|
|||||||
end
|
end
|
||||||
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"] = "/"
|
env.response.headers["Location"] = "/"
|
||||||
halt env, status_code: 302
|
halt env, status_code: 302
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user