X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=src%2Fwebsites%2Fbliptv.rb;h=33205877c61152a2974412a27b0e2a5356f023c5;hb=57795a766ea4e59592f84426da3f34b3261ffb3b;hp=9322356a9e92353a31782e3a89c27500946b3939;hpb=d56c687299c6db6d4571c78ddb54e5da0d8b96ca;p=dead%2Fwhatever-dl.git diff --git a/src/websites/bliptv.rb b/src/websites/bliptv.rb index 9322356..3320587 100644 --- a/src/websites/bliptv.rb +++ b/src/websites/bliptv.rb @@ -17,57 +17,109 @@ # require 'src/website' +require 'cgi' + +class BliptvMediaFormat + # This is just a convenience class for parsing two parameters out of + # an RSS feed: 'url' and 'blip:role'. + def initialize(line) + @url = nil + @role = nil + + url_regex = /url=\"([^\"]+)\"/ + role_regex = /blip:role=\"([^\"]+)\"/ + url_matches = url_regex.match(line) + role_matches = role_regex.match(line) + + if not url_matches.nil? and (url_matches.length) > 1 + @url = url_matches[1] + end + + if not role_matches.nil? and (role_matches.length > 1) + @role = role_matches[1] + end + end + + def role + return @role + end + + def url + return @url + end +end + class Bliptv < Website - VALID_BLIPTV_URL_REGEX = /^(http:\/\/)?([[:alnum:]\-]+\.)?blip\.tv\/file\/(\d+)(.*)?$/ + VALID_BLIPTV_URL_REGEX = /^(http:\/\/)?blip\.tv\/.*?(\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 + video_id = self.parse_video_id() + rss_page_url = "http://blip.tv/rss/flash/#{video_id}" + rss_data = get_page_data(rss_page_url) + video_url = parse_video_url(rss_data) + + return video_url 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) + def parse_video_id() + video_id_regex = /(\d+)$/ + matches = video_id_regex.match(@url) - if not matches.nil? + if matches.nil? or (matches.length < 2) + raise StandardError.new("Couldn't parse the video id from the URL.") + else return matches[1] end + 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] + def choose_best_format(formats) + # 'formats' is assumed to be an array of BliptvMediaFormat. We + # return the best one (in terms of video quality). + formats.each do |f| + if f.url.nil? or f.role.nil? + formats.delete(f) + next + end + + return f if f.role == "Source" + end + + if formats.length == 0 + raise StandardError.new("No valid formats in the RSS feed.") + else + # Return whatever's left if we don't have a 'Source' video. + return formats[0] end + 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) + def parse_video_url(page_data) + # All of the elements containing video URLs begin like this. + media_regex = /^\s*