home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 May / maximum-cd-2010-05.iso / DiscContents / boxee-0.9.20.10711.exe / scripts / Lyrics / resources / lib / playlist.py < prev    next >
Encoding:
Python Source  |  2009-07-20  |  952 b   |  31 lines

  1. """
  2. This script will create a playlist by recursively searching MUSIC_PATH and adding songs.
  3. """
  4. import os
  5. import xbmc
  6.  
  7. # add all music paths here, no subdirectories needed
  8. MUSIC_PATH = ( "E:/Music", "F:/Music", )
  9. # add all music extensions wanted in lowercase
  10. MUSIC_EXT = xbmc.getSupportedMedia( "music" )
  11. # set to True to shuffle the playlist
  12. SHUFFLE = True
  13.  
  14. def create_playlist( base_path=MUSIC_PATH, shuffle=SHUFFLE ):
  15.     playlist = xbmc.PlayList( 0 )
  16.     playlist.clear()
  17.     for path in base_path:
  18.         os.path.walk( path, add_music, playlist )
  19.     if ( shuffle ): playlist.shuffle()
  20.     return playlist
  21.  
  22. def add_music( playlist, path, files ):    
  23.     for file in files:
  24.         ext = os.path.splitext( file )[ 1 ].lower()
  25.         if ( ext and ext in MUSIC_EXT ):
  26.             playlist.add( os.path.join( path, file ) )
  27.  
  28. if ( __name__ == "__main__" ):
  29.     playlist = create_playlist()
  30.     xbmc.Player().play( playlist )
  31.