SCENARIO:
Abbiamo svariate canzoni in formato mp3 e desideriamo gestire la playlist di XMMS in maniera random andandoci a peschare un tot numero di MP3 e mandandoli in riproduzione.
SOURCE:
#!/usr/bin/python
# simple random XMMS playlist generator...
# (C) mozako at openbeer dot it
import os
import sys
import random
MP3_PATH = ""
PLAYLIST = ""
def banner():
print "=================================="
print "Random XMMS playlist generator..."
print "(C) mozako at openbeer dot it"
print "=================================="
def main():
banner()
try:
PLAYLIST = int(sys.argv[1])
MP3_PATH = sys.argv[2]
except IndexError:
print "Usage: " + "./" + sys.argv[0] + " PLAYLIST_LEN " + "MP3_path"
sys.exit(-1)
counter = 0
mp3s = 0
new_list = []
print "[+] Searching for mp3..."
for x in os.listdir(MP3_PATH):
x = x.replace(str("&"),str("\&"))
x = x.replace(str("'"),str("\\'"))
x = x.replace(" ","\ ")
x = x.replace("(","\(")
x = x.replace(")","\)")
new_list.append(x)
mp3s = mp3s + 1
print "[!] Found " + str(mp3s) + " mp3"
print "[+] MP3's added to playlist: \n"
while(counter < PLAYLIST):
texec = "xmms -Q " + MP3_PATH + str(new_list[random.randint(0,mp3s)])
print str(counter+1) + ") " + texec[8+len(MP3_PATH):]
os.system(texec)
counter = counter + 1
if __name__ == '__main__':
main()
TEST:
$ randompl.py 10 /home/mozako/Desktop/\[shared\]/Mp3/
==================================
Random XMMS playlist generator...
(C) mozako at openbeer dot it
==================================
[+] Searching for mp3...
[!] Found 218 mp3
[+] MP3's added to playlist:
1) 1.mp3
2) 2.mp3
3) 3.mp3
4) 4.mp3
5) 5.mp3
6) 6.mp3
7) 7.mp3
8) 8.mp3
9) 9.mp3
10) 10.mp3
Dando uno sguardo ad XMMS scopriremo che le tracce sono state correttamente aggiunte.