Merge pull request #2590 from techAPJ/patch-1

FIX: support start time in lazyYT
This commit is contained in:
Robin Ward 2014-07-28 11:06:36 -04:00
commit 1e20218e2f
1 changed files with 17 additions and 1 deletions

View File

@ -17,7 +17,7 @@ class Onebox::Engine::YoutubeOnebox
if video_id
# Avoid making HTTP requests if we are able to get the video ID from the
# URL.
html = "<div class=\"lazyYT\" data-youtube-id=\"#{video_id}\" data-width=\"480\" data-height=\"270\"></div>"
html = "<div class=\"lazyYT\" data-youtube-id=\"#{video_id}\" data-width=\"480\" data-height=\"270\" data-parameters=\"start=0\"></div>"
else
# Fall back to making HTTP requests.
html = raw[:html] || ""
@ -25,4 +25,20 @@ class Onebox::Engine::YoutubeOnebox
rewrite_agnostic(append_params(html))
end
def append_params(html)
result = html.dup
result.gsub! /(src="[^"]+)/, '\1&wmode=opaque'
if url =~ /t=(\d+h)?(\d+m)?(\d+s?)?/
h = Regexp.last_match[1].to_i
m = Regexp.last_match[2].to_i
s = Regexp.last_match[3].to_i
total = (h * 60 * 60) + (m * 60) + s
start_time = "\"start=#{total}\""
result.gsub!('"start=0"', start_time)
end
result
end
end