Menu

Dave’s MP3 jukebox of his dreams–almost

Edna is a very easy-to-setup up MP3 jukebox written in Python and licensed under the GPL. I think a radio-like mode can be added to it pretty easily. Here’s the routine that selects songs to play:

def make_list(self, fullpath, url, recursive, shuffle, songs=None):
# This routine takes a string for 'fullpath' and 'url', a list for
# 'songs' and a boolean for 'recursive' and 'shuffle'. If recursive is
# false make_list will return a list of every file ending in '.mp3' in
# fullpath. If recursive is true make_list will return a list of every
# file ending in '.mp3' in fullpath and in every directory beneath
# fullpath.
#

if songs is None:
songs = []
for name in sort_dir(fullpath):
base, ext = os.path.splitext(name)
if extensions.has_key(string.lower(ext)):
# add the song's URL to the list we're building
songs.append(self.build_url(url, name) + '\n')

What it’s supposed to do is load a blacklist and overplay list and, when shuffling, compare the current element against the blacklist, and if it finds a match, randomly substitutes a song from the overplay list.

8 thoughts on “Dave’s MP3 jukebox of his dreams–almost”

Note too that sucking in the whole file via readlines() will end every line with a CR, which may not match your song list. You might want to compare blacklist[j][:-1] instead (which will chop off the last character of each line, usually a CR).

Talk to me tomorrow if it still doesn’t work, I’ve got my Python books a spare moment or two and maybe we can sort it out.

The == was the start of the problem. Getting the strings into the right format was another. It’s crudely working now but definitely in the only-works-for-me stage (hard-coded IP addresses in places, stuff like that, definitely not ready for prime time). Thanks much–it would have taken me a long time to figure that out.

Joseph, thanks for the link to the story. The biography of Scott and Zelda Fitzgerald I just read argued that Zelda was every Fitzgerald female antagonist, but the elements of his first love in Daisy Buchanan (from Gatsby) in particular are undeniable.

OK, programmers, another question for you: My hack works. But it’s slow. It’s fine with a half-dozen songs, but throw a hundred at it and it takes minutes to sort it all out on the Celeron-366 I’m using as a server. Any thoughts on a better sort algorithm to use?

While not addressing the need for a better sort, as soon as you have determined that song[i] matches blacklist[j] and adjusted it, you know that there is no need to to compare song[i] to anyother blacklist entry…

So, try adding a “break” after the assignment to song[i] to terminate the loop through the blacklist, and move on to the next song.

I just switched from IIS 5.1 to Apache 2.0 and needed something besides the ASP server I was using. Reading about Edna here made it pretty darned simple. One Python install, one Edna install, one config file edit, and Edna even displays my ‘cover.jpg’ graphic files by default. Simple, clean, and quick to setup. Thanks, guys!!