This commit is contained in:
r888888888
2014-10-09 14:26:33 -07:00
parent 5bc0bb88cf
commit 0a61aac231
9 changed files with 18 additions and 20 deletions

View File

@@ -0,0 +1,37 @@
module Downloads
module RewriteStrategies
class Tumblr < Base
def rewrite(url, headers)
if url =~ %r{^https?://.*tumblr\.com}
url, headers = rewrite_cdn(url, headers)
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
given_size = $2
big_1280_url = url.sub(match + given_size, match + "1280")
if http_exists?(big_1280_url, headers)
return [big_1280_url, headers]
end
end
return [url, headers]
end
def rewrite_cdn(url, headers)
if url =~ %r{https?://gs1\.wac\.edgecastcdn\.net/8019B6/data\.tumblr\.com/}
url.sub!("gs1.wac.edgecastcdn.net/8019B6/", "")
end
return [url, headers]
end
end
end
end