Class: LastFM12::Track
- Inherits:
-
Object
- Object
- LastFM12::Track
- Defined in:
- lib/lastfm12.rb
Overview
a class for tracks
Instance Method Summary collapse
- #[](key) ⇒ Object
-
#album ⇒ Object
a album name of the track.
-
#artist ⇒ Object
alias creator.
-
#creator ⇒ Object
a creator name of the track.
-
#duration ⇒ Object
seconds of the track.
-
#image_url ⇒ Object
an URL of the track image.
-
#initialize(hash) ⇒ Track
constructor
A new instance of Track.
-
#length ⇒ Object
alias duration.
-
#location ⇒ Object
A redirection URL to another URL * Cannot make multi-connetion with the URL.
-
#name ⇒ Object
alias title.
-
#play(&block) ⇒ Object
execute a given block against the mp3 stream the block is given a segument data of mp3.
-
#station ⇒ Object
a station name.
-
#title ⇒ Object
a title of the track.
Constructor Details
#initialize(hash) ⇒ Track
Returns a new instance of Track.
246 247 248 249 250 251 |
# File 'lib/lastfm12.rb', line 246 def initialize(hash) if hash.class != Hash raise ArgumentError end @hash = hash end |
Instance Method Details
#[](key) ⇒ Object
253 254 255 |
# File 'lib/lastfm12.rb', line 253 def [](key) @hash[key] end |
#album ⇒ Object
a album name of the track
274 275 276 |
# File 'lib/lastfm12.rb', line 274 def album @hash[:album] end |
#artist ⇒ Object
alias creator
283 284 285 |
# File 'lib/lastfm12.rb', line 283 def artist creator end |
#creator ⇒ Object
a creator name of the track
279 280 281 |
# File 'lib/lastfm12.rb', line 279 def creator @hash[:creator] end |
#duration ⇒ Object
seconds of the track
288 289 290 |
# File 'lib/lastfm12.rb', line 288 def duration @hash[:duration].to_i end |
#image_url ⇒ Object
an URL of the track image
298 299 300 |
# File 'lib/lastfm12.rb', line 298 def image_url @hash[:image] end |
#length ⇒ Object
alias duration
293 294 295 |
# File 'lib/lastfm12.rb', line 293 def length duration end |
#location ⇒ Object
A redirection URL to another URL
- Cannot make multi-connetion with the URL.
- Cannot make a connection after second with the URL.
260 261 262 |
# File 'lib/lastfm12.rb', line 260 def location @hash[:location] end |
#name ⇒ Object
alias title
269 270 271 |
# File 'lib/lastfm12.rb', line 269 def name title end |
#play(&block) ⇒ Object
execute a given block against the mp3 stream the block is given a segument data of mp3
309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 |
# File 'lib/lastfm12.rb', line 309 def play(&block) uri = URI(@hash[:location]) ret = nil redirect_flag = true while redirect_flag host = uri.host path = uri.path path = path + "?" + uri.query if uri.query redirect_flag = false header = { 'Host' => host, 'User-Agent' => @hash[:user_agent], } Net::HTTP.new(host).request_get(path,header) do |res| if res.code.match(/^30[0-3]$/) uri = URI(res['location']) redirect_flag = true next end res.read_body(&block) end end # of "begin" ret end |
#station ⇒ Object
a station name
303 304 305 |
# File 'lib/lastfm12.rb', line 303 def station @hash[:station] end |
#title ⇒ Object
a title of the track
265 266 267 |
# File 'lib/lastfm12.rb', line 265 def title @hash[:title] end |