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 class Generic
< Website
23 VALID_GENERIC_URL_REGEX
= /^(http:\/\
/)?(www\.)?(.+)$/
25 def self.owns_url
?(url
)
26 return url
=~ VALID_GENERIC_URL_REGEX
31 page_data
= self.get_page_data(@url)
32 video_url
= self.parse_video_url(page_data
)
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)
46 # It's assumed that this will work, since @url is valid.
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
)
54 if not matches
.nil? || matches
.length
< 2
58 partial_video_url_regex
= /([^\=\"\']+\.(flv|mp4))/i
59 matches
= partial_video_url_regex
.match(page_data
)
61 if not matches
.nil? || matches
.length
< 2
62 return base_url + matches
[1]