fix minor bug, which so far only manifests itself on penny-arcade.com
This commit is contained in:
parent
c8b04f9f33
commit
0846e910ac
1 changed files with 25 additions and 1 deletions
|
|
@ -25,6 +25,8 @@ require 'rexml/document'
|
||||||
require 'date'
|
require 'date'
|
||||||
require 'getoptlong'
|
require 'getoptlong'
|
||||||
|
|
||||||
|
@debug=false
|
||||||
|
|
||||||
def usage
|
def usage
|
||||||
puts <<EOT
|
puts <<EOT
|
||||||
Usage: #{$0.sub(/.*\//, "")} [options]
|
Usage: #{$0.sub(/.*\//, "")} [options]
|
||||||
|
|
@ -34,6 +36,9 @@ Usage: #{$0.sub(/.*\//, "")} [options]
|
||||||
-l, --list list podcasts
|
-l, --list list podcasts
|
||||||
-p, --podcast <podcast> only fetch <podcast>
|
-p, --podcast <podcast> only fetch <podcast>
|
||||||
-v, --verbose be more verbose
|
-v, --verbose be more verbose
|
||||||
|
|
||||||
|
To use a proxy set the HTTP_PROXY environment variable, like such:
|
||||||
|
export HTTP_PROXY=http://<host>:<port>
|
||||||
EOT
|
EOT
|
||||||
exit
|
exit
|
||||||
end
|
end
|
||||||
|
|
@ -101,11 +106,25 @@ def fetch(uri_str, limit = 10)
|
||||||
proxy_pass = nil
|
proxy_pass = nil
|
||||||
|
|
||||||
if ENV['HTTP_PROXY']
|
if ENV['HTTP_PROXY']
|
||||||
|
begin
|
||||||
uri = URI.parse(ENV['HTTP_PROXY'])
|
uri = URI.parse(ENV['HTTP_PROXY'])
|
||||||
proxy_host = uri.host
|
proxy_host = uri.host
|
||||||
proxy_port = uri.port
|
proxy_port = uri.port
|
||||||
proxy_user, proxy_pass = uri.userinfo.split(/:/) if uri.userinfo
|
proxy_user, proxy_pass = uri.userinfo.split(/:/) if uri.userinfo
|
||||||
|
rescue
|
||||||
|
puts $!
|
||||||
end
|
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,
|
Net::HTTP::Proxy(proxy_host, proxy_port,
|
||||||
proxy_user, proxy_pass).start(host) {|http|
|
proxy_user, proxy_pass).start(host) {|http|
|
||||||
|
|
@ -114,7 +133,9 @@ def fetch(uri_str, limit = 10)
|
||||||
else
|
else
|
||||||
req = Net::HTTP::Get.new("#{path}")
|
req = Net::HTTP::Get.new("#{path}")
|
||||||
end
|
end
|
||||||
|
if ! @user.nil? && ! @pass.nil?
|
||||||
req.basic_auth @user, @pass
|
req.basic_auth @user, @pass
|
||||||
|
end
|
||||||
response = http.request(req)
|
response = http.request(req)
|
||||||
case response
|
case response
|
||||||
when Net::HTTPSuccess then 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::HTTPNotFound then puts "404 Not Found #{uri_str}"; response.error!
|
||||||
when Net::HTTPUnauthorized then puts "401 Authorization Required #{uri_str}"; response.error!
|
when Net::HTTPUnauthorized then puts "401 Authorization Required #{uri_str}"; response.error!
|
||||||
else
|
else
|
||||||
|
puts response.message
|
||||||
response.error!
|
response.error!
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
|
@ -176,6 +198,8 @@ def getenclosure(podcast, item)
|
||||||
return "#{@podcasts[podcast]["savedir"]}/#{filename}"
|
return "#{@podcasts[podcast]["savedir"]}/#{filename}"
|
||||||
rescue Timeout::Error, Errno::EHOSTUNREACH, Errno::ECONNREFUSED, Errno::ECONNRESET, Errno::ETIMEDOUT, Net::HTTPFatalError
|
rescue Timeout::Error, Errno::EHOSTUNREACH, Errno::ECONNREFUSED, Errno::ECONNRESET, Errno::ETIMEDOUT, Net::HTTPFatalError
|
||||||
puts " error #{$!} fetching, skipping"
|
puts " error #{$!} fetching, skipping"
|
||||||
|
rescue
|
||||||
|
puts "WTF"
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
return "#{@podcasts[podcast]["savedir"]}/#{filename}"
|
return "#{@podcasts[podcast]["savedir"]}/#{filename}"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue