Clean up '/channel/'
This commit is contained in:
parent
d4e37c0201
commit
9fbab6125a
|
@ -1527,46 +1527,41 @@ get "/channel/:ucid" do |env|
|
||||||
client = make_client(YT_URL)
|
client = make_client(YT_URL)
|
||||||
|
|
||||||
if !ucid.match(/UC[a-zA-Z0-9_-]{22}/)
|
if !ucid.match(/UC[a-zA-Z0-9_-]{22}/)
|
||||||
rss = client.get("/feeds/videos.xml?user=#{ucid}").body
|
rss = client.get("/feeds/videos.xml?user=#{ucid}")
|
||||||
rss = XML.parse_html(rss)
|
rss = XML.parse_html(rss.body)
|
||||||
|
|
||||||
ucid = rss.xpath_node("//feed/channelid")
|
ucid = rss.xpath_node("//feed/channelid")
|
||||||
if ucid
|
if !ucid
|
||||||
ucid = ucid.content
|
error_message = "User does not exist."
|
||||||
else
|
|
||||||
error_message = "User does not exist"
|
|
||||||
next templated "error"
|
next templated "error"
|
||||||
end
|
end
|
||||||
|
|
||||||
env.redirect "/channel/#{ucid}"
|
next env.redirect "/channel/#{ucid}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
rss = XML.parse_html(rss.body)
|
||||||
|
author = rss.xpath_node("//feed/author/name").not_nil!.content
|
||||||
|
|
||||||
url = produce_playlist_url(ucid, (page - 1) * 100)
|
url = produce_playlist_url(ucid, (page - 1) * 100)
|
||||||
response = client.get(url)
|
response = client.get(url)
|
||||||
|
response = JSON.parse(response.body)
|
||||||
|
|
||||||
json = JSON.parse(response.body)
|
if !response["content_html"]?
|
||||||
if !json["content_html"]? || json["content_html"].as_s.empty?
|
error_message = "This channel does not exist."
|
||||||
error_message = "This channel does not exist or has no videos."
|
|
||||||
next templated "error"
|
next templated "error"
|
||||||
end
|
end
|
||||||
|
|
||||||
if json["content_html"].as_s.strip(" \n").empty?
|
document = XML.parse_html(response["content_html"].as_s)
|
||||||
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
|
|
||||||
|
|
||||||
videos = [] of ChannelVideo
|
|
||||||
|
|
||||||
next templated "channel"
|
|
||||||
end
|
|
||||||
|
|
||||||
document = XML.parse_html(json["content_html"].as_s)
|
|
||||||
anchor = document.xpath_node(%q(//div[@class="pl-video-owner"]/a))
|
anchor = document.xpath_node(%q(//div[@class="pl-video-owner"]/a))
|
||||||
if !anchor
|
if !anchor
|
||||||
error_message = "This channel is not available"
|
videos = [] of ChannelVideo
|
||||||
next templated "error"
|
next templated "channel"
|
||||||
end
|
end
|
||||||
author = anchor.content
|
|
||||||
|
|
||||||
videos = [] of ChannelVideo
|
videos = [] of ChannelVideo
|
||||||
document.xpath_nodes(%q(//a[contains(@class,"pl-video-title-link")])).each do |node|
|
document.xpath_nodes(%q(//a[contains(@class,"pl-video-title-link")])).each do |node|
|
||||||
|
|
Loading…
Reference in New Issue