def build_music_playlist():
    utils.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 ( os.path.splitext( trivia_settings[ "trivia_music_file" ] )[ 1 ] ).lower() in ( "m3u", "pls", "asf", "ram" ):
            utils.log( "Music Playlist: %s" % trivia_settings[ "trivia_music_file" ] )
            if trivia_settings[ "trivia_music_file" ].endswith(".m3u"):
                track_location = parser.parse_m3u( trivia_settings[ "trivia_music_file" ], xbmc.getSupportedMedia('music') )
            elif trivia_settings[ "trivia_music_file" ].endswith(".pls"):
                track_location = parser.parse_pls( trivia_settings[ "trivia_music_file" ], xbmc.getSupportedMedia('music') )
            elif trivia_settings[ "trivia_music_file" ].endswith(".asf"):
                track_location = parser.parse_asf( trivia_settings[ "trivia_music_file" ], xbmc.getSupportedMedia('music') )
            elif trivia_settings[ "trivia_music_file" ].endswith(".ram"):
                track_location = parser.parse_ram( trivia_settings[ "trivia_music_file" ], 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 = absolute_listdir( trivia_settings[ "trivia_music_folder" ], media_type = "music", recursive = True )
    # shuffle playlist
    shuffle( track_location )
    for track in track_location:
        music_playlist.add( track,  )
 def fetch_trailers( self ):
     utils.log( "Fetching Trailers", xbmc.LOGNOTICE )
     # get watched list
     self._get_watched()
     # fetch all trailers recursively
     self.tmp_trailers = absolute_listdir( self.settings[ "trailer_folder" ], media_type = "video", recursive = True, contains = "-trailer" )
     # get a random number of trailers
     self._shuffle_trailers()
     # save watched list
     self._save_watched()
     # return results
     return self.trailers
Beispiel #3
0
 def fetch_trailers(self):
     utils.log("Fetching Trailers", xbmc.LOGNOTICE)
     # get watched list
     self._get_watched()
     # fetch all trailers recursively
     self.tmp_trailers = absolute_listdir(self.settings["trailer_folder"],
                                          media_type="video",
                                          recursive=True,
                                          contains="-trailer")
     # get a random number of trailers
     self._shuffle_trailers()
     # save watched list
     self._save_watched()
     # return results
     return self.trailers
Beispiel #4
0
def build_music_playlist():
    utils.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 (os.path.splitext(
                trivia_settings["trivia_music_file"])[1]).lower() in (".m3u",
                                                                      ".pls",
                                                                      ".asf",
                                                                      ".ram"):
            utils.log("Music Playlist: %s" %
                      trivia_settings["trivia_music_file"])
            if trivia_settings["trivia_music_file"].endswith(".m3u"):
                track_location = parser.parse_m3u(
                    trivia_settings["trivia_music_file"],
                    xbmc.getSupportedMedia('music'))
            elif trivia_settings["trivia_music_file"].endswith(".pls"):
                track_location = parser.parse_pls(
                    trivia_settings["trivia_music_file"],
                    xbmc.getSupportedMedia('music'))
            elif trivia_settings["trivia_music_file"].endswith(".asf"):
                track_location = parser.parse_asf(
                    trivia_settings["trivia_music_file"],
                    xbmc.getSupportedMedia('music'))
            elif trivia_settings["trivia_music_file"].endswith(".ram"):
                track_location = parser.parse_ram(
                    trivia_settings["trivia_music_file"],
                    xbmc.getSupportedMedia('music'))
        elif (os.path.splitext(
                trivia_settings["trivia_music_file"])[1]).replace(
                    ".", "") 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 = absolute_listdir(
                trivia_settings["trivia_music_folder"],
                media_type="music",
                recursive=True)
    # shuffle playlist
    shuffle(track_location)
    for track in track_location:
        music_playlist.add(track, )
Beispiel #5
0
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"):
    utils.log("_get_special_items() Started")
    video_list = []
    # return if not user preference
    if not items:
        utils.log("No Items added to playlist")
        return
    # if path is a file check if file exists
    if genre == "Movie Rating":
        folders, files = xbmcvfs.listdir(path)
        for f in files:
            if (os.path.splitext(f)[0]).lower() == mpaa.lower():
                path = os.path.join(path, f)
    if os.path.splitext(path)[1] and not path.startswith(
            "http://") and not xbmcvfs.exists(path):
        utils.log("_get_special_items() - File Does not Exist")
        return
    # parse playlist file
    if (os.path.splitext(path)[1]).lower() in (".m3u", ".pls", ".asf", ".ram"):
        utils.log("Video Playlist: %s" % path)
        if (os.path.splitext(path)[1]).lower() == ".m3u":
            video_list = parser.parse_m3u(path,
                                          xbmc.getSupportedMedia(media_type))
        elif (os.path.splitext(path)[1]).lower() == ".pls":
            video_list = parser.parse_pls(path,
                                          xbmc.getSupportedMedia(media_type))
        elif (os.path.splitext(path)[1]).lower() == ".asf":
            video_list = parser.parse_asf(path,
                                          xbmc.getSupportedMedia(media_type))
        elif (os.path.splitext(path)[1]).lower() == ".ram":
            video_list = parser.parse_ram(path,
                                          xbmc.getSupportedMedia(media_type))
        if not video_list:
            utils.log("Playlist empty or has unsupported media files")
            return
        try:
            for item in video_list[::-1]:
                utils.log("Checking Path: %s" % item)
                # format a title (we don't want the ugly extension)
                video_title = title or os.path.splitext(
                    os.path.basename(item))[0]
                # create the listitem and fill the infolabels
                listitem = _get_listitem(title=video_title,
                                         url=item,
                                         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 += [(
                        item,
                        listitem,
                    )]
                else:
                    playlist.add(item, listitem, index=index)
        except:
            traceback.print_exc()
    else:
        # set default paths list
        tmp_paths = [path]
        # if path is a folder fetch # videos/pictures
        if path.endswith("/") or path.endswith("\\"):
            utils.log("_get_special_items() - Path: %s" % path)
            # initialize our lists
            tmp_paths = absolute_listdir(path,
                                         media_type=media_type,
                                         recursive=True)
            shuffle(tmp_paths)
        # enumerate thru and add our videos/pictures
        for count in range(items):
            try:
                # set our path
                path = tmp_paths[count]
                utils.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:
                    utils.log(
                        "Looking for %d files, but only found %d" %
                        (items, count), 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"
                      ):
    utils.log( "_get_special_items() Started" )
    video_list = []
    # return if not user preference
    if not items:
        utils.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 ):
        utils.log( "_get_special_items() - File Does not Exist" )
        return
    # parse playlist file
    if ( os.path.splitext( path )[ 1 ] ).lower() in ( "m3u", "pls", "asf", "ram" ):
        utils.log( "Video Playlist: %s" % path )
        if ( os.path.splitext( path )[ 1 ] ).lower() == ".m3u":
            video_list = parser.parse_m3u( path, xbmc.getSupportedMedia( media_type ) )
        elif ( os.path.splitext( path )[ 1 ] ).lower() == ".pls":
            video_list = parser.parse_pls( path, xbmc.getSupportedMedia( media_type ) )
        elif ( os.path.splitext( path )[ 1 ] ).lower() == ".asf":
            video_list = parser.parse_asf( path, xbmc.getSupportedMedia( media_type ) )
        elif ( os.path.splitext( path )[ 1 ] ).lower() == ".ram":
            video_list = parser.parse_ram( path, xbmc.getSupportedMedia( media_type ) )
        if not video_list:
            utils.log( "Playlist empty or has unsupported media files" )
            return
        try:
            for item in video_list[::-1]:
                utils.log( "Checking Path: %s" % item )
                # format a title (we don't want the ugly extension)
                video_title = title or os.path.splitext( os.path.basename( item ) )[ 0 ]
                # create the listitem and fill the infolabels
                listitem = _get_listitem( title=video_title,
                                            url=item,
                                      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 += [ ( item, listitem, ) ]
                else:
                    playlist.add( item, listitem, index=index )
        except:
            traceback.print_exc()
    else:
        # set default paths list
        tmp_paths = [ path ]
        # if path is a folder fetch # videos/pictures
        if path.endswith( "/" ) or path.endswith( "\\" ):
            utils.log( "_get_special_items() - Path: %s" % path )
            # initialize our lists
            tmp_paths = absolute_listdir( path, media_type = media_type, recursive = True )
            shuffle( tmp_paths )
        # enumerate thru and add our videos/pictures
        for count in range( items ):
            try:
                # set our path
                path = tmp_paths[ count ]
                utils.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:
                    utils.log( "Looking for %d files, but only found %d" % ( items, count), xbmc.LOGNOTICE )
                    break
                else:
                    traceback.print_exc()