Class: VgVimeo

Inherits:
Object show all
Defined in:
lib/acts_as_unvlogable/vg_vimeo.rb

Instance Method Summary collapse

Constructor Details

#initialize(url = nil, options = {}) ⇒ VgVimeo

Returns a new instance of VgVimeo.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/acts_as_unvlogable/vg_vimeo.rb', line 9

def initialize(url=nil, options={})
  # general settings
  @url = url
  @video_id = parse_url(url)

  if !(@vimeo_id =~ /^[0-9]+$/)
    r = Net::HTTP.get_response(URI.parse(url))

    if r.code == "301"
      @url = "http://vimeo.com#{r.header['location']}"
      @video_id = parse_url(@url)
    end
  end

  res = Net::HTTP.get(URI.parse("http://vimeo.com/api/v2/video/#{@video_id}.xml"))
  @feed = REXML::Document.new(res)
end

Instance Method Details

#download_urlObject



58
59
60
61
62
# File 'lib/acts_as_unvlogable/vg_vimeo.rb', line 58

def download_url
  request_signature = REXML::XPath.first( @feed, "//request_signature" )[0]
  request_signature_expires = REXML::XPath.first( @feed, "//request_signature_expires" )[0]
  "http://www.vimeo.com/moogaloop/play/clip:#{@video_id}/#{request_signature}/#{request_signature_expires}/?q=hd"
end

#durationObject



39
40
41
# File 'lib/acts_as_unvlogable/vg_vimeo.rb', line 39

def duration
  REXML::XPath.first( @feed, "//duration" )[0].to_s.to_i
end

#embed_html(width = 425, height = 344, options = {}, params = {}) ⇒ Object



47
48
49
# File 'lib/acts_as_unvlogable/vg_vimeo.rb', line 47

def embed_html(width=425, height=344, options={}, params={})
  "<object width='#{width}' height='#{height}'><param name='movie' value='#{embed_url}'></param><param name='allowFullScreen' value='true'></param><param name='allowscriptaccess' value='always'></param><embed src='#{embed_url}' type='application/x-shockwave-flash' allowscriptaccess='always' allowfullscreen='true' width='#{width}' height='#{height}'></embed></object>"
end

#embed_urlObject



43
44
45
# File 'lib/acts_as_unvlogable/vg_vimeo.rb', line 43

def embed_url
  "http://vimeo.com/moogaloop.swf?clip_id=#{@video_id}&amp;force_embed=1&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=0&amp;show_portrait=1&amp;color=ffffff&amp;fullscreen=1&amp;autoplay=0&amp;loop=0"
end

#flvObject



51
52
53
54
55
56
# File 'lib/acts_as_unvlogable/vg_vimeo.rb', line 51

def flv
  res = Net::HTTP.get(URI.parse("http://vimeo.com/42966264?action=download"))
  request_signature = res.split("\"signature\":\"")[1].split("\"")[0]
  request_cached_timestamp = res.split("\"cached_timestamp\":")[1].split(",")[0]
  "http://player.vimeo.com/play_redirect?clip_id=#{@video_id}&sig=#{request_signature}&time=#{request_cached_timestamp}&quality=sd&codecs=H264,VP8,VP6&type=moogaloop&embed_location="
end

#serviceObject



64
65
66
# File 'lib/acts_as_unvlogable/vg_vimeo.rb', line 64

def service
  "Vimeo"
end

#thumbnailObject



35
36
37
# File 'lib/acts_as_unvlogable/vg_vimeo.rb', line 35

def thumbnail
  REXML::XPath.first( @feed, "//thumbnail_medium" )[0].to_s
end

#titleObject



31
32
33
# File 'lib/acts_as_unvlogable/vg_vimeo.rb', line 31

def title
  REXML::XPath.first( @feed, "//title" )[0].to_s
end

#video_idObject



27
28
29
# File 'lib/acts_as_unvlogable/vg_vimeo.rb', line 27

def video_id
  @video_id
end