Example #1
0
 def start(self,
           xml_file,
           labels=None,
           textboxes=None,
           buttons=None,
           thelist=0,
           save_profile=False):
     count = 0
     delay = int(ADDON.getSetting('player_autoclose_delay'))
     autoclose = ADDON.getSetting('player_autoclose').lower()
     display = SHOW(xml_file,
                    ADDON_PATH,
                    labels=labels,
                    textboxes=textboxes,
                    buttons=buttons,
                    thelist=thelist)
     display.show()
     while (KODIPLAYER.isPlaying()
            or save_profile) and not KODIMONITOR.abortRequested():
         if save_profile:
             notify.logDebug(
                 'the current returned value from display is: %s' %
                 str(display.ret))
             if display.ret is not None:
                 break
         elif autoclose == 'true':
             if count >= delay:
                 break
             count = count + 1
         KODIMONITOR.waitForAbort(1)
     ret = display.ret
     del display
     return ret
Example #2
0
 def changeProfile(self, profile, forceload=''):
     if profile in profiles:
         # get last loaded profile
         lastProfile = self.getLastProfile()
         notify.logDebug('[MONITOR] Last loaded profile: %s To switch profile: %s' % (lastProfile, profile))
         if (lastProfile != profile and susppend_auto_change is not True) or forceload.lower() == 'true':
             xbmc.executebuiltin('RunScript(%s, %s)' % (ADDON_ID, profile))
         else:
             notify.logDebug('[MONITOR] Switching omitted (same profile) or switching is susspend')
Example #3
0
 def profile(self, profile):
     # read addon settings
     sVolume = ADDON.getSetting('volume')
     sPlayer = ADDON.getSetting('player')
     sVideo = ADDON.getSetting('video')
     sCec = ADDON.getSetting('profile' + profile + '_cec')
     # read settings from profile
     f = xbmcvfs.File(
         os.path.join(ADDON_PATH_DATA, 'profile' + profile + '.json'), 'r')
     result = f.read()
     try:
         jsonResult = json.loads(result)
         f.close()
     except ValueError:
         notify.popup('%s %s (%s)' %
                      (ADDON_LANG(32104), profile, sName[int(profile)]))
         notify.logError(
             '[LOAD JSON FROM FILE]: Error reading from profile - %s' %
             str(profile))
         return False
     # settings needed quote for value
     quote_needed = [
         'audiooutput.audiodevice', 'audiooutput.passthroughdevice',
         'locale.audiolanguage', 'lookandfeel.soundskin'
     ]
     # set settings readed from profile file
     notify.logInfo('[RESTORING SETTING]: %s' % sName[int(profile)])
     for setName, setValue in jsonResult.items():
         # skip setting that type is disable to changing
         if 'false' in sPlayer and setName.startswith('videoplayer'):
             continue
         if 'false' in sVideo and setName.startswith('videoscreen'):
             continue
         notify.logDebug('[RESTORING SETTING]: %s: %s' %
                         (setName, setValue))
         # add quotes
         if setName in quote_needed:
             setValue = '"%s"' % setValue
         # set setting
         if 'true' in sVolume and setName == 'volume':
             xbmc.executeJSONRPC(
                 '{"jsonrpc": "2.0", "method": "Application.SetVolume", "params": {"volume": %s}, "id": 1}'
                 % jsonResult['volume'])
         else:
             xbmc.executeJSONRPC(
                 '{"jsonrpc": "2.0", "method": "Settings.SetSettingValue", "params": {"setting": "%s", "value": %s}, "id": 1}'
                 % (setName, setValue))
     notify.popup(sName[int(profile)])
     # write curent profile
     f = xbmcvfs.File(os.path.join(ADDON_PATH_DATA, 'profile'), 'w')
     f.write(profile)
     f.close()
     # CEC
     if sCec != '' and int(sCec) > 0:
         notify.logInfo('[SENDING CEC COMMAND]: %s' %
                        cecCommands[int(sCec)])
         xbmc.executebuiltin(cecCommands[int(sCec)])
Example #4
0
 def __init__(self):
     notify.logInfo('running profiles script')
     notify.logDebug('[SYS.ARGV]: %s' % str(sys.argv))
     notify.logDebug('[XBMC VERSION]: %s' % str(xbmc_version))
     self.xmlFile = 'script-audio-profiles-menu.xml'
     # detect mode, check args
     if (len(sys.argv) < 2 or len(sys.argv[0]) == 0):
         mode = False
     else:
         mode = str(sys.argv[1])
     notify.logDebug('[MODE]: %s' % str(mode))
     self.start(mode)
Example #5
0
 def onNotification(self, sender, method, data):
     global susppend_auto_change
     global set_for_susspend
     data = json.loads(data)
     if 'System.OnWake' in method:
         notify.logDebug('[MONITOR] METHOD: %s DATA: %s' % (str(method), str(data)))
         # default for kodi wakeup
         self.changeProfile(ADDON.getSetting('auto_default'))
     if 'Player.OnStop' in method:
         notify.logDebug('[MONITOR] METHOD: %s DATA: %s' % (str(method), str(data)))
         # gui
         susppend_auto_change = False
         self.changeProfile(ADDON.getSetting('auto_gui'))
     if 'Player.OnPlay' in method:
         notify.logDebug('[MONITOR] METHOD: %s DATA: %s' % (str(method), str(data)))
         # auto switch
         if 'item' in data and 'type' in data['item']:
             self.autoSwitch(data)
