''' Kaleidascrape v0.1 Code By: Ricky (kaleidascrape@distantcreations.com) "index" function (directory listing code) taken from a random web page (I forget where) The functionality here is an attempt to bring the XBMC one step closer to having the abilities of the extremely expensive Kaleidascape system (www.kaleidascape.com), with little to no cost. This script is a first attempt at adding easy video file queueing to XBMC. It lets you press two gamepad or remote control buttons while your My Videos section that result in the automatic queueing and launching of a series of "intro" video clips, followed by your main feature. You can add your home theater intros or trivia clips that you always want to play before your movies into the array below. You can also specify a directory from which this script will automatically randomly choose a single clip to play after your intro(s). The point of this is to have a directory full of sound system clips (DTS, DDS, THX, etc) and have only one automatically chosen and queued, giving you a different experience each time you watch a film. Finally, the script will add your "feature presentation" to the end of the playlist and then launch the playlist, seemlessly transitioning between your intros and your actual movie. It's a great way to impress your friends and family. Please see the comments throughout the actual code to customize this to your system. This is not the most elegant solution to this problem, but it works for me. As you can see the playlist takes your already queued up file and adds it to the end of a list of other clips and then plays everything. It allows you to press one button to queue the initial movie and another button to run the script and enjoy the movie. In case you don't have anywhere to download intro clips from, I suggest the following: - http://www.dvdloc8.com/list_dvd_clip.php - http://www.avsforum.com (check the home theater forum for personalized intros) # Added by chris hardy (christofer.hardy@gmail.com) Added the functionality as such - Trivia and Coke Ads (done) - Fixed Playlist syntax - Pulls Quicktime Trailer from apple.com/trailers (working) - Seperate out intros(done) - Seperate out clips (done) - Seperate out commercials (done) - Seperate out cartoons (done) - Seperate out studio banner - THX vob ### INSTALLATION ### Add the following code to the MyVideos section of keymap.xml: XBMC.RunScript(Q:\Scripts\kaleidascrape.py) This will allow you to press the X button in your MyVideos section to launch the script. You can also add it to the MyVideoTitles section to have it work there too. ''' ### PRIOR TO RUNNING THIS SCRIPT ### # You must press Y on your gamepad or the appropriate button on your remote to # # queue up your "main feature", which will be the last clip in your playlist. # # This is the first of two button presses that are required to make this work. # # # # Simply navigte to the movie that you want to watch and add it to the XBMC # # video playlist by pressing Y on the gamepad or the queue button on a remote. # ### ### #Importing all needed modules. I build on the backs of giants# import xbmc, xbmcgui, os, random, time, re # import QuickTimeBrowser_utils as qtb class Trivia(xbmcgui.Window): def __init__(self): self.image = xbmcgui.ControlImage(40,0,640,480,triviaDir+"0.png") self.addControl(self.image) def display(self, triviafile): self.image.setImage(triviafile) self.show time.sleep(triviaTime) self.close ### ADD YOUR INTROS THAT YOU ALWAYS WANT TO PLAY FIRST HERE ### intro_files= ['E:\\intros\\Home Theater Intro.vob', 'E:\\intros\\Feature Presentation.vob'] ### EDIT THIS TO POINT TO YOUR DIRECTORY CONTAINING YOUR OTHER INTRO CLIPS ### videos_dir = 'F:\\clips' videos_num = 2 triviaDir = 'F:\\Trivia\\' trivia_num = 25 triviaTime = 18 musicDir = 'F:\\music\\' commercial_dir = 'F:\\commer\\' commercial_num = 3 cartoon_dir = 'F:\\cartoon' cartoon_num = 2 studio_dir = 'F:\\studio' studio_num = 1 thx_dir = 'F:\\thx' thx_num = 1 intros_dir = 'F:\\intros' intros_num = 2 dts_dir = 'F:\\dts' dts_num = 1 trailer_dir = 'F:\\trailers' trailer_num = 4 psa_dir = 'F:\\psa' psa_num = 1 count = 0 DOWNLOAD_DIR = 'E:\\trailers' #Qucktime Values for the grabbing of New trailers# HTTP_TIMEOUT = 5.0 DEFAULT_SIZE = 2 DOWNLOAD_ATTEMPTS = 5 DEBUG = False PARSE_ON_RESTART = True #Seed the random variable based on the XBox system time# random.seed(time.time()) #Directory traversal function - returns an array of full file paths# def index(directory): # like os.listdir, but traverses directory trees stack = [directory] files = [] while stack: directory = stack.pop() for file in os.listdir(directory): fullname = os.path.join(directory, file) files.append(fullname) if os.path.isdir(fullname) and not os.path.islink(fullname): stack.append(fullname) return files def queueItems(dataDir,loop_num): dirlist = index(dataDir); count = (len(dirlist)) queuecount = 0 if count > 0: while queuecount < loop_num: randlist = random.randrange(1, count) plist.add(dirlist[randlist]) queuecount = queuecount + 1 #Get the XBMC video playlist# plist = xbmc.PlayList(2) #List of movies pre-queued into playlist# queuedmovies = [] #Grab queued movie('s) filename(s)# plistnumber = 0 while plistnumber < plist.size(): queuedmovies.append(plist[plistnumber].getfilename()) plistnumber = plistnumber + 1 #Clear the playlist for now# plist.clear() #Add intro files to XBMC video playlist# for intro_file in intro_files: if (os.path.isfile(intro_file)): plist.add(intro_file) #First we want the commercials, then the trailers, then the trivia, then the clips# queueItems(commercial_dir, commercial_num) #First we want the commercials, then the trailers, then the trivia, then the clips# queueItems(psa_dir, psa_num) #First we want the cartoons, then the trailers, then the trivia, then the clips# queueItems(cartoon_dir, cartoon_num) #First we want the cartoons, then the trailers, then the trivia, then the clips# queueItems(videos_dir, videos_num) #Get all the file paths in the above specified intro clips folder# #Create the Trivia & Coke showings# musicList = index(musicDir) count = (len(musicList)) mlist = xbmc.PlayList(1) #Create on the fly Playlist of anything in the musicDir, shuffle at end queuecount = 0 while queuecount < count: mlist.add(musicList[queuecount]) queuecount = queuecount + 1 mlist.shuffle() #Function to grab Trivia# trivialist = index(triviaDir); count = (len(trivialist)) queuecount = 0 mytrivia = Trivia() xbmc.Player().play(mlist) time.sleep(1) mytrivia.show() while queuecount < trivia_num: randtriv = random.randint(1, count) randInfo = trivialist[randtriv] randInfo1 = trivialist[randtriv] randInfo2 = trivialist[randtriv] randInfo1 = re.sub(r'([^-]+)b.jpg', r'\1a.jpg', str(randInfo1)) randInfo2 = re.sub(r'([^-]+)a.jpg', r'\1b.jpg', str(randInfo2)) match = re.match('.*?b.jpg', randInfo) match2 = re.match('.*?a.jpg', randInfo) if match: mytrivia.display(randInfo1) mytrivia.display(randInfo2) elif match2: mytrivia.display(randInfo1) mytrivia.display(randInfo2) else: mytrivia.display(randInfo1) queuecount = queuecount + 1 mytrivia.close() xbmc.Player().stop(mlist) del mytrivia #First we want the cartoons, then the trailers, then the trivia, then the clips# queueItems(intros_dir, intros_num) #First we want the cartoons, then the trailers, then the trivia, then the clips# queueItems(dts_dir, dts_num) #First we want the cartoons, then the trailers, then the trivia, then the clips# queueItems(thx_dir, thx_num) #First we want the cartoons, then the trailers, then the trivia, then the clips# queueItems(studio_dir, studio_num) #First we want the cartoons, then the trailers, then the trivia, then the clips# queueItems(trailer_dir, trailer_num) #Add the Feature Presentation(s) (previously queued) to the end of the playlist# for queuedmovie in queuedmovies: plist.add(queuedmovie) #Play the playlist# xbmc.Player().play(plist)