Module: Virgo::VideoHelper

Defined in:
app/helpers/virgo/video_helper.rb

Instance Method Summary collapse

Instance Method Details

#video_provider(video_url = '') ⇒ Object



3
4
5
6
7
8
9
# File 'app/helpers/virgo/video_helper.rb', line 3

def video_provider(video_url='')
  if video_url.include?('vimeo')
    :vimeo
  else
    :youtube
  end
end

#vimeo_embed_url(video_url) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
# File 'app/helpers/virgo/video_helper.rb', line 22

def vimeo_embed_url(video_url)
  vimeo_regex = /https?:\/\/(www\.)?vimeo.com\/(\d+)/

  result = video_url.match(vimeo_regex)

  video_id = result ? result[2] : nil

  if video_id
    "https://player.vimeo.com/video/#{video_id}"
  end
end

#youtube_embed_url(youtube_url) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'app/helpers/virgo/video_helper.rb', line 11

def youtube_embed_url(youtube_url)
  if youtube_url[/youtu\.be\/([^\?]*)/]
    youtube_id = $1
  else
    # Regex from # http://stackoverflow.com/questions/3452546/javascript-regex-how-to-get-youtube-video-id-from-url/4811367#4811367
    youtube_url[/^.*((v\/)|(embed\/)|(watch\?))\??v?=?([^\&\?]*).*/]
    youtube_id = $5
  end
  "http://www.youtube.com/embed/#{youtube_id}"
end