[livejournal] r23050: LJSUP-13713: Last.fm works incorrect

Committer: atyurin
LJSUP-13713: Last.fm works incorrect
U   trunk/htdocs/js/lastfm.js
Modified: trunk/htdocs/js/lastfm.js
===================================================================
--- trunk/htdocs/js/lastfm.js	2012-10-04 09:59:24 UTC (rev 23049)
+++ trunk/htdocs/js/lastfm.js	2012-10-04 10:53:58 UTC (rev 23050)
@@ -1,6 +1,6 @@
 LJ.LastFM = {
     /*
-     * Get current playing track in last.fm
+     * Get current playing (or just listened) track in last.fm
      * http://www.last.fm/api/show/user.getRecentTracks
      * @param {String} user LastFM username
      * @param {Function(Object)} callback Argument is the current track, see last.fm API
@@ -21,11 +21,16 @@
         }).done(function(res) {
             var tracks = res.recenttracks,
                 last = tracks && tracks.track[0],
-                nowPlaying = null;
+                nowPlaying = null,
+                date = null,
+                justListened = false;
 
             if (last.name && last.artist && last.artist.name) {
-                var date = +new Date(Number(last.date.uts) * 1000),
+
+                if (last.date) {
+                    date = +new Date(Number(last.date.uts) * 1000),
                     justListened = +new Date() - date < 300000;
+                }
 
                 if ((last['@attr'] && last['@attr'].nowplaying) || justListened) {
                     nowPlaying = {