Class: Umatic::Vimeo

Inherits:
Channel show all
Defined in:
lib/channel/vimeo.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Channel

channels, inherited, #initialize, open, #process

Constructor Details

This class inherits a constructor from Umatic::Channel

Class Method Details

.supports?(url) ⇒ Boolean

Returns:

  • (Boolean)


6
7
8
# File 'lib/channel/vimeo.rb', line 6

def self.supports? url
	url.match(/https?:\/\/vimeo.com\/[\d+]{6,10}/)
end

Instance Method Details

#correct_url(url) ⇒ Object



51
52
53
# File 'lib/channel/vimeo.rb', line 51

def correct_url(url)
	HTTPClient.instance.open(url)
end

#parse(page) ⇒ Object



10
11
12
13
14
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
48
49
# File 'lib/channel/vimeo.rb', line 10

def parse page
	page.delete!("\n")
	re = / = {config:(.+),assets:/
		json_match = page.match(re)
	raise "Unable to retrieve video info" unless json_match
	json = json_match[1]

	config = JSON.parse(json)
	title = config['video']['title']
	description = ''
	sources = []

	sig       = config['request']['signature']
	timestamp = config['request']['timestamp']
	video_id  = config['video']['id']

	files = config['video']['files']
	files.each do |codec, qualities|
		qualities.each do |quality|
			s = OpenStruct.new
			s.format = 'mp4'
			s.url = correct_url "http://player.vimeo.com/play_redirect?"\
				"clip_id=#{video_id}"\
			"&sig=#{sig}"\
			"&time=#{timestamp}"\
			"&quality=#{quality}"\
			"&codecs=#{codec.upcase}"\
			"&type=moogaloop_local"\
				"&embed_location=&seek=0"
			s.info = "#{codec} - #{quality}"
			sources << s
		end
	end

	{
		:title 				=> title,
		:description 	=> description,
		:sources			=> sources
	}
end