lib/onebox/engine/youtube_onebox.rb in onebox-1.8.79 vs lib/onebox/engine/youtube_onebox.rb in onebox-1.8.80

- old
+ new

@@ -1,5 +1,7 @@ +require 'onebox/oembed' + module Onebox module Engine class YoutubeOnebox include Engine include StandardEmbed @@ -10,13 +12,13 @@ WIDTH ||= 480 HEIGHT ||= 360 def placeholder_html if video_id - "<img src='https://i.ytimg.com/vi/#{video_id}/hqdefault.jpg' width='#{WIDTH}' height='#{HEIGHT}' #{Helpers.title_attr(video_oembed_data)}>" + "<img src='https://i.ytimg.com/vi/#{video_id}/hqdefault.jpg' width='#{WIDTH}' height='#{HEIGHT}' #{video_oembed_data.title_attr}>" elsif list_id - "<img src='#{list_thumbnail_url}' width='#{WIDTH}' height='#{HEIGHT}' #{Helpers.title_attr(list_oembed_data)}>" + "<img src='#{list_thumbnail_url}' width='#{WIDTH}' height='#{HEIGHT}' #{list_oembed_data.title_attr}>" else to_html end end @@ -47,15 +49,11 @@ html end end def video_title - @video_title ||= begin - Onebox::Helpers.truncate(video_oembed_data[:title], 80) - rescue - nil - end + @video_title ||= video_oembed_data.title end private def video_id @@ -83,26 +81,26 @@ def list_thumbnail_url @list_thumbnail_url ||= begin url = "https://www.youtube.com/oembed?format=json&url=https://www.youtube.com/playlist?list=#{list_id}" response = Onebox::Helpers.fetch_response(url) rescue "{}" - data = Onebox::Helpers.symbolize_keys(::MultiJson.load(response)) - data[:thumbnail_url] + data = Onebox::Oembed.new(response) + data.thumbnail_url rescue nil end end def video_oembed_data url = "https://www.youtube.com/oembed?format=json&url=https://www.youtube.com/watch?v=#{video_id}" response = Onebox::Helpers.fetch_response(url) rescue "{}" - Onebox::Helpers.symbolize_keys(::MultiJson.load(response)) + Onebox::Oembed.new(response) end def list_oembed_data url = "https://www.youtube.com/oembed?format=json&url=https://www.youtube.com/playlist?list=#{list_id}" response = Onebox::Helpers.fetch_response(url) rescue "{}" - Onebox::Helpers.symbolize_keys(::MultiJson.load(response)) + Onebox::Oembed.new(response) end def embed_params p = { 'feature' => 'oembed', 'wmode' => 'opaque' }