Class: Cherrypicker::Vimeo

Inherits:
Object
  • Object
show all
Defined in:
lib/cherrypicker/plugins/vimeo.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(link, opts = {}) ⇒ Vimeo

Returns a new instance of Vimeo.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/cherrypicker/plugins/vimeo.rb', line 15

def initialize(link, opts={})

  o = {
    :location => nil,
  }.merge(opts)

  @link         = link
  @filename     = ""
  @location     = o[:location]
  @download_url = ""

  hostname = "http://www.vimeo.com/moogaloop/play/clip"

  #the vimeo ID consists of decimal numbers in the URL
 vimeo_id = @link[/\d+/]
  response = Cherrypicker::remote_query("http://www.vimeo.com/moogaloop/load/clip:#{vimeo_id}")
  title = response.body[/<caption>(.*)<\/caption>/, 1] 
  request_signature = response.body[/<request_signature>(.*)<\/request_signature>/, 1] 
  request_signature_expires = response.body[/<request_signature_expires>(\d+)<\/request_signature_expires>/, 1]	
  hd = response.body[/<isHD>(.*)<\/isHD>/, 1] 

  if hd.to_i == 0
  download_url = ":#{vimeo_id}/#{request_signature}/#{request_signature_expires}"
 else
   download_url = ":#{vimeo_id}/#{request_signature}/#{request_signature_expires}/?q=hd"
  end

  @filename = title.delete("\"'").gsub(/[^0-9A-Za-z]/, '_') + ".mp4"
  #strip out _quote_ marks
  @filename.gsub!('_quot_', '')
  reply = Cherrypicker::remote_query("#{hostname}#{download_url}")
@download_url = reply.response['location']
end

Instance Attribute Details

#download_urlObject

Returns the value of attribute download_url.



13
14
15
# File 'lib/cherrypicker/plugins/vimeo.rb', line 13

def download_url
  @download_url
end

#filenameObject

Returns the value of attribute filename.



13
14
15
# File 'lib/cherrypicker/plugins/vimeo.rb', line 13

def filename
  @filename
end

Returns the value of attribute link.



13
14
15
# File 'lib/cherrypicker/plugins/vimeo.rb', line 13

def link
  @link
end

#locationObject

Returns the value of attribute location.



13
14
15
# File 'lib/cherrypicker/plugins/vimeo.rb', line 13

def location
  @location
end

Instance Method Details

#downloadObject



49
50
51
# File 'lib/cherrypicker/plugins/vimeo.rb', line 49

def download
  Cherrypicker::download_file(@download_url, :location => @location, :filename => @filename)
end