]> gitweb.michael.orlitzky.com - dead/whatever-dl.git/blob - lib/whatever-dl/websites/veoh.rb
Move all of the 'src' code under the more-standard 'lib'.
[dead/whatever-dl.git] / lib / whatever-dl / websites / veoh.rb
1 #
2 # Copyright Michael Orlitzky
3 #
4 # http://michael.orlitzky.com/
5 #
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.
10 #
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.
15 #
16 # http://www.fsf.org/licensing/licenses/gpl.html
17 #
18
19 require 'src/website'
20
21
22 class Veoh < Website
23
24 VALID_VEOH_URL_REGEX = /^(http:\/\/)?(www\.)?veoh\.com\/.*?(v[[:alnum:]]+)$/
25
26 def self.owns_url?(url)
27 return url =~ VALID_VEOH_URL_REGEX
28 end
29
30
31 def get_video_url()
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 redirect
35 # URL from it. Now, I guess we *could* retrieve the video
36 # id from the redirect, but for now we're going to rely
37 # on our HTTP library to follow the redirect for us and
38 # save us a step.
39 video_id = self.parse_video_id()
40 details_url = "http://www.veoh.com/rest/video/#{video_id}/details"
41 details_data = get_page_data(details_url)
42 redirect_url = parse_redirect_url(details_data)
43
44 # We trust our HTTP library to do the right thing here.
45 return redirect_url
46 end
47
48
49 def get_video_filename()
50 return (self.parse_video_id() + '.flv')
51 end
52
53 protected;
54
55 def parse_video_id()
56 video_id_regex = /v[[:alnum:]]+$/
57 matches = video_id_regex.match(@url)
58 video_id = matches[0] if not matches.nil?
59
60 return video_id
61 end
62
63
64 # The main video page has the "video" URL buried
65 # in some javascript parameters.
66 def parse_redirect_url(page_data)
67 redirect_url_regex = /fullPreviewHashPath=\"(.*?)\"/
68 matches = redirect_url_regex.match(page_data)
69 redirect_url = matches[1] if not matches.nil? || matches.length < 2
70
71 return redirect_url
72 end
73
74
75 end