]> gitweb.michael.orlitzky.com - dead/whatever-dl.git/blob - lib/whatever-dl/websites/generic.rb
Move all of the 'src' code under the more-standard 'lib'.
[dead/whatever-dl.git] / lib / whatever-dl / websites / generic.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 class Generic < Website
22
23 VALID_GENERIC_URL_REGEX = /^(http:\/\/)?(www\.)?(.+)$/
24
25 def self.owns_url?(url)
26 return url =~ VALID_GENERIC_URL_REGEX
27 end
28
29
30 def get_video_url()
31 page_data = self.get_page_data(@url)
32 video_url = self.parse_video_url(page_data)
33
34 return video_url
35 end
36
37
38 protected;
39
40 def base_url
41 # Return the website portion of the URL, e.g.
42 # http://www.example.com/
43 base_regex = /(http:\/\/.+?\/)/
44 matches = base_regex.match(@url)
45
46 # It's assumed that this will work, since @url is valid.
47 return matches[1]
48 end
49
50 def parse_video_url(page_data)
51 full_video_url_regex = /(http:\/\/[^\"\']+?\.(flv|mp4))/i
52 matches = full_video_url_regex.match(page_data)
53
54 if not matches.nil? || matches.length < 2
55 return matches[1]
56 end
57
58 partial_video_url_regex = /([^\=\"\']+\.(flv|mp4))/i
59 matches = partial_video_url_regex.match(page_data)
60
61 if not matches.nil? || matches.length < 2
62 return base_url + matches[1]
63 end
64
65 return nil
66 end
67
68
69 end