Add better error for invalid playlists

pull/186/head
Omar Roth 6 years ago
parent 5bdd8327d4
commit 1d9c6f63e1

@ -390,9 +390,8 @@ get "/playlist" do |env|
page = env.params.query["page"]?.try &.to_i? page = env.params.query["page"]?.try &.to_i?
page ||= 1 page ||= 1
playlist = fetch_playlist(plid)
begin begin
playlist = fetch_playlist(plid)
videos = fetch_playlist_videos(plid, page, playlist.video_count) videos = fetch_playlist_videos(plid, page, playlist.video_count)
rescue ex rescue ex
error_message = ex.message error_message = ex.message
@ -2823,9 +2822,9 @@ get "/api/v1/playlists/:plid" do |env|
page = env.params.query["page"]?.try &.to_i? page = env.params.query["page"]?.try &.to_i?
page ||= 1 page ||= 1
playlist = fetch_playlist(plid)
begin begin
playlist = fetch_playlist(plid)
videos = fetch_playlist_videos(plid, page, playlist.video_count) videos = fetch_playlist_videos(plid, page, playlist.video_count)
rescue ex rescue ex
error_message = {"error" => "Playlist is empty"}.to_json error_message = {"error" => "Playlist is empty"}.to_json

@ -142,6 +142,10 @@ def fetch_playlist(plid)
end end
response = client.get("/playlist?list=#{plid}&disable_polymer=1") response = client.get("/playlist?list=#{plid}&disable_polymer=1")
if response.status_code != 200
raise "Invalid playlist."
end
body = response.body.gsub(<<-END_BUTTON body = response.body.gsub(<<-END_BUTTON
<button class="yt-uix-button yt-uix-button-size-default yt-uix-button-link yt-uix-expander-head playlist-description-expander yt-uix-inlineedit-ignore-edit" type="button" onclick=";return false;"><span class="yt-uix-button-content"> less <img alt="" src="/yts/img/pixel-vfl3z5WfW.gif"> <button class="yt-uix-button yt-uix-button-size-default yt-uix-button-link yt-uix-expander-head playlist-description-expander yt-uix-inlineedit-ignore-edit" type="button" onclick=";return false;"><span class="yt-uix-button-content"> less <img alt="" src="/yts/img/pixel-vfl3z5WfW.gif">
</span></button> </span></button>

Loading…
Cancel
Save