バグ #600 » openimg-fix-instagram.patch
core/plugin/openimg/openimg.rb | ||
---|---|---|
5 | 5 | |
6 | 6 |
Plugin.create :openimg do |
7 | 7 |
DEFAULT_SIZE = [640, 480].freeze |
8 |
USER_AGENT = (Environment::NAME + '/' + Environment::VERSION.to_s).freeze |
|
8 | 9 |
@size = DEFAULT_SIZE |
9 | 10 |
@position = [Gdk.screen_width/2 - @size[0]/2, Gdk.screen_height/2 - @size[1]/2].freeze |
10 | 11 | |
... | ... | |
116 | 117 |
begin |
117 | 118 |
uri = URI.parse(url) |
118 | 119 |
path = uri.path + (uri.query ? "?"+uri.query : "") |
119 |
res = Net::HTTP.new(uri.host).get(path, "User-Agent" => Environment::NAME + '/' + Environment::VERSION.to_s)
|
|
120 |
res = Net::HTTP.new(uri.host).get(path, "User-Agent" => USER_AGENT)
|
|
120 | 121 |
case(res) |
121 | 122 |
when Net::HTTPSuccess |
122 | 123 |
address = get_tagattr(res.body, element_rule) |
... | ... | |
209 | 210 |
nil |
210 | 211 |
end |
211 | 212 |
} |
212 |
|
|
213 | ||
214 |
INSTAGRAM_PATTERN = %r{^http://(?:instagr\.am/p/([a-zA-Z0-9_]+)|instagram\.com/p/([a-zA-Z0-9_-]+))} |
|
215 |
addsupport(INSTAGRAM_PATTERN) do |url, cancel| |
|
216 |
m = url.match(INSTAGRAM_PATTERN) |
|
217 |
shortcode = m[1] || m[2] |
|
218 |
# http://instagram.com/developer/embedding/ |
|
219 |
uri = URI.parse "http://instagram.com/p/#{shortcode}/media/?size=l" |
|
220 |
res = Net::HTTP.new(uri.host).get uri.request_uri, 'User-Agent' => USER_AGENT |
|
221 |
if res.is_a? Net::HTTPRedirection |
|
222 |
res['Location'] |
|
223 |
else |
|
224 |
warn 'instagram url failed' |
|
225 |
nil |
|
226 |
end |
|
227 |
end |
|
228 | ||
213 | 229 |
::Gtk::TimeLine.addopenway(/.*\.(?:jpg|png|gif|)$/) { |shrinked_url, cancel| |
214 | 230 |
url = MessageConverters.expand_url_one(shrinked_url) |
215 | 231 |
Delayer.new { display(url, cancel) } |
core/plugin/openimg/pattern_file.json | ||
---|---|---|
71 | 71 |
} |
72 | 72 |
} |
73 | 73 |
}, |
74 |
"Instagram": { |
|
75 |
"url": "^http://(?:instagr\\.am/p/[a-zA-Z0-9_]+|instagram\\.com/p/[a-zA-Z0-9_-]+)", |
|
76 |
"attribute": { |
|
77 |
"class": "photo" |
|
78 |
} |
|
79 |
}, |
|
80 | 74 |
"img.ly": { |
81 | 75 |
"url": "^http://img\\.ly/[a-zA-Z0-9_]+", |
82 | 76 |
"attribute": { |