diff options
| author | Omar Roth <omarroth@protonmail.com> | 2020-01-14 08:21:17 -0500 |
|---|---|---|
| committer | Omar Roth <omarroth@protonmail.com> | 2020-01-14 08:21:17 -0500 |
| commit | 7baced75e555f094daaff3bfb06e34a9653408ab (patch) | |
| tree | ac5ac709d998a9d6a8123f69cc5fffa24fd5be09 /src | |
| parent | 9bdfd6025b6d5618da840351292c6cad7845fe25 (diff) | |
| download | invidious-7baced75e555f094daaff3bfb06e34a9653408ab.tar.gz invidious-7baced75e555f094daaff3bfb06e34a9653408ab.tar.bz2 invidious-7baced75e555f094daaff3bfb06e34a9653408ab.zip | |
Fix channel redirect
Diffstat (limited to 'src')
| -rw-r--r-- | src/invidious.cr | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/src/invidious.cr b/src/invidious.cr index 5ab779de..8340ebab 100644 --- a/src/invidious.cr +++ b/src/invidious.cr @@ -2602,13 +2602,9 @@ post "/data_control" do |env| next match["channel"] elsif match = channel["url"].as_s.match(/\/user\/(?<user>.+)/) response = YT_POOL.client &.get("/user/#{match["user"]}?disable_polymer=1&hl=en&gl=US") - document = XML.parse_html(response.body) - canonical = document.xpath_node(%q(//link[@rel="canonical"])) - - if canonical - ucid = canonical["href"].split("/")[-1] - next ucid - end + html = XML.parse_html(response.body) + ucid = html.xpath_node(%q(//link[@rel="canonical"])).try &.["href"].split("/")[-1] + next ucid if ucid end nil @@ -5873,7 +5869,7 @@ error 404 do |env| response = YT_POOL.client &.get("/#{item}") 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 if response.body.empty? @@ -5882,10 +5878,10 @@ error 404 do |env| end 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 - env.response.headers["Location"] = "/channel/#{ucid["content"]}" + env.response.headers["Location"] = "/channel/#{ucid}" halt env, status_code: 302 end |
