summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorOmar Roth <omarroth@hotmail.com>2018-08-10 08:20:35 -0500
committerOmar Roth <omarroth@hotmail.com>2018-08-10 08:20:35 -0500
commit9fbab6125ae28ed7aeb089d27029d868dd5c8ac1 (patch)
treeeae42def10a1d68c714d410c9cc2e10aa05219b3 /src
parentd4e37c0201058659ea8689980d08c3a9ac56d645 (diff)
downloadinvidious-9fbab6125ae28ed7aeb089d27029d868dd5c8ac1.tar.gz
invidious-9fbab6125ae28ed7aeb089d27029d868dd5c8ac1.tar.bz2
invidious-9fbab6125ae28ed7aeb089d27029d868dd5c8ac1.zip
Clean up '/channel/'
Diffstat (limited to 'src')
-rw-r--r--src/invidious.cr43
1 files changed, 19 insertions, 24 deletions
diff --git a/src/invidious.cr b/src/invidious.cr
index 7450e38d..ac9153f9 100644
--- a/src/invidious.cr
+++ b/src/invidious.cr
@@ -1527,46 +1527,41 @@ get "/channel/:ucid" do |env|
client = make_client(YT_URL)
if !ucid.match(/UC[a-zA-Z0-9_-]{22}/)
- rss = client.get("/feeds/videos.xml?user=#{ucid}").body
- rss = XML.parse_html(rss)
-
+ rss = client.get("/feeds/videos.xml?user=#{ucid}")
+ rss = XML.parse_html(rss.body)
ucid = rss.xpath_node("//feed/channelid")
- if ucid
- ucid = ucid.content
- else
- error_message = "User does not exist"
+ if !ucid
+ error_message = "User does not exist."
next templated "error"
end
- env.redirect "/channel/#{ucid}"
+ next env.redirect "/channel/#{ucid}"
end
- url = produce_playlist_url(ucid, (page - 1) * 100)
- response = client.get(url)
-
- json = JSON.parse(response.body)
- if !json["content_html"]? || json["content_html"].as_s.empty?
- error_message = "This channel does not exist or has no videos."
+ rss = client.get("/feeds/videos.xml?channel_id=#{ucid}")
+ if rss.status_code == 404
+ error_message = "This channel does not exist."
next templated "error"
end
- if json["content_html"].as_s.strip(" \n").empty?
- rss = client.get("/feeds/videos.xml?channel_id=#{ucid}").body
- rss = XML.parse_html(rss)
- author = rss.xpath_node("//feed/author/name").not_nil!.content
+ rss = XML.parse_html(rss.body)
+ author = rss.xpath_node("//feed/author/name").not_nil!.content
- videos = [] of ChannelVideo
+ url = produce_playlist_url(ucid, (page - 1) * 100)
+ response = client.get(url)
+ response = JSON.parse(response.body)
- next templated "channel"
+ if !response["content_html"]?
+ error_message = "This channel does not exist."
+ next templated "error"
end
- document = XML.parse_html(json["content_html"].as_s)
+ document = XML.parse_html(response["content_html"].as_s)
anchor = document.xpath_node(%q(//div[@class="pl-video-owner"]/a))
if !anchor
- error_message = "This channel is not available"
- next templated "error"
+ videos = [] of ChannelVideo
+ next templated "channel"
end
- author = anchor.content
videos = [] of ChannelVideo
document.xpath_nodes(%q(//a[contains(@class,"pl-video-title-link")])).each do |node|