Example #6
0
 def autoSwitch(self, data):
     global susppend_auto_change
     global set_for_susspend
     thetype = data['item']['type']
     theset = map_type.get(thetype)
     # auto show dialog
     notify.logDebug('the data are:')
     notify.logDebug(data)
     if 'true' in ADDON.getSetting('player_show'):
         xbmc.executebuiltin('RunScript(%s, popup)' % ADDON_ID)
     # if video is not from library assign to auto_videos
     if 'movie' in thetype and 'id' not in data['item']:
         theset = 'auto_videos'
     # distinguish pvr TV and pvr RADIO
     if 'channel' in thetype and 'channeltype' in data['item']:
         if 'tv' in data['item']['channeltype']:
             theset = 'auto_pvr_tv'
         elif 'radio' in data['item']['channeltype']:
             theset = 'auto_pvr_radio'
         else:
             theset = None
     # detect cdda that kodi return as unknown
     if 'unknown' in thetype and 'player' in data and 'playerid' in data['player']:
         jsonS = xbmc.executeJSONRPC(
         '{"jsonrpc": "2.0", "id": "1", "method": "Player.GetItem", "params": {"playerid": %s, "properties": ["file"]}}' % str(data['player']['playerid'])
                                    )
         jsonR = json.loads(jsonS)
         try:
             thefile = jsonR['result']['item']['file']
         except (IndexError, KeyError, ValueError):
             thefile = ''
         if thefile.startswith('cdda://'):
             theset = 'auto_music'
     notify.logDebug('[MONITOR] Setting parsed: %s' % str(theset))
     # cancel susspend auto change when media thetype change
     if theset != set_for_susspend:
         susppend_auto_change = False
         set_for_susspend = theset
     if theset is not None:
         self.changeProfile(ADDON.getSetting(theset))
         susppend_auto_change = True
Example #7
0
    def save(self):
        # get audio config and save to file
        enabledProfiles = self.getEnabledProfiles()
        ret = dialog.DIALOG().start(self.xmlFile,
                                    labels={10071: ADDON_LANG(32100)},
                                    buttons=enabledProfiles[1],
                                    thelist=10070,
                                    save_profile=True)
        notify.logDebug('the returned value is %s' % str(ret))
        if ret is None:
            return False
        else:
            button = enabledProfiles[0][ret]
        settingsToSave = {}
        json_s = [
            # get all settings from System / Audio section
            '{"jsonrpc":"2.0","method":"Settings.GetSettings", "params":{"level": "expert", "filter":{"section":"system","category":"audio"}},"id":1}',
            # get volume level
            '{"jsonrpc": "2.0", "method": "Application.GetProperties", "params": {"properties": ["volume"]}, "id": 1}',
            # get all settings from Player / Videos section
            '{"jsonrpc":"2.0","method":"Settings.GetSettings", "params":{"level": "expert", "filter":{"section":"player","category":"videoplayer"}}, "id":1}',
            # get all settings from System / Video section
            '{"jsonrpc":"2.0","method":"Settings.GetSettings", "params":{"level": "expert", "filter":{"section":"system","category":"display"}}, "id":1}'
        ]
        # send json requests
        for j in json_s:
            jsonGet = xbmc.executeJSONRPC(j)
            jsonGet = json.loads(jsonGet)
            notify.logDebug('[JSON]: %s' % str(jsonGet))
            if 'result' in jsonGet:
                if 'settings' in jsonGet['result']:
                    for theset in jsonGet['result']['settings']:
                        if 'value' in theset.keys():

                            if theset['value'] == True or theset[
                                    'value'] == False:  # lowercase bolean values
                                settingsToSave[theset['id']] = str(
                                    theset['value']).lower()
                            else:
                                if isinstance(theset['value'], int):
                                    settingsToSave[theset['id']] = str(
                                        theset['value'])
                                else:
                                    settingsToSave[theset['id']] = str(
                                        theset['value']).encode('utf-8')

                if 'volume' in jsonGet['result']:
                    settingsToSave['volume'] = str(jsonGet['result']['volume'])
        # prepare JSON string to save to file
        if xbmc_version > 18:
            settingsToSave = convert(settingsToSave)
        jsonToWrite = json.dumps(settingsToSave)
        # create dir in addon data if not exist
        if not xbmcvfs.exists(ADDON_PATH_DATA):
            xbmcvfs.mkdir(ADDON_PATH_DATA)
        # save profile file
        notify.logInfo('[SAVING SETTING]: %s' % sName[button])
        f = xbmcvfs.File(
            os.path.join(ADDON_PATH_DATA, 'profile%s.json' % str(button)), 'w')
        f.write(jsonToWrite)
        f.close()
        notify.popup('%s %s (%s)' %
                     (ADDON_LANG(32102), str(button), sName[button]),
                     force=True)