|Home | Gallery | Stats | Downloads | Links | Scripts | Fuel Stats | Wiki | RSS|
How about you let me hang up with you and get back to you.-- Gregg M 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")