Inert Detritus The Internet's dust bunnies

Posted
10 January 2009 @ 11am

Hacking iScrobbler for multiple iPods

I’ve been on Last.fm since 2004. I love music, and I love statistics and data analysis, so when the site launched and I saw what they had planned, I immediately set up an account.

I’ve long used iScrobbler for a Mac client to submit plays to Last.fm: it’s lightweight, supports running in a menu bar-only mode, and has given me zero grief over the years. iScrobbler watches iTunes to detect and scrobble1 songs played as they happen. This obviously isn’t possible with iPod plays, so iScrobbler asks you to use a Recently Played playlist that it watches: after you sync an iPod, iTunes updates that playlist with all the tracks played while you were out, and iScrobbler diffs the playlists to know what to submit.

Until this summer, I used both my 2nd gen nano and my iPod photo to play music: the photo fit nearly everything I had, while the nano was great for the gym. I now use the nano, my iPhone 3G, and an iPod classic for playing music on the go, so my #FirstWorldProblem of making sure all iPod2 song plays get scrobbled to Last.fm hit a bit of a speed bump. I started interleaving plays on the devices: I’d listen to my iPhone on the bus ride in, use the nano at the gym, then listen some more on the iPhone before syncing them back to iTunes.

To support the iPod, iScrobbler takes snapshots of the iTunes Library, and compares the Last Played and Play Counts in a playlist you configure3 to figure out what songs you listened to.

After an iPod update, iScrobbler will take the last played time of the last played song, sets this as the new “iTunes Last Played Time”, and scrobble everything played since the previous iTunes Last Played Time.4 With interleaved plays, this quickly becomes a problem: when you sync iPod A, iScrobbler bumps the iTunes LPT; any plays on iPod B that happened before that time are now “lost”, since that iPod hasn’t been synced, and they fall before that timestamp. Those plays are very difficult to get back later, so this is a problem worth avoiding5

Playlist snapshots let iScrobbler work around an iTunes/Last.fm problem: iTunes only stores the Last Played time, but Last.fm wants a timestamp for every song play. If iScrobbler sees a song which incremented Play Count by more than 1, it has to “synthesize” the play. The song must have a timestamp for Last.fm submission, so iScrobbler finds gaps in the play times where no songs were playing, and invents reasonable timestamps for any songs needing a time.

So, for the past few months, I’ve been closing iScrobbler before syncing my iPods. This let me sync both iPods with iTunes, which updated all the songs’ metadata, then launch iScrobbler and tell it to manually update from the iPod playlist.



A few weeks ago, instead of just closing iScrobbler before an iPod sync, I started running iTunes with iScrobbler completely closed. All my plays on the desktop go into the same playlist6 as any tracks my iPods play, so they would get picked up like the rest of my iPod plays.

iPods don’t cross-fade playback, so the Start Time of one song7 perfectly adjoins the Last Played time of the track before it. Last.fm is very particular about track lengths and timestamps, and won’t let you submit plays that overlap, so if that happens, iScrobbler drops the second track to avoid API issues.

The writing on the wall is clear: if you have cross-fade playback enabled in iTunes and play songs with iScrobbler closed, 50% of your desktop plays will be dropped by iScrobbler as overlapping. I haven’t filed a bug against the API on this yet8. You can work around it by turning off cross-fade playback in iTunes; that makes iTunes behave identically to iPods with playback, and you can keep iScrobbler closed for days at a time with no adverse effects.



Postscript: the iPhone 2.0 bug where Play Counts and Last Played times weren’t updated just about killed me. I had to exhibit extraordinary self-control to only play music on the nano, since it was the only device that properly updated the song metadata.

Yes, I think a play count will fall through the cracks if you play it once on both devices; iTunes will crush of the device’s play count with the other’s. I haven’t tested this to confirm or deny it, however.

  1. Submit, in iScrobber/AudioScrobbler/Last.fm speak []
  2. For the sake of brevity, “iPod” includes iPhones. []
  3. This is best set to a “Recently Played” smart playlist []
  4. It does this so takes less time and work to avoid duplicating submissions. Duplicate submissions are bounced by the Last.fm API with great prejudice. []
  5. I typically resort to leaving a playlist running overnight to fake them. []
  6. “Recently Played” captures anything played in the last few weeks []
  7. iScrobbler always has it, so iTunes must be bookkeeping it somewhere. As far as I can tell, this is stored behind-the-scenes and not exposed in the iTunes UI []
  8. There needs to be a few second “grace period” for device clock skew and cross-fading playback []

6 Comments

Posted by
Matthew Arevalo
10 January 2009 @ 11am

Thanks C‑note. I will be trying this very soon.


Posted by
Jon
10 January 2009 @ 4pm

I use an iPhone and iPod nano with iScrobbler. Here’s what I do. From menu bar, select iScrobbler, then “Pause Submissions.” Sync the iPhone. Disconnect. Go back to menu bar, and “Resume Submissions”. Sync the iPod nano. When that finishes, iScrobbler uploads the union of iPhone and nano’s combined Recently Played.


Posted by
Christopher Bowns
10 January 2009 @ 5pm

I never knew whether I could trust “Pause Submissions”, so I’d never tried it. That’s very good to know, thanks, I’ll give that a try.


Posted by
Christopher Bowns
15 January 2009 @ 10pm

A post by the iScrobbler doesn’t seem to back that up: it appears that button can be used to silently drop plays.


Posted by
amarshwren
24 January 2009 @ 9pm

Thanks for sharing this. I wonder how many last.fm scrobblers are as fanatic. I’ve spent a lot of time obsessing over making “every play count,” although I’ve mellowed enough to not grieve over listening to CDs in the car anymore ;)


Posted by
Digital Book Reader
20 December 2009 @ 11pm

This is very informative post. I love this and I will check your blog again.