X-Git-Url: http://gitweb.michael.orlitzky.com/?p=dead%2Fwhatever-dl.git;a=blobdiff_plain;f=bin%2Fwhatever-dl;h=782624973dbb860b59313aff47e4f87bd7eb953e;hp=146dbeca69cc48087eefb2914f0e065c7fe8322f;hb=097749b9e9d7ab29bb78f681f01865741aea9342;hpb=873bf451b10441d763128dd0a758a15b58b15ae4 diff --git a/bin/whatever-dl b/bin/whatever-dl index 146dbec..7826249 100755 --- a/bin/whatever-dl +++ b/bin/whatever-dl @@ -19,39 +19,12 @@ # http://www.fsf.org/licensing/licenses/gpl.html # -# We need Pathname to get the real filesystem path -# of this script (and not, for example, the path of -# a symlink which points to it. -require 'pathname' +# This should load everything we need for us. +require 'whatever-dl' # And getoptlong to check for our one option, --continue. require 'getoptlong' -# This bit of magic adds the parent directory (the -# project root) to the list of ruby load paths. -# Thus, our require statements will work regardless of -# how or from where the script was run. -executable = Pathname.new(__FILE__).realpath.to_s -$LOAD_PATH << File.dirname(executable) + '/../' - -# Load our config file. -require 'bin/configuration' - -# And the downloaders... -require 'src/downloader' - -# The Dir.glob that's coming up doesn't use the -# Ruby library path so we need to tell it where to -# look explicitly. -websites_pattern = File.dirname(executable) + '/../src/websites/*.rb' - -# All of the website classes are located in one -# directory, so we can 'require' them automatically. -Dir.glob(websites_pattern).each do |r| - require r -end - - EXIT_SUCCESS = 0 EXIT_NO_URL = 1 EXIT_INVALID_URL = 2 @@ -137,17 +110,29 @@ if (__FILE__ == $0) then site.get_video_filename(), site.headers(), continue=options[:continue]) + rescue Errno::ECONNREFUSED => e - puts 'The connection to the server (to download the video file) was refused. Check your connection, and try again later.' + msg = 'The connection to the server (to download the video file) ' + msg += 'was refused. Check your connection, and try again later.' + puts msg Kernel.exit(EXIT_CONNECTION_REFUSED) + rescue Errno::EACCES => e - puts "Access denied. Check that you have write permission to the output file/directory. Details: #{e.message}." + msg = 'Access denied. Check that you have write permission ' + msg += "to the output file/directory. Details: #{e.message}." + puts msg + Kernel.exit(EXIT_ACCESS_DENIED) + rescue OpenURI::HTTPError => e - puts "An HTTP error occurred while downloading the video file: #{e.message}." + msg = 'An HTTP error occurred while downloading ' + msg += " the video file: #{e.message}." + puts msg Kernel.exit(EXIT_HTTP_ERROR) + rescue IOError => e puts "Input/Output Error: #{e.message}" Kernel.exit(EXIT_IO_ERROR) + end # Write an empty line at the end for aesthetic reasons.