Support rewriting direct twitter url -> full size url
If the user gives us the direct image url the twitter api is useless since it doesn't have the status id. So just rewrite the url itself.
This commit is contained in:
@@ -3,19 +3,29 @@ module Downloads
|
||||
class Twitter < Base
|
||||
def rewrite(url, headers, data = {})
|
||||
if url =~ %r!^https?://(?:mobile\.)?twitter\.com!
|
||||
url, headers = rewrite_image_url(url, headers)
|
||||
url, headers = rewrite_status_page(url, headers)
|
||||
elsif url =~ %r{^https?://pbs\.twimg\.com}
|
||||
url, headers = rewrite_direct_image_url(url, headers)
|
||||
end
|
||||
|
||||
return [url, headers, data]
|
||||
end
|
||||
|
||||
protected
|
||||
def rewrite_image_url(url, headers)
|
||||
def rewrite_status_page(url, headers)
|
||||
source = ::Sources::Strategies::Twitter.new(url)
|
||||
source.get
|
||||
url = source.image_url
|
||||
return [url, headers]
|
||||
end
|
||||
|
||||
def rewrite_direct_image_url(url, headers)
|
||||
if url =~ %r{^(https?://pbs\.twimg\.com/media/[^:]+)}
|
||||
url = $1 + ":orig"
|
||||
end
|
||||
|
||||
return [url, headers]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user