Skip to content

Commit

Permalink
Catch exception when file cannot be downloaded
Browse files Browse the repository at this point in the history
We have several situation when file cannot be downloaded:
* youtube: video was removed
* youtube: video is private
* youtube: confreaks contain wrong embed_code, probably `none` value
* vimeo: video doesn't exist
* downloaded uncompleted video - we should retry

Above conditions should handle live streams too smcabrera#6.
  • Loading branch information
wafcio committed Sep 29, 2016
1 parent 17bc7df commit 3c2ec17
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions lib/get_freaky/video.rb
Expand Up @@ -41,6 +41,25 @@ def self.find(event_short_code, title)
def download
puts "downloading #{title}"
YoutubeDL.download url, { output: "#{title}.mp4" }
rescue Cocaine::ExitStatusError => e
regex_errors = [
/YouTube said\: This video does not exist\./,
/YouTube said\: Please sign in to view this video\./,
/Incomplete YouTube ID/,
/HTTP Error 404\: Not Found/, # for vimeo
]

case e.message
when *regex_errors
puts $LAST_MATCH_INFO[0]
return
when /content too short/
puts "#{$LAST_MATCH_INFO[0]} - retry"
return download
end

# raise different uncaught exceptions
raise e
end

def event
Expand Down

0 comments on commit 3c2ec17

Please sign in to comment.