]>
gitweb.michael.orlitzky.com - dead/whatever-dl.git/blob - src/websites/bliptv.rb
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
22 class BliptvMediaFormat
23 # This is just a convenience class for parsing two parameters out of
24 # an RSS feed: 'url' and 'blip:role'.
29 url_regex
= /url=\"([^\"]+)\"/
30 role_regex
= /blip:role=\"([^\"]+)\"/
31 url_matches
= url_regex
.match(line
)
32 role_matches
= role_regex
.match(line
)
34 if not url_matches
.nil? and (url_matches
.length
) > 1
38 if not role_matches
.nil? and (role_matches
.length
> 1)
39 @role = role_matches
[1]
53 class Bliptv
< Website
55 VALID_BLIPTV_URL_REGEX
= /^(http:\/\
/)?blip\.tv\/.*?(\d+
)$/
57 def self.owns_url
?(url
)
58 return url
=~ VALID_BLIPTV_URL_REGEX
63 video_id
= self.parse_video_id()
64 rss_page_url
= "http://blip.tv/rss/flash/#{video_id}"
65 rss_data
= get_page_data(rss_page_url
)
66 video_url
= parse_video_url(rss_data
)
75 video_id_regex
= /(\d+)$/
76 matches
= video_id_regex
.match(@url)
78 if matches
.nil? or (matches
.length
< 2)
79 raise StandardError
.new("Couldn't parse the video id from the URL.")
86 def choose_best_format(formats
)
87 # 'formats' is assumed to be an array of BliptvMediaFormat. We
88 # return the best one (in terms of video quality).
90 if f
.url
.nil? or f
.role
.nil?
95 return f
if f
.role
== "Source"
98 if formats
.length
== 0
99 raise StandardError
.new("No valid formats in the RSS feed.")
101 # Return whatever's left if we don't have a 'Source' video.
106 def parse_video_url(page_data
)
107 # All of the elements containing video URLs begin like this.
108 media_regex
= /^\s*<media:content/
111 # Create an array of BliptvMediaFormat from lines matching
113 page_data
.lines
.each
do |line
|
114 if (line
=~ media_regex
)
115 bp
= BliptvMediaFormat
.new(line
)
120 # And return the URL from the best one.
121 # choose_best_format will raise an error if need be.
122 return choose_best_format(formats
).url