From b5bd330b68bbdbd4481f1ab91f1203930f12737b Mon Sep 17 00:00:00 2001 From: EbiflyBB Date: Sun, 14 Feb 2016 00:42:12 +0900 Subject: [PATCH] =?UTF-8?q?Instagram=E3=81=B8=E3=81=AE=E5=AF=BE=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/plugin/photo_support/photo_support.rb | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/core/plugin/photo_support/photo_support.rb b/core/plugin/photo_support/photo_support.rb index 6bf2b88..03c947c 100644 --- a/core/plugin/photo_support/photo_support.rb +++ b/core/plugin/photo_support/photo_support.rb @@ -4,7 +4,7 @@ require 'httpclient' require 'totoridipjp' module Plugin::PhotoSupport - INSTAGRAM_PATTERN = %r{^https?://(?:instagr\.am|instagram\.com)/p/([a-zA-Z0-9_\-]+)} + INSTAGRAM_PATTERN = %r{(?:instagr\.am|instagram\.com)/p/([a-zA-Z0-9_\-]+)/} class << self # Twitter cardsのURLを画像のURLに置き換える。 @@ -160,9 +160,12 @@ Plugin.create :photo_support do # instagram defimageopener('instagram', Plugin::PhotoSupport::INSTAGRAM_PATTERN) do |display_url| - m = display_url.match(Plugin::PhotoSupport::INSTAGRAM_PATTERN) - shortcode = m[1] - open("https://instagram.com/p/#{shortcode}/media/?size=l") + connection = HTTPClient.new + page = connection.get_content(display_url) + next nil if page.empty? + doc = Nokogiri::HTML(page) + result = doc.xpath("//meta[@property='og:image']/@content").first + open(result) end # d250g2 -- 1.8.4