Class: Cherrypicker::Vimeo

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from PluginBase

inherited

Constructor Details

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

Returns a new instance of Vimeo.



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
48
49
50
51
# File 'lib/cherrypicker/plugins/vimeo.rb', line 19

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

Class Method Details

.matches_provider?(url) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/cherrypicker/plugins/vimeo.rb', line 15

def self.matches_provider?(url)
  url.include?("vimeo.com")
end

Instance Method Details

#downloadObject



53
54
55
# File 'lib/cherrypicker/plugins/vimeo.rb', line 53

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