Class: Scrapescrobbler::Listener
- Inherits:
-
Object
- Object
- Scrapescrobbler::Listener
- Defined in:
- lib/scrapescrobbler/listener.rb
Instance Attribute Summary collapse
-
#lastfm ⇒ Object
Returns the value of attribute lastfm.
-
#started ⇒ Object
Returns the value of attribute started.
-
#station ⇒ Object
Returns the value of attribute station.
Instance Method Summary collapse
-
#initialize(station) ⇒ Listener
constructor
A new instance of Listener.
- #listen ⇒ Object
- #now_playing ⇒ Object
- #scrobble(song) ⇒ Object
- #update ⇒ Object
Constructor Details
#initialize(station) ⇒ Listener
Returns a new instance of Listener.
7 8 9 10 |
# File 'lib/scrapescrobbler/listener.rb', line 7 def initialize(station) @lastfm = Listener.authenticate @station = ::Scrapescrobbler::Stations.const_get(station.classify) end |
Instance Attribute Details
#lastfm ⇒ Object
Returns the value of attribute lastfm.
5 6 7 |
# File 'lib/scrapescrobbler/listener.rb', line 5 def lastfm @lastfm end |
#started ⇒ Object
Returns the value of attribute started.
5 6 7 |
# File 'lib/scrapescrobbler/listener.rb', line 5 def started @started end |
#station ⇒ Object
Returns the value of attribute station.
5 6 7 |
# File 'lib/scrapescrobbler/listener.rb', line 5 def station @station end |
Instance Method Details
#listen ⇒ Object
12 13 14 15 |
# File 'lib/scrapescrobbler/listener.rb', line 12 def listen raise if @started @started = DateTime.now end |
#now_playing ⇒ Object
35 36 37 38 |
# File 'lib/scrapescrobbler/listener.rb', line 35 def update if not @now_playing @now_playing end |
#scrobble(song) ⇒ Object
29 30 31 32 33 |
# File 'lib/scrapescrobbler/listener.rb', line 29 def scrobble song puts "Scrobbling #{song} @ #{song.time || Time.now}" @lastfm.track.scrobble(song.artist, song.title, song.time.utc.to_i || Time.now.utc.to_i, song.album) end |
#update ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/scrapescrobbler/listener.rb', line 17 def update playlist = Stations::Wyep::playlist if playlist and playlist.length > 0 then @now_playing = playlist.first playlist.each do |song| next if song == nil saved = song.save self.scrobble(song) if saved end end end |