X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=src%2Fwget_downloader.rb;h=ce4c760b5f2784c67db4ee2fcf2fe1951bb252da;hb=05f6c664ebd77e194656a828855d74d2c4959d85;hp=2cbdd4556dc4be305fb39795432afa4975853977;hpb=e3eeb8df887fc68959ab7d7ebae5c0206b79c230;p=dead%2Fwhatever-dl.git diff --git a/src/wget_downloader.rb b/src/wget_downloader.rb index 2cbdd45..ce4c760 100644 --- a/src/wget_downloader.rb +++ b/src/wget_downloader.rb @@ -18,9 +18,25 @@ class WgetDownloader < Downloader - def download(url, outfile) + def download(url, outfile, headers = {}, continue = false) + if (continue == false and File.exists?(outfile)) + raise IOError.new("Output file already exists. Please remove #{outfile}, and try again. If this is a partially-downloaded file, you can use the --continue flag to pick up where it left off.") + end + + options = '' + + if continue == true + options += '--continue ' + end + + headers.each_key do |key| + options += "--header '#{key}: #{headers[key]}' " + end + # This one's easy. - Kernel.exec("wget -O \"#{outfile}\" \"#{url}\"") + cmd = "wget #{options} -O \"#{outfile}\" \"#{url}\"" + puts "\nExecuting external command: #{cmd}\n\n" + Kernel.exec(cmd) end end