X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=src%2Furi_utilities.rb;h=dcff2fe11c4ed330cf8ada0eb5df5f8d4acad371;hb=05f6c664ebd77e194656a828855d74d2c4959d85;hp=61d57af63ea29d84b03ef70b65dfebcbf34e6e32;hpb=9390083b114048a6782454a37f799733707ee5dc;p=dead%2Fwhatever-dl.git diff --git a/src/uri_utilities.rb b/src/uri_utilities.rb index 61d57af..dcff2fe 100644 --- a/src/uri_utilities.rb +++ b/src/uri_utilities.rb @@ -25,24 +25,17 @@ require 'vendor/ruby-progressbar/progressbar' # for trouble. class UriUtilities - # Get the filename portion of a given URI. - # Return nil if there is no filename portion. - def get_filename(uri) - return uri.path.split('/').last - end - - # Download the given URI object to . # Should use the progress_proc parameter to show # a progress bar using the Ruby/ProgressBar library. - def download_with_progress_bar(uri, outfile_name) + def download_with_progress_bar(uri, outfile_name, headers = {}) # We wrap the whole thing in a begin/rescue so that # we can clean up afterwards in case of an error. begin - open(outfile_name, 'wb') do |outfile| + File.open(outfile_name, 'wb') do |outfile| pbar = nil - uri.open(:content_length_proc => lambda {|content_length| - if content_length && (0 < content_length) + uri.open({:content_length_proc => lambda {|content_length| + if content_length && (0 < content_length) pbar = ProgressBar.new("Download", content_length) pbar.instance_eval { @bar_mark = '=' } pbar.file_transfer_mode @@ -50,9 +43,10 @@ class UriUtilities }, :progress_proc => lambda {|size| pbar.set(size) if pbar - }) do |video_file| + } + }.merge!(headers)) do |video_file| outfile.write(video_file.read) - end + end end # Toss out an empty line to get rid of the progress bar. @@ -70,5 +64,5 @@ class UriUtilities raise(e) end end - + end