X-Git-Url: http://gitweb.michael.orlitzky.com/?p=dead%2Fwhatever-dl.git;a=blobdiff_plain;f=bin%2Fwhatever-dl;h=fbc84e909bde09dbfc14f525404300c56e00394a;hp=9a6b8c3e23eabe2b02624fe5a38539b3de340d74;hb=e3eeb8df887fc68959ab7d7ebae5c0206b79c230;hpb=b832fe95552b3ea080c55a576373e52960c7df39 diff --git a/bin/whatever-dl b/bin/whatever-dl index 9a6b8c3..fbc84e9 100755 --- a/bin/whatever-dl +++ b/bin/whatever-dl @@ -31,10 +31,11 @@ require 'pathname' executable = Pathname.new(__FILE__).realpath.to_s $: << File.dirname(executable) + '/../' -# We require the UriUtilities class to handle -# the download of the video URL. -require 'src/uri_utilities' +# 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 @@ -82,23 +83,22 @@ if (__FILE__ == $0) then puts 'Error retrieving video URL.' exit(EXIT_COULDNT_GET_VIDEO_URL) end - - video_uri = URI.parse(video_url) - uu = UriUtilities.new() - + if File.exists?(site.get_video_filename()) puts "Error: output file already exists. Please remove #{site.get_video_filename()}, and try again." Kernel.exit(EXIT_OUTPUT_FILE_ALREADY_EXISTS) end - + # The Downloader class is a factory; it should decide + # which subclass we get. + downloader = Downloader.create(Configuration::DOWNLOAD_METHOD) + # Attempt to download the file, and rescue and report - # any (predictable) exceptions. + # any (predictable) exceptions. The wget downloader will + # naturally not report any of these, since it will die in + # its own process. begin - puts "Fetching #{video_url}" - puts "Saving as #{site.get_video_filename()}." - puts "" - uu.download_with_progress_bar(video_uri, site.get_video_filename()) + downloader.download(video_url, site.get_video_filename()) rescue Errno::ECONNREFUSED => e puts 'The connection to the server (to download the video file) was refused. Check your connection, and try again later.' Kernel.exit(EXIT_CONNECTION_REFUSED) @@ -110,7 +110,7 @@ if (__FILE__ == $0) then end # Write an empty line at the end for aesthetic reasons. - puts "" + puts '' Kernel.exit(EXIT_SUCCESS) end