def build_music_playlist(): xbmc.log( "%s - Building Music Playlist" % log_message, level=xbmc.LOGNOTICE) xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "AudioPlaylist.Clear", "id": 1}') music_playlist = xbmc.PlayList( xbmc.PLAYLIST_MUSIC ) track_location = [] # check to see if playlist or music file is selected if int( _S_( "trivia_music" ) ) == 1: if _S_( "trivia_music_file" ).endswith(".m3u"): xbmc.log( "%s - Music Playlist: %s" % ( log_message, _S_( "trivia_music_file" ) ), level=xbmc.LOGDEBUG) playlist_file = open( _S_( "trivia_music_file" ), 'rb') saved_playlist = playlist_file.readlines() xbmc.log( "%s - Finished Reading Music Playlist" % log_message, level=xbmc.LOGDEBUG) track_info, track_location = parse_playlist( saved_playlist, xbmc.getSupportedMedia('music') ) elif os.path.splitext( _S_( "trivia_music_file" ) )[1] in xbmc.getSupportedMedia('music'): for track in range(100): track_location.append( _S_( "trivia_music_file" ) ) # otherwise else: if _S_( "trivia_music_folder" ): # search given folder and subfolders for files track_location = dirEntries( _S_( "trivia_music_folder" ), "music", "TRUE" ) # shuffle playlist count = 0 while count <6: shuffle( track_location, random ) count+=1 for track in track_location: music_playlist.add( track, )
def build_music_playlist(): log( "Building Music Playlist", xbmc.LOGNOTICE ) xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "AudioPlaylist.Clear", "id": 1}') music_playlist = xbmc.PlayList( xbmc.PLAYLIST_MUSIC ) track_location = [] # check to see if playlist or music file is selected if trivia_settings[ "trivia_music" ] == 1: if trivia_settings[ "trivia_music_file" ].endswith(".m3u"): log( "Music Playlist: %s" % trivia_settings[ "trivia_music_file" ] ) playlist_file = xbmcvfs.File( trivia_settings[ "trivia_music_file" ], 'rb') saved_playlist = playlist_file.read().splitlines() playlist_file.close() log( "Finished Reading Music Playlist" ) track_info, track_location = parse_playlist( saved_playlist, xbmc.getSupportedMedia('music') ) elif os.path.splitext( trivia_settings[ "trivia_music_file" ] )[1] in xbmc.getSupportedMedia('music'): for track in range(100): track_location.append( trivia_settings[ "trivia_music_file" ] ) # otherwise else: if trivia_settings[ "trivia_music_folder" ]: # search given folder and subfolders for files track_location = dirEntries( trivia_settings[ "trivia_music_folder" ], "music", "TRUE" ) # shuffle playlist shuffle( track_location ) for track in track_location: music_playlist.add( track, )
def _get_slides( paths, movie_mpaa ): # reset folders list tmp_slides = [] folders = [] # mpaa ratings mpaa_ratings = { "G": 0, "PG": 1, "PG-13": 2, "R": 3, "NC-17": 4, "--": 5, "": 6 } # enumerate thru paths and fetch slides recursively for path in paths: # get the directory listing entries = dirEntries( path, media_type="files", recursive="FALSE" ) # sort in case entries.sort() # get a slides.xml if it exists slidesxml_exists, mpaa, question_format, clue_format, answer_format, still_format = _get_slides_xml( path ) # check if rating is ok log( "Movie MPAA: %s" % movie_mpaa ) log( "Slide MPAA: %s" % mpaa ) if ( slidesxml_exists and mpaa_ratings.get( movie_mpaa, -1 ) < mpaa_ratings.get( mpaa, -1 ) ): log( "Slide Rating above movie rating - skipping whole folder", xbmc.LOGNOTICE ) continue # initialize these to True so we add a new list item to start question = clue = answer = still = True # enumerate through our entries list and combine question, clue, answer for entry in entries: # if folder add to our folder list to recursively fetch slides if ( entry.endswith( "/" ) or entry.endswith( "\\" ) ): folders += [ entry ] # sliders.xml was included, so check it elif ( slidesxml_exists ): # question if ( question_format and re.search( question_format, os.path.basename( entry ), re.IGNORECASE ) ): if ( question ): tmp_slides += [ [ "", "", "" ] ] clue = answer = still = False tmp_slides[ -1 ][ 0 ] = "__question__" + entry # clue elif ( clue_format and re.search( clue_format, os.path.basename( entry ), re.IGNORECASE ) ): if ( clue ): tmp_slides += [ [ "", "", "" ] ] question = answer = still = False tmp_slides[ -1 ][ 1 ] = "__clue__" + entry # answer elif ( answer_format and re.search( answer_format, os.path.basename( entry ), re.IGNORECASE ) ): if ( answer ): tmp_slides += [ [ "", "", "" ] ] question = clue = still = False tmp_slides[ -1 ][ 2 ] = "__answer__" + entry # still elif ( still_format and re.search( still_format, os.path.basename( entry ), re.IGNORECASE ) ): if ( still ): tmp_slides += [ [ "", "", "" ] ] clue = answer = question = False tmp_slides[ -1 ][ 0 ] = "__still__" + entry # add the file as a question TODO: maybe check for valid picture format? elif ( entry and os.path.splitext( entry )[ 1 ].lower() in xbmc.getSupportedMedia( "picture" ) ): tmp_slides += [ [ "", "", "__still__" + entry ] ] # if there are folders call again (we want recursive) if ( folders ): tmp_slides.extend( _get_slides( folders, movie_mpaa ) ) return tmp_slides
def _get_special_items( playlist, items, path, genre, title="", thumbnail=None, plot="", runtime="", mpaa="", release_date="0 0 0", studio="", writer="", director="", index=-1, media_type="video" ): xbmc.log( "%s - _get_special_items() Started" % log_message, level=xbmc.LOGDEBUG) # return if not user preference if not items: xbmc.log( "%s - No Items" % log_message, level=xbmc.LOGDEBUG) return # if path is a file check if file exists if os.path.splitext( path )[ 1 ] and not path.startswith( "http://" ) and not ( xbmc.executehttpapi( "FileExists(%s)" % ( path, ) ) == "<li>True" ): xbmc.log( "%s - _get_special_items() - File Does not Exist" % log_message, level=xbmc.LOGDEBUG) return # set default paths list tmp_paths = [ path ] # if path is a folder fetch # videos/pictures if path.endswith( "/" ) or path.endswith( "\\" ): xbmc.log( "%s - _get_special_items() - Path: %s" % ( log_message, path ), level=xbmc.LOGDEBUG) # initialize our lists tmp_paths = dirEntries( path, media_type, "TRUE" ) shuf = 0 while shuf <6: shuffle( tmp_paths, random ) shuf += 1 # enumerate thru and add our videos/pictures for count in range( items ): try: # set our path path = tmp_paths[ count ] xbmc.log( "%s - Checking Path: %s" % ( log_message, path ), level=xbmc.LOGDEBUG) # format a title (we don't want the ugly extension) title = title or os.path.splitext( os.path.basename( path ) )[ 0 ] # create the listitem and fill the infolabels listitem = _get_listitem( title=title, url=path, thumbnail=thumbnail, plot=plot, runtime=runtime, mpaa=mpaa, release_date=release_date, studio=studio or _L_( 32604 ), genre=genre or _L_( 32605 ), writer=writer, director=director ) # add our video/picture to the playlist or list if isinstance( playlist, list ): playlist += [ ( path, listitem, ) ] else: playlist.add( path, listitem, index=index ) except: if items > count: xbmc.log( "%s - Looking for %d files, but only found %d" % ( log_message, items, count), level=xbmc.LOGNOTICE) break else: traceback.print_exc()
def _get_special_items( playlist, items, path, genre, title="", thumbnail="", plot="", runtime="", mpaa="", release_date="0 0 0", studio="", writer="", director="", index=-1, media_type="video" ): log( "_get_special_items() Started" ) # return if not user preference if not items: log( "No Items added to playlist" ) return # if path is a file check if file exists if os.path.splitext( path )[ 1 ] and not path.startswith( "http://" ) and not xbmcvfs.exists( path ): log( "_get_special_items() - File Does not Exist" ) return # set default paths list tmp_paths = [ path ] # if path is a folder fetch # videos/pictures if path.endswith( "/" ) or path.endswith( "\\" ): log( "_get_special_items() - Path: %s" % path ) # initialize our lists tmp_paths = dirEntries( path, media_type, "TRUE" ) shuffle( tmp_paths ) # enumerate thru and add our videos/pictures for count in range( items ): try: # set our path path = tmp_paths[ count ] log( "Checking Path: %s" % path ) # format a title (we don't want the ugly extension) title = title or os.path.splitext( os.path.basename( path ) )[ 0 ] # create the listitem and fill the infolabels listitem = _get_listitem( title=title, url=path, thumbnail=thumbnail, plot=plot, runtime=runtime, mpaa=mpaa, release_date=release_date, studio=studio or "Cinema Experience", genre=genre or "Movie Trailer", writer=writer, director=director ) # add our video/picture to the playlist or list if isinstance( playlist, list ): playlist += [ ( path, listitem, ) ] else: playlist.add( path, listitem, index=index ) except: if items > count: log( "Looking for %d files, but only found %d" % ( items, count), xbmc.LOGNOTICE ) break else: traceback.print_exc()
def fetch_trailers( self ): log( "%s - Fetching Trailers" % logmessage, xbmc.LOGNOTICE ) # get watched list self._get_watched() # fetch all trailers recursively self.tmp_trailers = dirEntries( self.settings[ "trailer_folder" ], "video", "TRUE", "-trailer" ) # get a random number of trailers self._shuffle_trailers() # save watched list self._save_watched() # return results return self.trailers
def _get_slides(paths, movie_mpaa): # reset folders list tmp_slides = [] folders = [] # mpaa ratings mpaa_ratings = { "G": 0, "PG": 1, "PG-13": 2, "R": 3, "NC-17": 4, "--": 5, "": 6 } # enumerate thru paths and fetch slides recursively for path in paths: # get the directory listing entries = dirEntries(path, media_type="files", recursive="FALSE") # sort in case entries.sort() # get a slides.xml if it exists slidesxml_exists, mpaa, question_format, clue_format, answer_format, still_format = _get_slides_xml( path) # check if rating is ok log("Movie MPAA: %s" % movie_mpaa) log("Slide MPAA: %s" % mpaa) if (slidesxml_exists and mpaa_ratings.get(movie_mpaa, -1) < mpaa_ratings.get(mpaa, -1)): log("Slide Rating above movie rating - skipping whole folder", xbmc.LOGNOTICE) continue # initialize these to True so we add a new list item to start question = clue = answer = still = True # enumerate through our entries list and combine question, clue, answer for entry in entries: # if folder add to our folder list to recursively fetch slides if (entry.endswith("/") or entry.endswith("\\")): folders += [entry] # sliders.xml was included, so check it elif (slidesxml_exists): # question if (question_format and re.search(question_format, os.path.basename(entry), re.IGNORECASE)): if (question): tmp_slides += [["", "", ""]] clue = answer = still = False tmp_slides[-1][0] = "__question__" + entry # clue elif (clue_format and re.search( clue_format, os.path.basename(entry), re.IGNORECASE)): if (clue): tmp_slides += [["", "", ""]] question = answer = still = False tmp_slides[-1][1] = "__clue__" + entry # answer elif (answer_format and re.search(answer_format, os.path.basename(entry), re.IGNORECASE)): if (answer): tmp_slides += [["", "", ""]] question = clue = still = False tmp_slides[-1][2] = "__answer__" + entry # still elif (still_format and re.search( still_format, os.path.basename(entry), re.IGNORECASE)): if (still): tmp_slides += [["", "", ""]] clue = answer = question = False tmp_slides[-1][0] = "__still__" + entry # add the file as a question TODO: maybe check for valid picture format? elif (entry and os.path.splitext(entry)[1].lower() in xbmc.getSupportedMedia("picture")): tmp_slides += [["", "", "__still__" + entry]] # if there are folders call again (we want recursive) if (folders): tmp_slides.extend(_get_slides(folders, movie_mpaa)) return tmp_slides