diff --git a/getdistorted/getdistorted.rb b/getdistorted/getdistorted.rb index d10985f..32b689e 100755 --- a/getdistorted/getdistorted.rb +++ b/getdistorted/getdistorted.rb @@ -78,14 +78,23 @@ def fetch(uri_str, limit = 10) # You should choose better exception. raise ArgumentError, 'HTTP redirect too deep' if limit == 0 - response = Net::HTTP.get_response(URI.parse(uri_str)) - case response - when Net::HTTPSuccess then response - when Net::HTTPRedirection then fetch(response['location'], limit - 1) - when Net::HTTPNotFound then puts "404 Not Found #{uri_str}"; response.error! - else - response.error! - end + host = URI.parse(uri_str).host + path = URI.parse(uri_str).path + query = URI.parse(uri_str).query + + Net::HTTP.start(host) {|http| + req = Net::HTTP::Get.new("#{path}?#{query}") + req.basic_auth @user, @pass + response = http.request(req) + case response + when Net::HTTPSuccess then response + when Net::HTTPRedirection then fetch(response['location'], limit - 1) + 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 + response.error! + end + } end def deleteold(podcast) @@ -153,9 +162,11 @@ def getcasts(podcast=nil) files = Array.new puts podcast begin + @user = @podcasts[podcast]["username"].nil? ? nil : @podcasts[podcast]["username"] + @pass = @podcasts[podcast]["password"].nil? ? nil : @podcasts[podcast]["password"] res = fetch(@podcasts[podcast]["rss"]) @filelist = {} - + # body.gsub!(/#{13.chr}#{10.chr}/, "#{10.chr}") xmldoc = REXML::Document.new(res.body) xmldoc.elements.each("rss/channel") {|item|