April 6, 2007

GNUMP3d: A small, portable, MP3/OGG streaming server

Author: Joseph Quigley

Suppose you want to let a friend thousands of miles away listen to a song from your computer. Perhaps you just want to open up the music library on your computer to a select few while you're on another client on your local area network. Enabling file sharing might be overkill. Instead, you can use a streaming server such as GNUMP3d. Streaming servers are useful for more than Internet radio; they can let people choose individual songs from your music library and play them -- no need to configure NFS, SSH, or Samba.

GNUMP3d is a small, portable streaming server for Ogg Vorbis and MP3 files. It also supports a few video formats. It is designed to be stable, self-contained, and secure. Because it is written in Perl, it can be run on most Unix or Unix-based platforms (such as BSD, Linux, and Mac OS X), and even on Microsoft Windows. GNUMP3d's simple, themeable, Web-based interface is intuitive, and the package includes its own server, creating almost no dependencies.

GNUMP3d requires some configuration to set up properly. The server can be run as root or as a normal user. Most distros provide an init script to run GNUMP3 at boot time. Users who don't have access to system configuration files or just don't want to run GNUMP3d as root can run the server as a non-root user.

The first time GNUMP3d is run by a normal user, it returns an error message stating that it can't use the default log file, since normal users don't have permission to write to /var/log/gnump3d/access.log. To get around that, you have two options. The first is to copy the main configuration file (located at /etc/gnump3d/gnump3d.conf) to the normal user's home folder (~/.gnump3drc). The other is to edit the main config file to save logs to a different place by changing the "logfile" variable. I opted to copy the main config file to my home directory and change the "logfile" variable to write to a file in my home directory.

When run by a normal user, GNUMP3d always checks the home directory for the .gnump3drc config file. If it does not find it, GNUMP3d will use the system config file located in /etc. GNUMP3d also needs to know where to find the folder containing your music. You can create a symlink at /var/music (where GNUMP3d looks for music by default) and point it to your music folder, or change the "root" variable in the configuration file from /var/music to your music folder.

The config file has many more features. Security-minded people will want to read all the comments in the security section of the file. For starters, GNUMP3d can be run from an init script. To be more secure, the server can be run as a separate user (instead of root) by uncommenting the "user" variable and changing it, preferably to the user "nobody." GNUMP3d also supports usernames and passwords to keep out prying and unauthorized eyes.

Whenever GNUMP3d is run, it will index the music collection (either to build it or to look for changes). If the collection is larger than 15GB, this may take a while. To prevent GNUMP3d from indexing music every time it is run, you can use the --fast command line argument. The only downside to this approach is that if a file is deleted, GNUMP3d may try to play it anyway, not knowing about the file's current state.

To let users browse streamable music, GNUMP3d provides a small Web server. You can view it by pointing a browser at http://localhost:port, where port is the port that GNUMP3d is configured to run on. (It's usually port 8888, unless specified otherwise in the config file.) As long as a firewall isn't suppressing incoming connections from other computers, other users can browse and listen to music by pointing their browsers to the GNMP3d's host IP address or hostname.

GNUMP3d's Web interface is easy to use and is themeable. Most themes provide a link to a search box or display it on every page, and custom themes are easy to make. If you know a bit of HTML and CSS you can quick create a good-looking theme. The interface provides links to download and stream songs and create playlists filled with random songs or even the entire music library. You can browse and search music by ID3 tags. GNUMP3d also provides song information and statistics such as the bitrate, genre, file name, and the song's length. The statistics feature provides lists of the most popular songs, directories, users, most recent tracks served, the most popular user agents (usually the browser identification), the most popular clients (by IP address, hostname, and connection count), and what is currently playing on other people's computers.

You can listen to streamed songs from XMMS, VLC, RealPlayer, Amarok, WinAmp, Zinf, iTunes, or pretty much any other program that plays streamed MP3s or Ogg files and can support M3U playlists. GNUMP3d also provides the option to download music to any computer for users who would rather not stream it. I was, however, unable to download or stream several video files, and I could not find much information regarding video from GNUMP3d's site.

GNUMP3d is available in several popular Linux distribution repositories. It is easy to configure, set up, deploy, secure, and interact with. Because it's written in Perl, it is one of the most portable streaming servers around. With source code taking up less than two megabytes, the server might even run on embedded systems. It's a great way to share your music easily.

Click Here!