implements #2350
This commit is contained in:
@@ -22,6 +22,20 @@ module Downloads
|
||||
@data[:get_thumbnail] = options[:get_thumbnail]
|
||||
end
|
||||
|
||||
def size
|
||||
headers = {
|
||||
"User-Agent" => "#{Danbooru.config.safe_app_name}/#{Danbooru.config.version}"
|
||||
}
|
||||
@source, headers, @data = before_download(@source, headers, @data)
|
||||
url = URI.parse(@source)
|
||||
Net::HTTP.start(url.host, url.port, :use_ssl => url.is_a?(URI::HTTPS)) do |http|
|
||||
http.read_timeout = 3
|
||||
http.request_head(url.request_uri, headers) do |res|
|
||||
return res.content_length
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def download!
|
||||
@source, @data = http_get_streaming(@source, @data) do |response|
|
||||
self.content_type = response["Content-Type"]
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
module Sources
|
||||
class Site
|
||||
attr_reader :url, :strategy
|
||||
delegate :get, :referer_url, :site_name, :artist_name, :profile_url, :image_url, :tags, :artist_record, :unique_id, :page_count, :file_url, :ugoira_frame_data, :to => :strategy
|
||||
delegate :get, :get_size, :referer_url, :site_name, :artist_name, :profile_url, :image_url, :tags, :artist_record, :unique_id, :page_count, :file_url, :ugoira_frame_data, :to => :strategy
|
||||
|
||||
def self.strategies
|
||||
[Strategies::Pixiv, Strategies::NicoSeiga, Strategies::DeviantArt, Strategies::Nijie, Strategies::Twitter]
|
||||
|
||||
@@ -18,6 +18,10 @@ module Sources
|
||||
raise NotImplementedError
|
||||
end
|
||||
|
||||
def get_size
|
||||
@get_size ||= Downloads::File.new(@image_url).size
|
||||
end
|
||||
|
||||
# Subclasses should return true only if the URL is in its final normalized form.
|
||||
#
|
||||
# Sources::Site.new("http://img.pixiv.net/img/evazion").normalized_for_artist_finder?
|
||||
|
||||
Reference in New Issue
Block a user