Class: BBCNet
- Inherits:
-
Object
- Object
- BBCNet
- Defined in:
- lib/bbcnet.rb
Defined Under Namespace
Classes: CacheMetaInfoDevice, MetaInfo
Constant Summary collapse
- RtspRegexp =
URI.regexp(['rtsp'])
- MmsRegexp =
URI.regexp(['mms'])
- DirectStreamRegexp =
URI.regexp(['mms', 'rtsp', 'rtmp', 'rtmpt'])
Class Method Summary collapse
-
.extractPid(url) ⇒ Object
get PID from BBC episode Url.
-
.getDirectStreamUrl(url) ⇒ Object
.asf/.ram => .wma/.ra.
-
.getPlayerConsoleUrl(url) ⇒ Object
convert epsode Url to console Url.
- .getTime(str) ⇒ Object
- .read(url) ⇒ Object
- .setProxy(url) ⇒ Object
Class Method Details
.extractPid(url) ⇒ Object
get PID from BBC episode Url
170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/bbcnet.rb', line 170 def self.extractPid(url) case url when %r!/(?:item|episode|programmes)/([a-z0-9]{8})! $1 when %r!^[a-z0-9]{8}$! url when %r!\b(b[a-z0-9]{7}\b)! $1 else raise "No PID in Url '%s'" % url end end |
.getDirectStreamUrl(url) ⇒ Object
.asf/.ram => .wma/.ra
185 186 187 188 189 190 191 192 193 194 195 |
# File 'lib/bbcnet.rb', line 185 def self.getDirectStreamUrl(url) old = '' while url != old and not url[DirectStreamRegexp] do old = url res = BBCNet.read(url) url = res[ DirectStreamRegexp ] || res[ UrlRegexp ] || old $log.debug { "new url:#{url}, old url:#{old}" } $log.debug { "no url in response '#{res}'" } if url[ UrlRegexp ] end url end |
.getPlayerConsoleUrl(url) ⇒ Object
convert epsode Url to console Url
165 166 167 |
# File 'lib/bbcnet.rb', line 165 def self.getPlayerConsoleUrl(url) "http://www.bbc.co.uk/iplayer/console/" + extractPid(url) end |
.getTime(str) ⇒ Object
153 154 155 156 157 |
# File 'lib/bbcnet.rb', line 153 def self.getTime(str) tm = str.match(/(\d{4})-(\d\d)-(\d\d)\w(\d\d):(\d\d):(\d\d)/) par = ((1..6).inject([]) do |a, n| a << tm[n].to_i end) Time.gm( *par ) end |
.read(url) ⇒ Object
198 199 200 201 202 203 204 205 206 207 208 209 |
# File 'lib/bbcnet.rb', line 198 def self.read(url) header = { "User-Agent" => self.randomUserAgent } if defined? @@proxy header[:proxy] = @@proxy end uri = URI.parse(url) res = Net::HTTP.start(uri.host, uri.port) do |http| http.get(uri.request_uri, header) end res.body end |
.setProxy(url) ⇒ Object
212 213 214 |
# File 'lib/bbcnet.rb', line 212 def self.setProxy(url) @@proxy = url end |