Fix channel redirect

This commit is contained in:
Omar Roth 2020-01-14 08:21:17 -05:00
parent 9bdfd6025b
commit 7baced75e5
No known key found for this signature in database
GPG Key ID: B8254FB7EC3D37F2
1 changed files with 6 additions and 10 deletions

View File

@ -2602,13 +2602,9 @@ post "/data_control" do |env|
next match["channel"] next match["channel"]
elsif match = channel["url"].as_s.match(/\/user\/(?<user>.+)/) elsif match = channel["url"].as_s.match(/\/user\/(?<user>.+)/)
response = YT_POOL.client &.get("/user/#{match["user"]}?disable_polymer=1&hl=en&gl=US") response = YT_POOL.client &.get("/user/#{match["user"]}?disable_polymer=1&hl=en&gl=US")
document = XML.parse_html(response.body) html = XML.parse_html(response.body)
canonical = document.xpath_node(%q(//link[@rel="canonical"])) ucid = html.xpath_node(%q(//link[@rel="canonical"])).try &.["href"].split("/")[-1]
next ucid if ucid
if canonical
ucid = canonical["href"].split("/")[-1]
next ucid
end
end end
nil nil
@ -5873,7 +5869,7 @@ error 404 do |env|
response = YT_POOL.client &.get("/#{item}") response = YT_POOL.client &.get("/#{item}")
if response.status_code == 301 if response.status_code == 301
response = YT_POOL.client &.get(response.headers["Location"]) response = YT_POOL.client &.get(URI.parse(response.headers["Location"]).full_path)
end end
if response.body.empty? if response.body.empty?
@ -5882,10 +5878,10 @@ error 404 do |env|
end end
html = XML.parse_html(response.body) html = XML.parse_html(response.body)
ucid = html.xpath_node(%q(//meta[@itemprop="channelId"])) ucid = html.xpath_node(%q(//link[@rel="canonical"])).try &.["href"].split("/")[-1]
if ucid if ucid
env.response.headers["Location"] = "/channel/#{ucid["content"]}" env.response.headers["Location"] = "/channel/#{ucid}"
halt env, status_code: 302 halt env, status_code: 302
end end