4 |
4 |
require 'totoridipjp'
|
5 |
5 |
|
6 |
6 |
module Plugin::PhotoSupport
|
7 |
|
INSTAGRAM_PATTERN = %r{^https?://(?:instagr\.am|instagram\.com)/p/([a-zA-Z0-9_\-]+)}
|
|
7 |
INSTAGRAM_PATTERN = %r{(?:instagr\.am|instagram\.com)/p/([a-zA-Z0-9_\-]+)/}
|
8 |
8 |
|
9 |
9 |
class << self
|
10 |
10 |
# Twitter cardsのURLを画像のURLに置き換える。
|
... | ... | |
160 |
160 |
|
161 |
161 |
# instagram
|
162 |
162 |
defimageopener('instagram', Plugin::PhotoSupport::INSTAGRAM_PATTERN) do |display_url|
|
163 |
|
m = display_url.match(Plugin::PhotoSupport::INSTAGRAM_PATTERN)
|
164 |
|
shortcode = m[1]
|
165 |
|
open("https://instagram.com/p/#{shortcode}/media/?size=l")
|
|
163 |
connection = HTTPClient.new
|
|
164 |
page = connection.get_content(display_url)
|
|
165 |
next nil if page.empty?
|
|
166 |
doc = Nokogiri::HTML(page)
|
|
167 |
result = doc.xpath("//meta[@property='og:image']/@content").first
|
|
168 |
open(result)
|
166 |
169 |
end
|
167 |
170 |
|
168 |
171 |
# d250g2
|