]>
gitweb.michael.orlitzky.com - dead/whatever-dl.git/blob - websites/veoh.rb
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
21 # Needed to download the page, which is in turn
22 # needed because it contains the video (redirect) URL.
29 VALID_VEOH_URL_REGEX
= /^(http:\/\
/)?(www\.)?veoh\.com\/videos\
/([[:alnum:]]+)$/
31 def self.owns_url
?(url
)
32 return url
=~ VALID_VEOH_URL_REGEX
37 # First, figure out the video id from the URL.
38 # Then, use the video id to construct the video details URL.
39 # Get the video details page, and parse the redirect
40 # URL from it. Now, I guess we *could* retrieve the video
41 # id from the redirect, but for now we're going to rely
42 # on our HTTP library to follow the redirect for us and
44 video_id
= self.parse_video_id()
45 details_url
= "http://www.veoh.com/rest/video/#{video_id}/details"
46 details_data
= get_page_data(details_url
)
47 redirect_url
= parse_redirect_url(details_data
)
49 # We trust our HTTP library to do the right thing here.
54 def get_video_filename()
55 return (self.parse_video_id() +
'.flv')
61 video_id_regex
= /[[:alnum:]]+$/
62 matches
= video_id_regex
.match(@url)
63 video_id
= matches
[0] if not matches
.nil?
69 # The main video page has the "video" URL buried
70 # in some javascript parameters.
71 def parse_redirect_url(page_data
)
72 redirect_url_regex
= /fullPreviewHashPath=\"(.*?)\"/
73 matches
= redirect_url_regex
.match(page_data
)
74 redirect_url
= matches
[1] if not (matches
.nil? || matches
.length
< 1)
80 def get_page_data(url
)
83 response
= Net
::HTTP.start(uri
.host
, uri
.port
) do |http
|