fix minor bug, which so far only manifests itself on penny-arcade.com

This commit is contained in:
Ward Wouts 2007-09-22 22:50:03 +00:00
parent c8b04f9f33
commit 0846e910ac

View file

@ -25,6 +25,8 @@ require 'rexml/document'
require 'date'
require 'getoptlong'
@debug=false
def usage
puts <<EOT
Usage: #{$0.sub(/.*\//, "")} [options]
@ -34,6 +36,9 @@ Usage: #{$0.sub(/.*\//, "")} [options]
-l, --list list podcasts
-p, --podcast <podcast> only fetch <podcast>
-v, --verbose be more verbose
To use a proxy set the HTTP_PROXY environment variable, like such:
export HTTP_PROXY=http://<host>:<port>
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}"