def main():
    contextMenuSource = sys.listitem.getfilename()

    # see if the user selected a directory. display an error and exit if the
    # user selected anything other than a directory
    jsonRequest = pykodi.get_base_json_request('Files.GetDirectory')
    jsonRequest['params'] = {'directory': contextMenuSource}
    jsonResponse = pykodi.execute_jsonrpc(jsonRequest)
    if 'error' in jsonResponse:
        xbmcgui.Dialog().notification(addon.getLocalizedString(32400), \
                                      addon.getLocalizedString(32406), \
                                      xbmcgui.NOTIFICATION_WARNING)
        pykodi.log(str(jsonResponse), xbmc.LOGNOTICE)
        sys.exit(1)

    # these parameters do not apply if the user chose the "Run Cinder from here"
    # context menu option

    # Changing these variables will not change how Cinder behaves
    additionalSourceList = []
    additionalSourceWeightList = []
    maximumSourceWeight = 100

    cinderRandomPlayer = CinderRandomPlayer.CinderRandomPlayer(
        additionalSourceList, additionalSourceWeightList, maximumSourceWeight,
        contextMenuSource)
    cinderRandomPlayer.playRandomEpisodes()
Ejemplo n.º 2
0
    def __init__(self, additionalSourceList, additionalSourceWeightList, maximumSourceWeight, contextMenuSource=None):
        self.addon = xbmcaddon.Addon()
        self.configSettings = {}
        self.maximumSourceWeight = maximumSourceWeight
        self.contextMenuSource = contextMenuSource

        # seed the random number generator with the current time
        random.seed()

        pykodi.log("maximumSourceWeight: " + str(self.maximumSourceWeight),  xbmc.LOGDEBUG)

        # check for invalid input
        if len(additionalSourceList) != len(additionalSourceWeightList):
            xbmcgui.Dialog().notification(self.addon.getLocalizedString(32400), 
                                          self.addon.getLocalizedString(32403), 
                                          xbmcgui.NOTIFICATION_WARNING)
            sys.exit(1)
        if maximumSourceWeight <= 0 or maximumSourceWeight > 1000000:
            xbmcgui.Dialog().notification(self.addon.getLocalizedString(32400), 
                                          self.addon.getLocalizedString(32404), 
                                          xbmcgui.NOTIFICATION_WARNING)
            sys.exit(1)


        # aquire the users configuration settings
        self.aquireConfigSettings(additionalSourceList, additionalSourceWeightList)
def main():
    contextMenuSource = sys.listitem.getfilename()

    # see if the user selected a directory. display an error and exit if the 
    # user selected anything other than a directory 
    jsonRequest = pykodi.get_base_json_request('Files.GetDirectory')
    jsonRequest['params'] = {'directory': contextMenuSource}
    jsonResponse = pykodi.execute_jsonrpc(jsonRequest)
    if 'error' in jsonResponse: 
        xbmcgui.Dialog().notification(addon.getLocalizedString(32400), \
                                      addon.getLocalizedString(32406), \
                                      xbmcgui.NOTIFICATION_WARNING)
        pykodi.log(str(jsonResponse), xbmc.LOGNOTICE)
        sys.exit(1)

    # these parameters do not apply if the user chose the "Run Cinder from here"
    # context menu option

    # Changing these variables will not change how Cinder behaves
    additionalSourceList = []
    additionalSourceWeightList = []
    maximumSourceWeight = 100

    cinderRandomPlayer = CinderRandomPlayer.CinderRandomPlayer(additionalSourceList, additionalSourceWeightList, maximumSourceWeight, contextMenuSource)
    cinderRandomPlayer.playRandomEpisodes()
