# # 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 Bliptv < Website VALID_BLIPTV_URL_REGEX = /^(http:\/\/)?([[:alnum:]\-]+\.)?blip\.tv\/file\/(\d+)(.*)?$/ def self.owns_url?(url) return url =~ VALID_BLIPTV_URL_REGEX end def get_video_url() page_data = self.get_page_data(@url) filepath = parse_video_url(page_data) return filepath end protected; def parse_video_url(page_data) # First, try to find the MOV video. The source videos are usually # encoded with MOV. video_url_regex = /"Quicktime \(\.mov\)", "attribute" : "(.*?\.mov)/i matches = video_url_regex.match(page_data) if not matches.nil? return matches[1] end # If that didn't work, try the WMV format, which is occasionally # used for the source as well. video_url_regex = /"Windows Media \(\.wmv\)", "attribute" : "(.*?\.wmv)/i matches = video_url_regex.match(page_data) if not matches.nil? return matches[1] end # If neither of the source formats are present, just grab the # video URL from the Flash variable and be done with it. video_url_regex = /setPrimaryMediaUrl\("(.*?\.(flv|mov|wmv|mp4))/i matches = video_url_regex.match(page_data) if matches.nil? raise StandardError.new("Couldn't parse any of the video format URLs.") end return matches[1] end end