]> gitweb.michael.orlitzky.com - dead/whatever-dl.git/blobdiff - src/uri_utilities.rb
Allow the downloaders to take advantage of the websites' headers.
[dead/whatever-dl.git] / src / uri_utilities.rb
index df09619fce99cf8adaaaaed4f3322eb9cba8a151..dcff2fe11c4ed330cf8ada0eb5df5f8d4acad371 100644 (file)
@@ -28,14 +28,14 @@ class UriUtilities
   # Download the given URI object to <outfile_name>.
   # 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
       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
@@ -43,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.
@@ -63,5 +64,5 @@ class UriUtilities
       raise(e)
     end
   end
-  
+
 end