X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=lib%2Fwhatever-dl%2Fwebsites%2Fbliptv.rb;fp=lib%2Fwhatever-dl%2Fwebsites%2Fbliptv.rb;h=33205877c61152a2974412a27b0e2a5356f023c5;hb=6de408333ceb0d142f8fa0fef2571228e89c8fc1;hp=0000000000000000000000000000000000000000;hpb=8e886df259246365023322b78f58e4037cb536a4;p=dead%2Fwhatever-dl.git diff --git a/lib/whatever-dl/websites/bliptv.rb b/lib/whatever-dl/websites/bliptv.rb new file mode 100644 index 0000000..3320587 --- /dev/null +++ b/lib/whatever-dl/websites/bliptv.rb @@ -0,0 +1,125 @@ +# +# 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' +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:\/\/)?blip\.tv\/.*?(\d+)$/ + + def self.owns_url?(url) + return url =~ VALID_BLIPTV_URL_REGEX + end + + + def get_video_url() + 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_id() + video_id_regex = /(\d+)$/ + matches = video_id_regex.match(@url) + + 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 + + + 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 + + def parse_video_url(page_data) + # All of the elements containing video URLs begin like this. + media_regex = /^\s*