The NSLU2 NAS device from Linksys is a great little gadget. Thanks to the nslu2-linux project you can run a full Linux distribution like SlugOS or Debian on it. Beside using the box as small fileserver or torrent slave, you can turn it into a feature rich juke box, to play your mp3 library or even last.fm streams.
All you need is a cheap Linux supported USB soundcard (the one I've bought costs around 12€), a USB hub and you have to run one of the available Linux distributions. Information about setting that up can be found at http://nslu2-linux.org or on my NSLU2 page.
Because the NSLU2 has a relatively weak CPU, and processing compressed audio is a CPU expensive task there are some caveats when it comes to audio playback. Uwe Hermann provides a nice comparisson about audio playback and streaming playback on the NSLU2 using various tools.
It turns out that Ogg is way more CPU expensive than MP3. Ogg, together with an external HD turned out to work only with annoyong crackling sounds during playback. MP3 seems to play just fine, so I had to convert my whole library to MP3 format. The following little script can help you with that. You need to have lame and the vorbis-tools installed to be able to use it. I also suggest to, if possible, don't do the conversion on the NSLU2 itself, as this will literally take ages to finish on a large libarary!
ogg2mp3
#!/bin/bash
# @author Michael Klier <chi@chimeric.de>
BIN_OGGDEC=/usr/bin/oggdec
BIN_LAME=/usr/bin/lame
ARTIST=$(ogginfo "${1}" | grep ARTIST | cut -f2 -d\=)
TITLE=$(ogginfo "${1}" | grep TITLE | cut -f2 -d\=)
ALBUM=$(ogginfo "${1}" | grep ALBUM | cut -f2 -d\=)
TRACKNUMBER=$(ogginfo "${1}" | grep TRACKNUMBER | cut -f2 -d\=)
FILENAME=$(basename "${1}" .ogg)
cd $(dirname "${1}")
${BIN_OGGDEC} -o - "${1}" | ${BIN_LAME} -S -b 160 -h --add-id3v2 --tt "${TITLE}" --ta "${ARTIST}" --tl "${ALBUM}" --tn "${TRACKNUMBER}" - "${FILENAME}.mp3"
rm "${1}"
Just execute it in a directory containing .ogg files: Note that the script will
remove the .ogg files! You can also use a combination with find to make
the whole thing work for multiple directories at once.
The best option to play music on the NSLU2 IMHO is using MPD (Music Player Daemon) because it allows you to remote access the box with various front ends to control what's played. That way you don't have to constantly SSH to your NSLU2 to control the music player.
Setting up mpd on Debian is quite straight forward.
After the installation you have to edit /etc/mpd.conf to set your music and playlist directory as well as the bind address setting (I didn't need to touch the audio settings, they worked out of the box):
/etc/mpd.conf
music_directory "/mnt/data/media/audio/music"
playlist_directory "/mnt/data/media/audio/playlists"
bind_to_address "192.168.1.xxx"
For mpd in order to be able to serve the music it needs to own the files/directories. I suggest to also add a new group audio (if it doesn't exist already) to be able to access the music files as normal user.
% chown -R mpd:audio /mnt/data/media/audio/music
% chown mpd:audio /mnt/data/media/audio/playlists
% chmod -R 775 /mnt/data/media/audio/music
% chmod 775 /mnt/data/media/audio/playlists
After that, and whenever you add music to your library you have to re-create the mpd database.
% mpd --create-db
% /etc/init.d/mpd restart
Now you should be able to start playback by using one of the available mpd frontends like mpc for example. For details on how to do that please refer to the manual of the used frontend.
If you have an last.fm account, you can also log your listening habits by installing two additional programs.
% aptitude install lastmp lastfmsubmitd
The install process will ask you for your last.fm credentials. Note, at the time I've installed those the permissions for /var/run/lastfm and /var/log/lastfm where wrong after the installation and I had to grant write permissions for the lastfm user which is created during installation. You might need to restart both if that's the case for you as well.
% /etc/init.d/lastmp restart
% /etc/init.d/lastfmsubmitd restart
So, now he can log or listening habits. But, one of the main features I like about last.fm is to be able to listen to you friends/neighbours streams or streams by artists or certain tags. This is possible by using mc, a little shell script to fetch last.fm streams and adding them to the mpd playlist. Note that you need to have mpc installed to be able to use it. For example, listening to similar artists like Squarepusher all you have to do is:
The script also makes it possible to listen to neighbor streams etc., which is described in the help output.
That's it, we have a small, energy efficient jukebox
. The only downside of this setup is that you still have to either SSH to the box or use a mpd frontend on one of your other computers to control what's being played. One possibility to ommit that, I am evaluating at the moment, is to use a bluetooth adapter and control mpc over my cell phone. Another possiblity would be probably to use my Nintendo DS along with homebrew and SSH
. Once I've a ready to use solution I'll post it here as well.