Ejemplo n.º 4
0
    def aquireConfigSettings(self, additionalSourceList, additionalSourceWeightList):
        settings = xbmcaddon.Addon(id='script.cinder')

        configKeyList = [ 'WatchedRandomMode', 'NumberOfShows', 'ShufflePlaylist', \
                          'SkipSources', 'BootstrapPlayback', 'Source1Uri', 'Source1Weight', \
                          'Source2Uri', 'Source2Weight', 'Source3Uri', 'Source3Weight', \
                          'Source4Uri', 'Source4Weight', 'Source5Uri', 'Source5Weight', \
                          'Source6Uri', 'Source6Weight', 'Source7Uri', 'Source7Weight', \
                          'Source8Uri', 'Source8Weight', 'Source9Uri', 'Source9Weight', \
                          'Source10Uri', 'Source10Weight', 'Source11Uri', 'Source11Weight', \
                          'Source12Uri', 'Source12Weight', 'Source13Uri', 'Source13Weight', \
                          'Source14Uri', 'Source14Weight', 'Source15Uri', 'Source15Weight', \
                          'Source16Uri', 'Source16Weight', 'Source17Uri', 'Source17Weight', \
                          'Source18Uri', 'Source18Weight', 'Source19Uri', 'Source19Weight', \
                          'Source20Uri', 'Source20Weight' ]

        self.configSettings = {}
        self.configSettings['SourceUriList'] = []
        self.configSettings['SourceWeightList'] = []

        allWeightsSum = 0
        for configKey in configKeyList: 
            if configKey.find('Source') == 0:
                value = settings.getSetting(configKey) 
                if len(value) == 0:
                    pykodi.log(configKey + ": SKIPPING", xbmc.LOGDEBUG)
                else:
                    index = configKey.find('Weight')
                    if index == -1:
                        self.configSettings[configKey] = settings.getSetting(configKey) 
                        self.configSettings['SourceUriList'].append(value)
                        pykodi.log(configKey + ": " + value, xbmc.LOGDEBUG)
                    else:
                        modifiedKey = configKey[:index] + 'Uri'
                        if modifiedKey in self.configSettings.keys():
                            self.configSettings[configKey] = settings.getSetting(configKey) 
                            self.configSettings['SourceWeightList'].append(value)
                            allWeightsSum += int(value)
                            pykodi.log(configKey + ": " + value, xbmc.LOGDEBUG)
                        else:
                            pykodi.log(configKey + ": SKIPPING", xbmc.LOGDEBUG)
            else:
                self.configSettings[configKey] = settings.getSetting(configKey) 
                pykodi.log(configKey + ": " + self.configSettings[configKey], xbmc.LOGDEBUG)

        # append additional sources that the user may have passed in via lists in the
        # constructor
        for additionalSource in additionalSourceList:
            self.configSettings['SourceUriList'].append(additionalSource)
        for additionalSourceWeight in additionalSourceWeightList:
            self.configSettings['SourceWeightList'].append(additionalSourceWeight)
            allWeightsSum += int(additionalSourceWeight)

        # make sure that the sum of all weights are > 0
        if allWeightsSum == 0:
            xbmcgui.Dialog().notification(self.addon.getLocalizedString(32400), 
                                          self.addon.getLocalizedString(32405), 
                                          xbmcgui.NOTIFICATION_WARNING)
            sys.exit(1)
Ejemplo n.º 5
0
def remove_from_playlist(index, playlistid=xbmc.PLAYLIST_VIDEO):
    json_request = get_base_json_request('Playlist.Remove')
    json_request['params']['position'] = index
    json_request['params']['playlistid'] = playlistid

    json_result = pykodi.execute_jsonrpc(json_request)
    if not _check_json_result(json_result, 'OK', json_request):
        log(json_result, xbmc.LOGWARNING)
Ejemplo n.º 6
0
def set_movie_details(movie_id, **movie_details):
    json_request = get_base_json_request('VideoLibrary.SetMovieDetails')
    json_request['params'] = movie_details
    json_request['params']['movieid'] = movie_id

    json_result = pykodi.execute_jsonrpc(json_request)
    if not _check_json_result(json_result, 'OK', json_request):
        log(json_result)
Ejemplo n.º 7
0
def set_episode_details(episode_id, **episode_details):
    json_request = get_base_json_request('VideoLibrary.SetEpisodeDetails')
    json_request['params'] = episode_details
    json_request['params']['episodeid'] = episode_id

    json_result = pykodi.execute_jsonrpc(json_request)
    if not _check_json_result(json_result, 'OK', json_request):
        log(json_result)
Ejemplo n.º 8
0
def set_season_details(season_id, **season_details):
    json_request = get_base_json_request('VideoLibrary.SetSeasonDetails')
    json_request['params'] = season_details
    json_request['params']['seasonid'] = season_id

    json_result = pykodi.execute_jsonrpc(json_request)
    if not _check_json_result(json_result, 'OK', json_request):
        log(json_result)
Ejemplo n.º 9
0
def set_tvshow_details(tvshow_id, **tvshow_details):
    json_request = get_base_json_request('VideoLibrary.SetTVShowDetails')
    json_request['params'] = tvshow_details
    json_request['params']['tvshowid'] = tvshow_id

    json_result = pykodi.execute_jsonrpc(json_request)
    if not _check_json_result(json_result, 'OK', json_request):
        log(json_result)
Ejemplo n.º 10
0
def main():
    if len(sys.argv) < 2:
        runscript = 'RunScript(script.playrandomvideos, "<list path>", "label=<list label>")'
        log("See README.md for full usage: '%s'" % runscript, xbmc.LOGNOTICE)
        return
    if not sys.argv[1]:
        return

    pathinfo = get_arginfo()
    if not pathinfo:
        return
    playrandom.play(pathinfo)
