|Home | Gallery | Stats | Downloads | Links | Scripts | Fuel Stats | Wiki | RSS|
It doesn't matter if you engineer the "hostile takeover" of a business computer network, write a breakthrough video card driver, host a Linux Help Page or redeem some trapped soul from Microsoft Hell...it is the cumulation and communication of these efforts that drive us forward.-- Ken Starks Add quote.
While setting up my new music server today I had a small issue to take care of, setting up play lists. While I do like having tracks play randomly most of my music is meant to be listened to as a complete album, Dark Side of the Moon, for example.
Enter python, in less than 25 lines of code I came up with a solution. The below script parses through my music directory, shuffles the albums and then creates a play list file.
#!/usr/bin/env python import commands, os from random import * cmd = "find /export/home/music -type d" dirs = commands.getoutput(cmd).split("\n") shuffle(dirs) f = open("/usr/local/etc/ices-playlist.txt", "w") for dir in dirs: cmd = "find '%s' -maxdepth 1 -type f -name '*.mp3' -print | sort" %dir output = commands.getoutput(cmd) f.write(output) f.write("\n") f.close() os.system("sed -i '/^$/d' /usr/local/etc/ices-playlist.txt")