This commit is contained in:
r888888888
2014-12-03 12:45:56 -08:00
parent 6c85572ae6
commit 97a71fe5a0
3 changed files with 19 additions and 2 deletions

View File

@@ -2,7 +2,7 @@ module Downloads
class File
class Error < Exception ; end
attr_reader :data
attr_reader :data, :options
attr_accessor :source, :content_type, :file_path
def initialize(source, file_path, options = {})
@@ -15,6 +15,10 @@ module Downloads
# we sometimes need to capture data from the source page
@data = {}
@options = options
@data[:get_thumbnail] = options[:get_thumbnail]
end
def download!

View File

@@ -14,6 +14,7 @@ module Downloads
url, headers = rewrite_html_pages(url, headers)
url, headers = rewrite_thumbnails(url, headers)
url, headers = rewrite_old_small_manga_pages(url, headers)
url, headers = rewrite_to_thumbnails(url, headers) if data.delete(:get_thumbnail)
end
# http://i2.pixiv.net/img-zip-ugoira/img/2014/08/05/06/01/10/44524589_ugoira1920x1080.zip
@@ -27,6 +28,18 @@ module Downloads
end
protected
def rewrite_to_thumbnails(url, headers)
if url =~ %r!https?://(i\d+)\.pixiv\.net/img-zip-ugoira/img/(\d{4}/\d{2}/\d{2}/\d{2}/\d{2}/\d{2})/(\d+)_ugoira\d+x\d+\.zip!
url = "http://#{$1}.pixiv.net/c/150x150/img-master/img/#{$2}/#{$3}_master1200.jpg"
elsif url =~ %r!https?://(i\d+)\.pixiv\.net/img-original/img/(\d{4}/\d{2}/\d{2}/\d{2}/\d{2}/\d{2})/(\d+_p\d+)\.jpg!
url = "http://#{$1}.pixiv.net/c/150x150/img-master/img/#{$2}/#{$3}_master1200.jpg"
elsif url =~ %r!http://(i\d+)\.pixiv\.net/img(\d+)/img/(.+?)/(\d+)\.jpg!
url = "http://#{$1}.pixiv.net/img#{$2}/img/#{$3}/mobile/#{$4}_240mw.jpg"
end
return [url, headers]
end
def rewrite_headers(url, headers)
headers["Referer"] = "http://www.pixiv.net"
return [url, headers]

View File

@@ -8,7 +8,7 @@ module Iqdb
def download_and_find_similar
tempfile = Tempfile.new("iqdb-#{$PROCESS_ID}")
@download = Downloads::File.new(source, tempfile.path)
@download = Downloads::File.new(source, tempfile.path, :get_thumbnail => true)
@download.download!
if Danbooru.config.iqdb_hostname_and_port