Ejemplo n.º 11
0
    def getRandomEpisodeRecusive(self, fullpath):
        jsonRequest = pykodi.get_base_json_request('Files.GetDirectory')
        jsonRequest['params'] = {'directory': fullpath, 'media': 'video'}
        jsonRequest['params']['properties'] = ['playcount']

        jsonResponse = pykodi.execute_jsonrpc(jsonRequest)

        # pykodi.log(str(jsonResponse), xbmc.LOGDEBUG)
        if 'result' in jsonResponse and 'files' in jsonResponse['result']:

            # leverage pythons random library to shuffle a list of indicies
            # to get a random file / directory
            fileEntryList = list(jsonResponse['result']['files'])
            fileEntryIndexList = range(0, len(fileEntryList))
            random.shuffle(fileEntryIndexList)
            random.shuffle(fileEntryIndexList)
            random.shuffle(fileEntryIndexList)

	    for index in fileEntryIndexList: 
                fileEntry = fileEntryList[index]

                # recurse down directories
                if self.isDirectory(fileEntry):
                    if fileEntry['label'] in ('extrafanart', 'extrathumbs'):
                        continue
                    subdirectoryResult = self.getRandomEpisodeRecusive(fileEntry['file'])
                    if len(subdirectoryResult) == 0:
                        # didn't find anything in the subdirectory
                        continue
                    else:
                        # found something in the subdirectory
                        return subdirectoryResult 

                # this is a file see if we can play it
                if self.shouldPlayFile(fileEntry):
                    # yes it can be played
                    return [ fileEntry ]
                else:
                    # no it can't be played
                    continue
            # we have walked off of the end of the 'files' list so return an empty list
        elif 'error' in jsonResponse:
            xbmcgui.Dialog().notification(self.addon.getLocalizedString(32400), 
                                          self.addon.getLocalizedString(32402) + fullpath, 
                                          xbmcgui.NOTIFICATION_WARNING)
            pykodi.log(jsonResponse, xbmc.LOGDEBUG)
            xbmc.executebuiltin('Dialog.Close(busydialog)')
            sys.exit(1)

        return []
Ejemplo n.º 12
0
def get_generator(content, info, singleresult):
    if content == 'tvshows':
        return RandomFilterableJSONGenerator(lambda filters, limit:
            quickjson.get_random_episodes(info.get('tvshowid'), info.get('season'), filters, limit),
            info.get('filters'), singleresult)
    elif content == 'movies':
        return RandomFilterableJSONGenerator(quickjson.get_random_movies, info.get('filters'), singleresult)
    elif content == 'musicvideos':
        return RandomFilterableJSONGenerator(quickjson.get_random_musicvideos, info.get('filters'), singleresult)
    elif content == 'other':
        return RandomJSONDirectoryGenerator(info['path'], info['watchmode'], singleresult)
    else:
        log("I don't know what to do with this:", xbmc.LOGWARNING)
        log({'content': content, 'info': info}, xbmc.LOGWARNING)
Ejemplo n.º 13
0
    def extend_playlist(self, count=1):
        if self.source_exhausted:
            return False
        addedcount = 0
        for _ in range(0, count):
            try:
                self.add_to_playlist(next(self._source))
                addedcount += 1
            except StopIteration:
                self.source_exhausted = True
                log("Source has been exhausted", xbmc.LOGINFO)
                break

        return True if addedcount else False
Ejemplo n.º 14
0
    def run(self):
        if self.showbusydialog:
            busy = get_busydialog()
            busy.create()
        extended = self.extend_playlist()
        if self.showbusydialog: busy.close()
        if extended:
            self.play(self.playlist)
            if LOAD_NEW - 1 > 0:
                self.extend_playlist(LOAD_NEW - 1)
        while xbmc.getCondVisibility('Player.HasMedia'):
            if self.source_exhausted:
                break
            xbmc.sleep(2000)

        log("I'm done", xbmc.LOGINFO)
Ejemplo n.º 15
0
 def _get_next_files(self):
     path_to_use = self._pop_randomdir()
     result_files = ()
     result_dirs = set()
     if not path_to_use:
         return result_dirs, result_files
     if not self.tick:
         timeout = time() + self.FIRST_TIMEOUT
     while not result_files and path_to_use:
         log("Listing '{0}'".format(path_to_use), xbmc.LOGINFO)
         newdirs, result_files = self._get_random_from_path(path_to_use)
         result_dirs |= newdirs
         if not self.tick and time() > timeout:
             log("Timeout reached", xbmc.LOGINFO)
             break
         if not result_files:
             path_to_use = self._pop_randomdir(result_dirs)
     return result_dirs, result_files
Ejemplo n.º 16
0
def jsonrpc_introspect():
    json_request = get_base_json_request('JSONRPC.Introspect')
    json_result = pykodi.execute_jsonrpc(json_request)
    log(json_result)