Class: Onebox::Engine::YoutubeOnebox
Instance Attribute Summary
#cache, #timeout, #url
Instance Method Summary
collapse
#raw
engines, included, #initialize
Instance Method Details
#append_params(html) ⇒ Object
39
40
41
42
43
44
45
46
|
# File 'lib/onebox/engine/youtube_onebox.rb', line 39
def append_params(html)
result = html.dup
result.gsub! /(src="[^"]+)/, '\1&wmode=opaque'
if url =~ /t=(\d+)/
result.gsub! /(src="[^"]+)/, '\1&start=' + Regexp.last_match[1]
end
result
end
|
#placeholder_html ⇒ Object
18
19
20
21
22
23
24
|
# File 'lib/onebox/engine/youtube_onebox.rb', line 18
def placeholder_html
if video_id
"<img src='http://i1.ytimg.com/vi/#{video_id}/hqdefault.jpg' width='480' height='270'>"
else
to_html
end
end
|
#rewrite_agnostic(html) ⇒ Object
48
49
50
|
# File 'lib/onebox/engine/youtube_onebox.rb', line 48
def rewrite_agnostic(html)
html.gsub(/https?:\/\//, '//')
end
|
#to_html ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/onebox/engine/youtube_onebox.rb', line 26
def to_html
if video_id
html = "<iframe width=\"480\" height=\"270\" src=\"https://www.youtube.com/embed/#{video_id}?feature=oembed\" frameborder=\"0\" allowfullscreen></iframe>"
else
html = raw[:html]
end
rewrite_agnostic(append_params(html))
end
|
#video_id ⇒ Object
Try to get the video ID. Works for URLs of the form:
13
14
15
16
|
# File 'lib/onebox/engine/youtube_onebox.rb', line 13
def video_id
match = @url.match(/^https?:\/\/(www\.)?(youtube\.com\/watch\?v=|youtu\.be\/|youtube\.com\/embed\/)([a-zA-Z0-9_\-]{11})$/)
match && match[3]
end
|