Play albums in random order using XMMS
May. 21st, 2004 05:40 pmI have no idea if this is at all useful to anyone but me, but I ginned this up on the bus the other day and figured I ought to put it somewhere where others (and Google) can find it.
I keep my MP3 collection sorted by album, usually in the format:
Artist's Name - Album Name
And the interior of the folder sorted with a prefix indicating the track number. So, my goal was to generate an MPU file (suitable for XMMS and, I understand, WinAmp, although I haven't tested that) which would be random by album but sorted internally.
This script does that. You pass in the path to your MP3 collection (it understands Ogg files as well) and it spits out (on standard output) the MPU. It also sends to stderr a list of empty directories it encounters. This was written out of necessity, but learning how to use os.path.walk was extremely worth my time, given as my professional life is all about the quantitative display of filesystem status and process information.
The program is written in python, so it will run on Win32 and Mac OS X boxen with python installed. However, it might need a later version of python, perhaps 2.1 and up, for the error reporting to work.
One other thing: if you have a directory named "Miscellaneous" (capitalization is important in Mac and Un*x, might not work in Win32), the contents will be further randomized rather than sorted.
I keep my MP3 collection sorted by album, usually in the format:
Artist's Name - Album Name
And the interior of the folder sorted with a prefix indicating the track number. So, my goal was to generate an MPU file (suitable for XMMS and, I understand, WinAmp, although I haven't tested that) which would be random by album but sorted internally.
This script does that. You pass in the path to your MP3 collection (it understands Ogg files as well) and it spits out (on standard output) the MPU. It also sends to stderr a list of empty directories it encounters. This was written out of necessity, but learning how to use os.path.walk was extremely worth my time, given as my professional life is all about the quantitative display of filesystem status and process information.
The program is written in python, so it will run on Win32 and Mac OS X boxen with python installed. However, it might need a later version of python, perhaps 2.1 and up, for the error reporting to work.
One other thing: if you have a directory named "Miscellaneous" (capitalization is important in Mac and Un*x, might not work in Win32), the contents will be further randomized rather than sorted.
#!/usr/local/bin/python
import os
import os.path
import sys
import re
import random
import string
random.seed()
mpr = re.compile('(mp3|ogg)$', re.IGNORECASE)
class Collection:
def __init__(self, root):
self.root = root
self.c = []
def __call__(self, nullarg, fdir, filenames):
for i in filenames:
if mpr.search(i) and os.path.isfile(fdir '/' i):
self.c.append(fdir '/' i)
def rep(self):
if len(self.c):
if string.find(self.c[0], '/Miscellaneous/') == -1:
self.c.sort()
else:
random.shuffle( self.c )
if len( self.c ) == 0:
print>>sys.stderr, "Empty directory:", self.root
return self.c
def genAlbum(path, colpath):
collector = Collection(colpath '/' path)
os.path.walk(colpath '/' path, collector, None)
return collector.rep()
def genCollection(colpath):
dirs = filter( lambda a: os.path.isdir( colpath '/' a), os.listdir(colpath) )
random.shuffle(dirs)
ret = []
for i in dirs:
ret = ret genAlbum( i, colpath )
return ret
if __name__ == '__main__':
for i in genCollection( sys.argv[1] ):
print i[len(sys.argv[1]) 1:]
Re: How different is
Date: 2004-05-22 11:18 am (UTC)Redundancy, repetition, and redundancy... it's what makes the internet go 'round.
Re: How different is
Date: 2004-05-22 10:19 pm (UTC)Thanks for trying to understand me or the post. My thought process goes so crazy and it so hard to form it to make sense. Sometimes I wish I can control it or slow it down. Sometime I wish the letters would just quit jumping around and switching on me.
I really want to thank you in trying to comprehend it. Not everyone tries to.
Re: How different is
Date: 2004-05-23 07:34 pm (UTC)Just for the record, you make more sense than most people.
Susan