Class: Onebox::Engine::YoutubeOnebox

Inherits:
Object
  • Object
show all
Includes:
Onebox::Engine, StandardEmbed
Defined in:
lib/onebox/engine/youtube_onebox.rb

Constant Summary

Constants included from Onebox::Engine

DEFAULT

Instance Attribute Summary

Attributes included from Onebox::Engine

#cache, #timeout, #uri, #url

Instance Method Summary collapse

Methods included from StandardEmbed

add_oembed_provider, add_opengraph_provider, #always_https?, oembed_providers, opengraph_providers, #raw

Methods included from Onebox::Engine

engines, included, #initialize, #options, #options=

Instance Method Details

#placeholder_htmlObject


13
14
15
16
17
18
19
20
21
# File 'lib/onebox/engine/youtube_onebox.rb', line 13

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)}>"
  elsif list_id
    "<img src='#{list_thumbnail_url}' width='#{WIDTH}' height='#{HEIGHT}' #{Helpers.title_attr(list_oembed_data)}>"
  else
    to_html
  end
end

#to_htmlObject


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/onebox/engine/youtube_onebox.rb', line 23

def to_html
  if video_id
    <<-HTML
      <iframe width="#{WIDTH}"
              height="#{HEIGHT}"
              src="https://www.youtube.com/embed/#{video_id}?#{embed_params}"
              frameborder="0"
              allowfullscreen>
      </iframe>
    HTML
  elsif list_id
    <<-HTML
      <iframe width="#{WIDTH}"
              height="#{HEIGHT}"
              src="https://www.youtube.com/embed/videoseries?list=#{list_id}&wmode=transparent&rel=0&autohide=1&showinfo=1&enablejsapi=1"
              frameborder="0"
              allowfullscreen>
      </iframe>
    HTML
  else
    # for channel pages
    html = Onebox::Engine::WhitelistedGenericOnebox.new(@url, @cache, @timeout).to_html
    return if Onebox::Helpers.blank?(html)
    html.gsub!(/['"]\/\//, "https://")
    html
  end
end

#video_titleObject


51
52
53
54
55
56
57
# File 'lib/onebox/engine/youtube_onebox.rb', line 51

def video_title
  @video_title ||= begin
    video_oembed_data[:title]
  rescue
    nil
  end
end