diff --git a/getdistorted/getdistorted.rb b/getdistorted/getdistorted.rb index fbf01a0..1fc7910 100755 --- a/getdistorted/getdistorted.rb +++ b/getdistorted/getdistorted.rb @@ -25,6 +25,8 @@ require 'rexml/document' require 'date' require 'getoptlong' +@debug=false + def usage puts < only fetch -v, --verbose be more verbose + +To use a proxy set the HTTP_PROXY environment variable, like such: +export HTTP_PROXY=http://: EOT exit end @@ -101,11 +106,25 @@ def fetch(uri_str, limit = 10) proxy_pass = nil if ENV['HTTP_PROXY'] + begin uri = URI.parse(ENV['HTTP_PROXY']) proxy_host = uri.host proxy_port = uri.port proxy_user, proxy_pass = uri.userinfo.split(/:/) if uri.userinfo + rescue + puts $! + end end +if @debug +p "Host: #{host}" +p "Path: #{path}" +p "Query: #{query}" + +p "proxy_host #{proxy_host}" +p "proxy_port #{proxy_port}" +p "proxy_user #{proxy_user}" +p "proxy_pass #{proxy_pass}" +end Net::HTTP::Proxy(proxy_host, proxy_port, proxy_user, proxy_pass).start(host) {|http| @@ -114,7 +133,9 @@ def fetch(uri_str, limit = 10) else req = Net::HTTP::Get.new("#{path}") end - req.basic_auth @user, @pass + if ! @user.nil? && ! @pass.nil? + req.basic_auth @user, @pass + end response = http.request(req) case response when Net::HTTPSuccess then response @@ -124,6 +145,7 @@ def fetch(uri_str, limit = 10) when Net::HTTPNotFound then puts "404 Not Found #{uri_str}"; response.error! when Net::HTTPUnauthorized then puts "401 Authorization Required #{uri_str}"; response.error! else + puts response.message response.error! end } @@ -176,6 +198,8 @@ def getenclosure(podcast, item) return "#{@podcasts[podcast]["savedir"]}/#{filename}" rescue Timeout::Error, Errno::EHOSTUNREACH, Errno::ECONNREFUSED, Errno::ECONNRESET, Errno::ETIMEDOUT, Net::HTTPFatalError puts " error #{$!} fetching, skipping" + rescue + puts "WTF" end else return "#{@podcasts[podcast]["savedir"]}/#{filename}"