2 # Copyright Michael Orlitzky
4 # http://michael.orlitzky.com/
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # http://www.fsf.org/licensing/licenses/gpl.html
24 VALID_VIMEO_URL_REGEX
= /^(http:\/\
/)?(www\.)?vimeo\.com\/(moogaloop\
.swf
\?clip_id
=)?(\d+
)/
26 def self.owns_url
?(url
)
27 return url
=~ VALID_VIMEO_URL_REGEX
32 # First, figure out the video id from the URL.
33 # Then, use the video id to construct the video details URL.
34 # Get the video details page, and parse the resulting XML for
35 # the junk we need to construct the video URL. Note that the file
36 # URL given in the XML is *not* valid.
37 video_id
= self.parse_video_id()
38 details_url
= "http://www.vimeo.com/moogaloop/load/clip:#{video_id}/local"
39 details_data
= get_page_data(details_url
)
41 request_signature
= parse_request_signature(details_data
)
42 request_signature_expires
= parse_request_signature_expires(details_data
)
43 quality
= parse_quality(details_data
)
45 referer
= "http://a.vimeocdn.com/p/flash/moogaloop/5.1.15/moogaloop.swf"
47 referer +
= "&time=#{request_signature_expires}"
48 self.headers
['Referer'] = referer
50 video_url
= "http://player.vimeo.com/play_redirect?clip_id=#{video_id}"
51 video_url +
= "&sig=#{request_signature}"
52 video_url +
= "&time=#{request_signature_expires}"
53 video_url +
= "&quality=#{quality}"
54 video_url +
= "&codecs=H264,VP8,VP6"
60 def get_video_filename()
61 # The default behavior is no good here, use the video
62 # id with an extension tacked onto it.
63 return (self.parse_video_id() +
'.flv')
72 # First, try to get the video id from the end of the URL.
73 video_id_regex
= /\/(\d+
)$/
74 matches
= video_id_regex
.match(@url)
77 # If that didn't work, the URL must be of the clip_id= form.
78 video_id_regex
= /clip_id\=(\d+)/
79 matches
= video_id_regex
.match(@url)
80 video_id
= matches
[1] if not (matches
.nil? || matches
.length
< 1)
82 video_id
= matches
[1] if not (matches
.nil? || matches
.length
< 1)
89 def parse_request_signature(page_data
)
91 rs_regex
= /<request_signature>(.*?)<\/request_signature
>/
92 matches
= rs_regex
.match(page_data
)
93 request_signature
= matches
[1] if not (matches
.nil? || matches
.length
< 1)
95 return request_signature
99 def parse_request_signature_expires(page_data
)
100 rse_regex
= /<request_signature_expires>(.*?)<\/request_signature_expires
>/
101 matches
= rse_regex
.match(page_data
)
102 request_signature_expires
= matches
[1] if not (matches
.nil? || matches
.length
< 1)
104 return request_signature_expires
108 def parse_quality(page_data
)
109 quality_regex
= /<isHD>([01])<\isHD>/
110 matches
= quality_regex
.match(page_data
)
111 is_hd
= matches
[1] if not (matches
.nil? || matches
.length
< 1)
117 # Standard-definition