mp3act hacking

9 months or so ago, I installed mp3act, a PHP-based online MP3 streaming server. I’ve found that I really like it, but like everything else, it would be oh-so-much cooler with a few little tweaks. Development on it seems to have stagnated (no releases since mid 2005), so I’ve decided to hack on it a bit to make it do my bidding. So far, I’m really happy with the results.

Here are some of the issues I’m trying to address:

  • mp3act doesn’t deal well with albums containing multiple artists. It breaks each unique artist out into its own separate album. So for example, if you have an album called ‘great songs’ containing songs from artist a, artist b, and artist c, mp3act will create 3 albums called ‘great songs’, each containing songs from one of the three distinct artists. This is not what I want.
  • mp3act doesn’t handle artist sorting very well. If you have an album by Tom Petty and the Heartbreakers, mp3act displays it under ‘T’. If you want it correctly filed under ‘P’, the mp3 would need to be tagged ‘Petty, Tom and the Heartbreakers’, which again, is not what I want.
  • mp3act’s search and download features are a little lacking. The search results page allows you to play and/or add songs to playlists one by one, but there’s no ‘play all’ or ‘add all to playlist’ feature. And, it only allows downloads of albums. A ‘download playlist’ feature would be really useful.
  • With multiple-CD sets, if the songs on multiple discs are grouped under the same album name, mp3act will interleave the tracks together (disc 1 track 1, disc 2 track 1, disc 1 track 2, disc 2 track 2, …).

There are a few other little things, but those are the biggies. I’m taking a two-fold approach to dealing with these: tweaking the mp3act database tables for some, and tweaking the mp3act PHP code for others.

mp3act’s database schema is simple and easy to understand. It has a few quirks (biggest quirk: the year field is associated with albums, when in fact, it should be associated with songs), but I’ve found that I can get a lot done just by importing music into the database, and then going through manually and tidying things up. Specifically, I’ve corrected the multi-artist album problem and the multi-disc track interleaving problem this way.

To reconstruct a multi-artist album, first find all of its parts:

select * from mp3act_albums where album_name like '%name here%'

Note album IDs, which are typically consecutive. Then create a new artist, if necessary, for the album:

insert into mp3act_artists values(null, 'Various Artists', '')

Now create a new album:

insert into mp3act_albums values(null, 'name here', last_insert_id(), 'genre here', year, '')

Then, using the album IDs from the first query, re-associate songs with the new album:

update mp3act_songs set album_id = last_insert_id() where album_id between low id and high id

And finally, delete the old, no-longer-used albums.

delete from mp3act_albums where album_id between low id and high id

That’s it. Now, this works great, but it does introduce a couple of problems. First off, when you browse to one of these albums, it doesn’t show the artist name in the track listing. And secondly, there’s now no way to browse to the individual artists that make up the album (unless you have other albums by those artists). The first issue is a quick, easy fix to the PHP code. The second is more complicated. For this one, I added a separate ‘browse’ option that browses songs by artists, instead of albums. It was a bit of work, but not too bad.

And so it goes. Here’s a summary of all the changes I’ve made so far.

  • Fix database to deal better with multi-artist albums
  • Fix database to deal better with multi-cd track ordering
  • Show artist name in track listing for album/song browse
  • Add ‘browse for songs by artist’ feature
  • Create custom genres for some albums. This is easy to do and you are not limited to valid ID3 genres, which is nice, because they suck.
  • Modify ‘browse for albums by artist’ to not show artists with no corresponding albums
  • Fix artist sorting issue by adding ‘sort key’ field to albums table, and modifying artist entries where the sort key is different from the artist name

mp3act works very well for me with these changes, and the framework has the potential to do a lot more. Over time I’ll keep hacking on it to add features and improve its operation.

Followup… My next big “to do” is to make the album downloads more flexible. mp3act handles downloads by building a zip file on the fly, then sending this to the browser as an attachment. But the zipfile library it uses (which is included with the app) is kind of bare-bones, and it requires the mp3 library to have a certain directory structure. Looking at this library, it’s easy to see why downloads are not as flexible as I would like. Fortunately, PHP 5.2 now includes a much nicer built-in zipfile library, so the first step is to modify mp3act to use this. At that point, I should be able to greatly improve the download functionality.

2 thoughts on “mp3act hacking

  1. I have made some modifications as well to mp3act and posted the source on my blog. You may want to take a look… a few things of interest are that I added in code that allows you to download individual songs… it is all flash based, so you, which is part 2, i integrated a flash player that streams the songs… kinda nice if you don’t want to setup a media player to handle the streaming. Also integrated playlist functionality in the flash player. Most of the flash was built off of the XSPF flash player source… I believe that was what it was called. Anyways… solves a couple issues with that. I wanted to add in better db structures in the backend… like you implemented… and add a remove song function as well. I did fix up the library building functionality and fix other small issues… like playlist saving, id3 tag errors, add songs being more verbose, etc. etc…. Just tossing it out there if you are interested. http://dethknite.blogspot.com

  2. Great stuff. You should get involved in the development of Grammafone.com to implement your stuff.

    Regards,

    Patrick

Comments are closed.