lib/kindai/util.rb in kindai-1.7.0 vs lib/kindai/util.rb in kindai-1.7.1
- old
+ new
@@ -2,10 +2,11 @@
require 'open3'
require 'tempfile'
require 'digest/sha1'
require 'RMagick'
require 'zipruby'
+require 'net/http'
module Kindai::Util
def self.logger
return @logger if @logger
@logger ||= Logger.new(STDOUT)
@@ -111,9 +112,20 @@
$stdout.flush
end
})
raise "received size unmatch(#{got.bytesize}, #{total})" if got.bytesize != total
return got
+ end
+
+ def self.get_redirected_uri(uri)
+ uri = URI.parse(uri) unless uri.kind_of? URI
+ self.logger.debug "get_redirected_uri #{uri}"
+
+ response = nil
+ Net::HTTP.start(uri.host, uri.port) {|http|
+ response = http.head(uri.request_uri)
+ }
+ response['Location']
end
def self.trim_info_auto(book, files)
info = nil
item = Kindai::Util::Database.item_for_book(book)