Skip to content

Commit

Permalink
Add 404 check.
Browse files Browse the repository at this point in the history
  • Loading branch information
stefansundin committed Mar 8, 2020
1 parent 4ebbcfc commit 6e9935c
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -867,12 +867,12 @@
if /twitch\.tv\/[^\/]+\/clip\/(?<clip_slug>[^?&#]+)/ =~ params[:url] || /clips\.twitch\.tv\/(?:embed\?clip=)?(?<clip_slug>[^?&#]+)/ =~ params[:url]
# https://www.twitch.tv/majinphil/clip/TenaciousCreativePieNotATK
# https://clips.twitch.tv/DignifiedThirstyDogYee
# https://clips.twitch.tv/majinphil/UnusualClamRaccAttack (legacy url, redirects to the one above)
# https://clips.twitch.tv/majinphil/UnusualClamRaccAttack (deprecated url)
# https://clips.twitch.tv/embed?clip=DignifiedThirstyDogYee&autoplay=false
elsif /twitch\.tv\/(?:[^\/]+\/)?(?:v|videos?)\/(?<vod_id>\d+)/ =~ params[:url] || /(?:^|v)(?<vod_id>\d+)/ =~ params[:url]
# https://www.twitch.tv/gsl/video/25133028
# https://www.twitch.tv/gamesdonequick/video/34377308?t=53m40s
# https://www.twitch.tv/videos/25133028 (legacy url)
# https://www.twitch.tv/videos/25133028
# https://www.twitch.tv/gsl/video/25133028 (legacy url)
# https://www.twitch.tv/gamesdonequick/video/34377308?t=53m40s (legacy url)
# https://www.twitch.tv/gamesdonequick/v/34377308?t=53m40s (legacy url)
# https://player.twitch.tv/?video=v103620362
elsif /twitch\.tv\/(?<channel_name>[^\/?#]+)/ =~ params[:url]
Expand All @@ -895,6 +895,8 @@
playlist_url = "http://usher.twitch.tv" + Addressable::URI.new(path: "/vod/#{vod_id}", query: "nauthsig=#{data["sig"]}&nauth=#{data["token"]}").normalize.to_s

response = HTTP.get(playlist_url)
return [response.code, "Video does not exist."] if response.code == 404
raise(TwitchError, response) if !response.success?
streams = response.body.split("\n").reject { |line| line[0] == "#" } + [playlist_url]
elsif channel_name
response = TwitchToken.get("/channels/#{channel_name}/access_token")
Expand Down

0 comments on commit 6e9935c

Please sign in to comment.