#1866: Tumblr thumbnail rewriting
This commit is contained in:
27
app/logical/downloads/strategies/tumblr.rb
Normal file
27
app/logical/downloads/strategies/tumblr.rb
Normal file
@@ -0,0 +1,27 @@
|
||||
module Downloads
|
||||
module Strategies
|
||||
class Tumblr < Base
|
||||
def rewrite(url, headers)
|
||||
if url =~ %r{^http?://(?:(?:\d+\.)\w+\.)?tumblr\.com}
|
||||
url, headers = rewrite_thumbnails(url, headers)
|
||||
end
|
||||
|
||||
return [url, headers]
|
||||
end
|
||||
|
||||
protected
|
||||
def rewrite_thumbnails(url, headers)
|
||||
if url =~ %r{^http?://.+\.tumblr\.com/(?:\w+/)?(?:tumblr_)?(\w+_)(250|400|500)\..+$}
|
||||
match = $1
|
||||
size = $2
|
||||
big_url = url.sub(match + size, match + "1280")
|
||||
if http_exists?(big_url, headers)
|
||||
url = big_url
|
||||
end
|
||||
end
|
||||
|
||||
return [url, headers]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user