fixes #2491
This commit is contained in:
@@ -14,16 +14,21 @@ module Downloads
|
|||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
def http_exists?(url, headers)
|
def http_head_request(url, headers)
|
||||||
exists = false
|
|
||||||
uri = URI.parse(url)
|
uri = URI.parse(url)
|
||||||
Net::HTTP.start(uri.host, uri.port) do |http|
|
Net::HTTP.start(uri.host, uri.port) do |http|
|
||||||
http.request_head(uri.request_uri, headers) do |res|
|
http.request_head(uri.request_uri, headers) do |res|
|
||||||
if res.is_a?(Net::HTTPSuccess)
|
return res
|
||||||
exists = true
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def http_exists?(url, headers)
|
||||||
|
exists = false
|
||||||
|
res = http_head_request(url, headers)
|
||||||
|
if res.is_a?(Net::HTTPSuccess)
|
||||||
|
exists = true
|
||||||
|
end
|
||||||
exists
|
exists
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -12,13 +12,22 @@ module Downloads
|
|||||||
|
|
||||||
protected
|
protected
|
||||||
def rewrite_thumbnails(url, headers)
|
def rewrite_thumbnails(url, headers)
|
||||||
if url =~ %r{^https?://.+\.tumblr\.com/(?:\w+/)?(?:tumblr_)?(\w+_)(\d+)\..+$}
|
if url =~ %r{^https?://.+\.tumblr\.com/(?:\w+/)?(?:tumblr_)?(\w+_)(\d+)(\..+)$}
|
||||||
match = $1
|
match = $1
|
||||||
given_size = $2
|
given_size = $2
|
||||||
|
file_ext = $3
|
||||||
|
|
||||||
big_1280_url = url.sub(match + given_size, match + "1280")
|
big_1280_url = url.sub(match + given_size, match + "1280")
|
||||||
if http_exists?(big_1280_url, headers)
|
if file_ext == ".gif"
|
||||||
return [big_1280_url, headers]
|
res = http_head_request(big_1280_url, headers)
|
||||||
|
# Sometimes the 1280 version of a gif is actually a static jpeg. We don't want that so we only use the 1280 version if it really is a gif.
|
||||||
|
if res.is_a?(Net::HTTPSuccess) && res["content-type"] == "image/gif"
|
||||||
|
return [big_1280_url, headers]
|
||||||
|
end
|
||||||
|
else
|
||||||
|
if http_exists?(big_1280_url, headers)
|
||||||
|
return [big_1280_url, headers]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user