Event Handler Script for LadioCast

Added this AppleScript to LadioCast to update from Spotify Radio to Sonos with proper track metadata when on local radio:

set lastName to “”
set lastArtist to “”
set lastAlbum to “”
tell application “Spotify”
set trackName to name of current track
set trackArtist to artist of current track
set trackAlbum to album of current track
end tell
if trackName is not lastName and trackArtist is not lastArtist and trackAlbum is not lastAlbum then
set lastName to trackName
set lastArtist to trackArtist
set lastAlbum to trackAlbum
tell application “LadioCast”
set metadata song to trackName & ” – ” & trackArtist & ” – ” & trackAlbum
end tell
end if
delay 15
end repeat

Seems to work. In LadioCast you can choose this saved script to run as an “event handler” when playing your Icecast stream. One field from Sonos “TuneIn Radio” that I still haven’t been able to propagate is “On Now” but the track metadata shows up correctly under “Information” and Sonos updates each track via Growl.

Avoiding the analog: Icecast2 for OS X, Sonos & Spotify Radio

Apparently, Spotify has finally released their Radio API to certain content management platforms, but until it’s built into Sonos the only way to actually get Spotify Radio on my ZP80 was to use the analog line-in.  What about creating an Icecast (Shoutcast, Podcast, etc.) local radio station that I tune in to on the Sonos locally? This would then avoid the analog hole (until I add a phonograph line stage).

There were a few sources I had to use to make this work, and I’ve only built/tested this under 32 bit 10.6.8 Snow Leopard (so your mileage may vary for 64 bit and/or more modern OS X machines).  Joao Ricardo’s blog post of  “Icecast Radio in Mac OS X” turns out to be a great starting point.  Note, that he recommends installing MacPorts, which may not strictly be necessary if you have Homebrew already installed.  I have not tried to port Icecast via Homebrew, but I imagine the installation would also work, as others have had success.   For example, here’s Josh Dzielak’s tutorial for Icecast & Darkice using Mountain Lion and Homebrew

So yes, per Joao’s instructions:

1) Install MacPorts (note: there are several dependencies, read up before you even install MacPorts)

2) In Terminal$: sudo port install icecast2

  • If doing Homebrew$: brew install icecast
  • Icecast vs. Icecast2?  I don’t know. You tell me internet, you tell me.
  • This took like 30 minutes using MacPorts on an old 32 bit Intel machine

3) Install Ladiocast.

4) Install Soundflower.

  • Reboot machine.

5) Make sure your admin/user has access/rights to “icecast -c /usr/etc/icecast.xml” as well as wherever an error for Icecast’s “access.log” and “error.log” files.  In my case they needed to added to /opt/local/etc.  You’ll need to adjust access with “chmod 755″ in this example.

6) Start playing some music on your Icecast server machine.  In OS X “Sound Preferences” make sure “Soundflower 2ch” is set as the “output device”; you can also “option + click” on the volume in the at the top right menu and select the source.

7) From Terminal$: icecast -c /usr/etc/icecast.xml

  • At this point Terminal will need to be open, obviously you can set this up as a background process, run on startup, etc. see Josh’s article linked above.

8) From within Ladiocast choose “Soundflower 2ch” as your source, click on the “main” button in Ladiocast.  You should see music bars making music.

  • From the menu in Ladiocast click on “Streamer 1” choose Icecast.  Set or whatever you machine’s IP is for the server.  The default user and pw is located the XML file.
  • For encoding, especially to work with iTunes and probably Sonos, I set it to AAC 320 kbps.  Ogg may in fact work with Sonos, I’ve not tried it.
  • Click “Connect” at the bottom there.

9) In a web browser, type in the IP for the Icecast server.  If said machine is localhost use which is the default port for the service. Click on the .m3u link and open in iTunes/Winamp or similar.  If you have music bars making music and you have a .m3u created you should hear music (double check OGG vs. AAC).

10) Final step: open the desktop Sonos App. Click “Manage” from the menu bar and then “Add Radio Station” and the enter (or whatever your IP is for the Icecast machine).  Create that as a favorite radio station.

11) Works for me.  If you want an Icecast radio station globally on WAN, well, poke those holes. Google a bit.  That’s not this blog entry.  Let’s hope Sonos adds Spotify Radio sooner than later.