]> gitweb.michael.orlitzky.com - dead/whatever-dl.git/blobdiff - bin/whatever-dl
Update bin/whatever-dl and the configuration class for the other changes.
[dead/whatever-dl.git] / bin / whatever-dl
index 146dbeca69cc48087eefb2914f0e065c7fe8322f..782624973dbb860b59313aff47e4f87bd7eb953e 100755 (executable)
 # 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.