2006-02-19, 15:59
hi,
i've been after a couple of scripts that load a playlist on start of xbmc, and shuffle the list to keep it interesting! - found a few lists from the internet, and i noticed there are a few posts here asking how to do it. so i have posted the working scripts, that did it for me! :thumbsup: :thumbsup:
autoexec.py script:
startup.py script
works for me, i can't code to save my life but i might be able to help where i can.
of course all credit goes to who ever made this script in the first place!! :bowdown:
i've been after a couple of scripts that load a playlist on start of xbmc, and shuffle the list to keep it interesting! - found a few lists from the internet, and i noticed there are a few posts here asking how to do it. so i have posted the working scripts, that did it for me! :thumbsup: :thumbsup:
autoexec.py script:
Quote:# auto execute scripts when xbmc starts, place this file in xbmchome\scripts\
#
# note: - do not execute more than one script at a time which asks for user input!
import xbmc
xbmc.executescript('e:\\apps\\xbmc\\scripts\\startup.py')
startup.py script
Quote:''' vim: ts=8 sw=4 noexpandtab
author: rune hammersland
version: 0.3
xbox media center comes with a script to play an mp3 file at startup
(startupmp3). this script will load a playlist if it exists, and if not,
traverse a directory and load all relevant music files. it is intended as a
replacement for startupmp3, and enables you to listen to a playlist, or all
music files in a given directory.
changelog:
2005-05-27 13:10:33 - rune hammersland:
* added possibility for multiple playlists.
* added possibility for multiple music dirs.
'''
import xbmc
import os
# ---------------------------------------- #
# "configuration"
# ---------------------------------------- #
# change this to your playlist(s).
# written like this: ['path\\to\\plist1', 'to\\plist2', 'plist\\3']
playlist_files= ['e:\\apps\\xbmc\\albums\playlists\music\\xbmc.m3u']
# dirs(s) to traverse if playlist does not exist. nb: no trailing slash.
# written like this: ['path\\to\\dir1', 'to\\dir2', 'dir\\3']
music_dirs = ['e:\\media\\music', 'f:\\media\\music']
# shuffle playlist if this var equals 1.
shuffle_files = 1
# ---------------------------------------- #
# code
# ---------------------------------------- #
# function for adding files to playlist
def add_files(pl, dirname, names):
for filename in names:
if (os.path.isfile(dirname + "\\" + filename)):
add = 0
# check extension of file.
if (filename[-4:] == ".mp3"): add = 1
if (filename[-4:] == ".ogg"): add = 1
if (filename[-4:] == ".wav"): add = 1
if (filename[-5:] == ".flac"): add = 1
# if file is to be added, do it.
if (add == 1): pl.add(dirname + "\\" + filename)
elif (os.path.isdir(dirname + "\\" + filename)):
os.path.walk(dirname + "\\" + filename, add_files, pl)
# get music playlist from xbmc
plist = xbmc.playlist(0)
plist.clear()
# load playlist if it exists
for playlist_file in playlist_files:
if (os.path.isfile(playlist_file)):
plist.load(playlist_file)
# else, find all available music
else:
for music_dir in music_dirs:
os.path.walk(music_dir, add_files, plist)
# do the shuffle!
if (shuffle_files == 1): plist.shuffle()
xbmc.player().play(plist)
works for me, i can't code to save my life but i might be able to help where i can.
of course all credit goes to who ever made this script in the first place!! :bowdown: