X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=lib%2Fwhatever-dl%2Fwebsites%2Fgeneric.rb;fp=lib%2Fwhatever-dl%2Fwebsites%2Fgeneric.rb;h=04537279cc2866c8473cecf651ea491a39588015;hb=6de408333ceb0d142f8fa0fef2571228e89c8fc1;hp=0000000000000000000000000000000000000000;hpb=8e886df259246365023322b78f58e4037cb536a4;p=dead%2Fwhatever-dl.git diff --git a/lib/whatever-dl/websites/generic.rb b/lib/whatever-dl/websites/generic.rb new file mode 100644 index 0000000..0453727 --- /dev/null +++ b/lib/whatever-dl/websites/generic.rb @@ -0,0 +1,69 @@ +# +# Copyright Michael Orlitzky +# +# http://michael.orlitzky.com/ +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# http://www.fsf.org/licensing/licenses/gpl.html +# + +require 'src/website' + +class Generic < Website + + VALID_GENERIC_URL_REGEX = /^(http:\/\/)?(www\.)?(.+)$/ + + def self.owns_url?(url) + return url =~ VALID_GENERIC_URL_REGEX + end + + + def get_video_url() + page_data = self.get_page_data(@url) + video_url = self.parse_video_url(page_data) + + return video_url + end + + + protected; + + def base_url + # Return the website portion of the URL, e.g. + # http://www.example.com/ + base_regex = /(http:\/\/.+?\/)/ + matches = base_regex.match(@url) + + # It's assumed that this will work, since @url is valid. + return matches[1] + end + + def parse_video_url(page_data) + full_video_url_regex = /(http:\/\/[^\"\']+?\.(flv|mp4))/i + matches = full_video_url_regex.match(page_data) + + if not matches.nil? || matches.length < 2 + return matches[1] + end + + partial_video_url_regex = /([^\=\"\']+\.(flv|mp4))/i + matches = partial_video_url_regex.match(page_data) + + if not matches.nil? || matches.length < 2 + return base_url + matches[1] + end + + return nil + end + + +end