summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOmar Roth <omarroth@hotmail.com>2018-09-04 09:13:58 -0500
committerOmar Roth <omarroth@hotmail.com>2018-09-04 09:13:58 -0500
commit98d71ca8e7d0681d512f1fd57e9922647d40f942 (patch)
tree3235a94564e2f1a4482246bd8743a96674deda94
parent0f2f273335e545bb72441e6b628738d82cf429a8 (diff)
downloadinvidious-98d71ca8e7d0681d512f1fd57e9922647d40f942.tar.gz
invidious-98d71ca8e7d0681d512f1fd57e9922647d40f942.tar.bz2
invidious-98d71ca8e7d0681d512f1fd57e9922647d40f942.zip
Add support for /c/ URLs
-rw-r--r--src/invidious.cr17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/invidious.cr b/src/invidious.cr
index 2daec20a..7a2fea10 100644
--- a/src/invidious.cr
+++ b/src/invidious.cr
@@ -1557,6 +1557,23 @@ end
# Channels
+# YouTube appears to let users set a "brand" URL that
+# is different from their username, so we convert that here
+get "/c/:user" do |env|
+ client = make_client(YT_URL)
+ user = env.params.url["user"]
+
+ response = client.get("/c/#{user}")
+ document = XML.parse_html(response.body)
+
+ anchor = document.xpath_node(%q(//a[contains(@class,"branded-page-header-title-link")]))
+ if !anchor
+ next env.redirect "/"
+ end
+
+ env.redirect anchor["href"]
+end
+
get "/user/:user" do |env|
user = env.params.url["user"]
env.redirect "/channel/#{user}"