jammus / lastfm-node

Read and write to Last.fm with node.js
http://return12.tumblr.com/tagged/lastfm-node
MIT License
203 stars 33 forks source link

Scrobbles are ignored but Now Playing updates succesfully #39

Closed salazarbarrera closed 1 year ago

salazarbarrera commented 1 year ago

What the title says. I've been trying for a while, but I can't make the 'scrobble' method to work as intended.

How to replicate:

Let's say I want to scrobble "Let Me Love You" by "DJ Snake" and capture that data in a variable track and I have a valid session called mySession.

To update the Now Playing status I call this when the song starts:

oldDate = Date.now(); lastfm.update('nowplaying', mySession, { track: track } ); And that in turn would post this payload

track = Let Me Love You
&sk = MY_SESSION_KEY
&method = track.updateNowPlaying
&api_key = MY_KEY
&format = json
&artist = DJ Snake
&album = Encore
&api_sig = CALCULATED_SIGNATURE

to http://ws.audioscrobbler.com/2.0

and I successfully get this response in return:

{
   "nowplaying":{
      "artist":{
         "corrected":"0",
         "#text":"DJ Snake"
      },
      "track":{
         "corrected":"0",
         "#text":"Let Me Love You"
      },
      "ignoredMessage":{
         "code":"0",
         "#text":""
      },
      "albumArtist":{
         "corrected":"0",
         "#text":""
      },
      "album":{
         "corrected":"0",
         "#text":"Encore"
      }
   }
}

Everything fine there. But then, once the song is over, I call this:

lastfm.update('scrobble', mySession, { track: track, timestamp: oldDate });

which is equivalent to posting this payload to the API endpoint:

track = Let Me Love You
&timestamp = 1693943468324
&sk = SAME_SESSION_KEY
&method = track.updateNowPlaying
&api_key = SAME_API_KEY
&format = json
&artist = DJ Snake
&album = Encore
&api_sig = SAME_CALCULATED_SIGNATURE

but the scrobble is not registered, and I get this response:

{
   "scrobbles":{
      "scrobble":{
         "artist":{
            "corrected":"0",
            "#text":"DJ Snake"
         },
         "album":{
            "corrected":"0",
            "#text":"Encore"
         },
         "track":{
            "corrected":"0",
            "#text":"Let Me Love You"
         },
         "ignoredMessage":{
            "code":"1",
            "#text":""
         },
         "albumArtist":{
            "corrected":"0",
            "#text":""
         },
         "timestamp":"1693943468324"
      },
      "@attr":{
         "ignored":1,
         "accepted":0
      }
   }
}

Honestly I can't figure out why the song is ignored. The API documentation seem to suggest that the song is ignored because of the artist, but that doesn't make sense, in that case track.updateNowPlaying would ignore it too. I read the payload generated by your library, and everything looks fine, but for some reason, it doesn't work.

salazarbarrera commented 1 year ago

I'm an idiot, Date.now() returns milliseconds, using Math.floor(Date.now() / 1000) solved the problem. Closing this non-issue.