lib/nanoc3/data_sources/last_fm.rb in nanoc3-3.0.2 vs lib/nanoc3/data_sources/last_fm.rb in nanoc3-3.0.3

- old
+ new

@@ -34,10 +34,11 @@ def items @items ||= begin require 'json' require 'time' require 'uri' + require 'enumerator' # Check configuration if self.config[:username].nil? raise RuntimeError, "LastFM data source requires a username in the configuration" end @@ -78,17 +79,28 @@ parsed_artist_data = JSON.parse(artist_data) raw_artist_info = parsed_artist_data['artist'] # Build data content = '' + + # Handle track dates + if raw_item['@attr'] && raw_item['@attr']['nowplaying'] == 'true' + track_played_at = Time.now + now_playing = true + else + played_at = Time.parse(raw_item['date']['#text']) + now_playing = false + end + attributes = { :name => raw_item['name'], :artist => { :name => raw_artist_info['name'], :url => raw_artist_info['url'] }, :url => raw_item['url'], - :played_at => Time.parse(raw_item['date']['#text']) + :played_at => track_played_at, + :now_playing => now_playing } identifier = "/#{i}/" mtime = nil # Build item