Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions lib/youtube_addy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,28 @@ def self.extract_video_id(youtube_url)
match = format_regex.match(youtube_url)
return match[:id] if match
end

return
end

def self.youtube_embed_url(youtube_url, width = 420, height = 315)
vid_id = extract_video_id(youtube_url)
%(<iframe width="#{width}" height="#{height}" src="http://www.youtube.com/embed/#{vid_id}" frameborder="0" allowfullscreen></iframe>)
return unless vid_id

%(<iframe width="#{width}" height="#{height}" src="https://www.youtube.com/embed/#{vid_id}" frameborder="0" allowfullscreen></iframe>)
end

def self.youtube_regular_url(youtube_url)
vid_id = extract_video_id(youtube_url)
"http://www.youtube.com/watch?v=#{ vid_id }"
return unless vid_id

"https://www.youtube.com/watch?v=#{ vid_id }"
end

def self.youtube_shortened_url(youtube_url)
vid_id = extract_video_id(youtube_url)
"http://youtu.be/#{ vid_id }"
return unless vid_id

"https://youtu.be/#{ vid_id }"
end
end