# 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
-$: << 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
end
# Warn about nonsensical options.
- if options[:continue] and not (Configuration::DOWNLOAD_METHOD == :wget)
+ if options[:continue] and not Configuration::DOWNLOAD_METHOD == :wget
puts 'WARNING: The --continue flag does nothing unless DOWNLOAD_METHOD is :wget.'
end
video_url = site.get_video_url()
if video_url.nil?
- puts 'Error retrieving video URL.'
- exit(EXIT_COULDNT_GET_VIDEO_URL)
- end
+ puts 'Error retrieving video URL:'
+ puts "Site not supported, and the generic parser couldn't find any videos."
+ exit(EXIT_COULDNT_GET_VIDEO_URL) end
# The Downloader class is a factory; it should decide
# which subclass we get.
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.