PDA

View Full Version : Random album


Spoonbase
2005-01-02, 19:15
what i really wanted was for a random album to play from my collection. this boils down to playing a random m3u from a list. the stumbling block (i finally learnt after a fair bit of nail biting) was that the results from file.readlines contain a closing \n and pls.load doesn't like the \n, so it needs to be cut off.

the only pain in using this script is that you'll need to create a file that contains the m3u files you'd like to randomize. from a command line in windows, i did this easily using

dir /b /s *.m3u > albums.txt

i then altered this file to change \ for / and, in my example, g: for smb://(machinename). the goal here is just to get the path recognizable in albums.txt. i then saved this file to the xbox.

of course, it would be much better if the script read through the directory structures, looking for m3u files, then picked a random one. i may get around to this, but i also envisage that this will delay the startup considerably, particularly if the music location is a networked drive.

here's the script if you're feeling brave enough to cut, paste, and ftp. i made this script execute automatically using autoexec.py:

import xbmc
from random import choice

pls = xbmc.playlist(0)

f = open('e:\\applications\\xbmc\\scripts\\albums.txt' , 'r')

albums = f.readlines()

f.close()

pls.load(choice(albums)[:-1])

xbmc.player().play(pls)

thanks to alexpoet for the scripts already written to get me started. feel free to use and abuse this script to your heart's content.