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
)
42 request_signature
= parse_request_signature(details_data
)
43 request_signature_expires
= parse_request_signature_expires(details_data
)
44 quality
= parse_quality(details_data
)
46 # Being slightly explicit about what we're doing here...
47 video_url
= "http://www.vimeo.com/moogaloop/play/clip:#{video_id}/#{request_signature}/#{request_signature_expires}/?q=#{quality}"
53 def get_video_filename()
54 # The default behavior is no good here, use the video
55 # id with an extension tacked onto it.
56 return (self.parse_video_id() +
'.flv')
65 # First, try to get the video id from the end of the URL.
66 video_id_regex
= /\/(\d+
)$/
67 matches
= video_id_regex
.match(@url)
70 # If that didn't work, the URL must be of the clip_id= form.
71 video_id_regex
= /clip_id\=(\d+)/
72 matches
= video_id_regex
.match(@url)
73 video_id
= matches
[1] if not (matches
.nil? || matches
.length
< 1)
75 video_id
= matches
[1] if not (matches
.nil? || matches
.length
< 1)
82 def parse_request_signature(page_data
)
84 rs_regex
= /<request_signature>(.*?)<\/request_signature
>/
85 matches
= rs_regex
.match(page_data
)
86 request_signature
= matches
[1] if not (matches
.nil? || matches
.length
< 1)
88 return request_signature
92 def parse_request_signature_expires(page_data
)
93 rse_regex
= /<request_signature_expires>(.*?)<\/request_signature_expires
>/
94 matches
= rse_regex
.match(page_data
)
95 request_signature_expires
= matches
[1] if not (matches
.nil? || matches
.length
< 1)
97 return request_signature_expires
101 def parse_quality(page_data
)
102 quality_regex
= /<isHD>([01])<\isHD>/
103 matches
= quality_regex
.match(page_data
)
104 is_hd
= matches
[1] if not (matches
.nil? || matches
.length
< 1)
110 # Standard-definition