Translating executehttpapi to JSON - change audio output
#1
Question 
Hi all,

Thanks to other posts on the XBMC forum and a little tinkering, I managed to adapt a Pyton script that I found to change my Audio Output device and some other settings, triggerd by a single keypress. Instead of going through the Settings menu's in the GUI and changing it manually, this script will do it all with a single press of a button.

The problem is, after upgrading to Frodo RC2 it no longer works, as the xbmc.executehttpapi is depreciated and removed. I have been googling for the past hour, but I can't find any useful hints as how to translate this code to the JSON RPC. All I need is some examples to get me going.

Would anyone be willing to help me out? Thanks in advance! And of course a Happy New Year!

Below the code in the pyton script
Code:
import os, xbmc

audio_output = "None"
current_channels = xbmc.executehttpapi( "GetGUISetting(0;audiooutput.channellayout)" ).replace("<li>","")
if (current_channels == "1"): #then Bedroom is selected, so switch to Living Room
  audio_device = "ALSA:hdmi:CARD=PCH,DEV=0"
  audio_output = "Living Room"  # Optional, if notification used
  audio_channel = 8
  audio_ac3 = "true"
  audio_dts = "true"
  audio_pass = "ALSA:hdmi:CARD=PCH,DEV=0"
else:  # Switch to Bedroom
  audio_device = "ALSA:hdmi:CARD=PCH,DEV=1"
  audio_output = "Bedroom"  #Optional, if notification used
  audio_channel = 1
  audio_ac3 = "false"
  audio_dts = "false"
  audio_pass = "ALSA:hdmi:CARD=PCH,DEV=1"
# Change audio settings and display notification of new mode:
xbmc.executehttpapi( "SetGUISetting(0;audiooutput.mode;%s)" % audio_mode )
xbmc.executehttpapi( "SetGUISetting(3;audiooutput.audiodevice;%s)" % audio_device )
xbmc.executehttpapi( "SetGUISetting(0;audiooutput.channels;%s)" % audio_channel )
xbmc.executehttpapi( "SetGUISetting(1;audiooutput.ac3passthrough;%s)" % audio_ac3 )
xbmc.executehttpapi( "SetGUISetting(1;audiooutput.dtspassthrough;%s)" % audio_dts )
xbmc.executehttpapi( "SetGUISetting(3;audiooutput.passthroughdevice;%s)" % audio_pass )
xbmc.executebuiltin( "Notification(Audio output changed to:, %s, 2000)" %audio_output )  # Optional notification

The error I'm getting with Frodo is:
Code:
13:14:40 T:2662329152   ERROR: EXCEPTION: Unimplemented method: executehttpapi::executehttpapi(...)
13:14:40 T:2662329152   ERROR: EXCEPTION Thrown (PythonToCppException) : -->Python callback/script returned the following error<--
                                             - NOTE: IGNORING THIS CAN LEAD TO MEMORY LEAKS!
                                            Error Type: <type 'exceptions.RuntimeError'>
                                            Error Contents: Unimplemented method: executehttpapi::executehttpapi(...)
                                            Traceback (most recent call last):
                                              File "/home/htpc/SwAudioOut.py", line 4, in <module>
                                                current_channels = xbmc.executehttpapi( "GetGUISetting(0;audiooutput.channellayout)" ).replace("<li>","")
                                            RuntimeError: Unimplemented method: executehttpapi::executehttpapi(...)
                                            -->End of Python script error report<--
Reply
#2
JSON RPC does not have access to GUI Settings. I do believe that the developers are working on the best access and which ones are accessible. But this will not be implemented for Frodo.
Reply
#3
Thanks giftie!

Does anyone have any ideas on how to accomplish this in another way, without JSON RPC?

Maybe I can customize a skin to include one easy accessible button that changes multiple GUI settings at once. Would something like that still be possible in Frodo? I prefer to find a way that does not mean modifying the source and recompiling XBMC, but if that is what it takes.. Smile
Reply
#4
(2013-01-07, 19:58)Xrypton Wrote: Thanks giftie!

Does anyone have any ideas on how to accomplish this in another way, without JSON RPC?

Maybe I can customize a skin to include one easy accessible button that changes multiple GUI settings at once. Would something like that still be possible in Frodo? I prefer to find a way that does not mean modifying the source and recompiling XBMC, but if that is what it takes.. Smile
You can read the guisettings.xml directly with python using minidom or elementtree

Code:
from xml.dom.minidom import parseString

def getAddonSetting(doc,id):
    for element in doc.getElementsByTagName('setting'):
        if element.getAttribute('id')==id:
            return element.getAttribute('value')

pguisettings = ~/.xbmc/userdata/guisettings.xml'

if os.path.exists(pguisettings):
    fguisettings = open(pguisettings, 'r')
    data = fguisettings.read()
    fguisettings.close
    guisettings = parseString(data)
    settingyourtryingtoread                          = getAddonSetting(guisettings, 'SETTINGYOURTRYINGTOREAD')
Reply
#5
Yes, but XBMC does not read the GUI Settings until either a login change or a restart

(2013-01-13, 12:13)otkaz Wrote:
(2013-01-07, 19:58)Xrypton Wrote: Thanks giftie!

Does anyone have any ideas on how to accomplish this in another way, without JSON RPC?

Maybe I can customize a skin to include one easy accessible button that changes multiple GUI settings at once. Would something like that still be possible in Frodo? I prefer to find a way that does not mean modifying the source and recompiling XBMC, but if that is what it takes.. Smile
You can read the guisettings.xml directly with python using minidom or elementtree

Code:
from xml.dom.minidom import parseString

def getAddonSetting(doc,id):
    for element in doc.getElementsByTagName('setting'):
        if element.getAttribute('id')==id:
            return element.getAttribute('value')

pguisettings = ~/.xbmc/userdata/guisettings.xml'

if os.path.exists(pguisettings):
    fguisettings = open(pguisettings, 'r')
    data = fguisettings.read()
    fguisettings.close
    guisettings = parseString(data)
    settingyourtryingtoread                          = getAddonSetting(guisettings, 'SETTINGYOURTRYINGTOREAD')

Reply
#6
Hi All , first post here, looking forward to being an active member

Thanks for posting your script any chance you can advise me on how to use it myself, where do I put this script to enable one button audio withing , I'm happy to stay with Eden and use this for the time being

thanks in advance
Reply
#7
(2013-01-30, 03:34)mouldy crumpet Wrote: Hi All , first post here, looking forward to being an active member

Thanks for posting your script any chance you can advise me on how to use it myself, where do I put this script to enable one button audio withing , I'm happy to stay with Eden and use this for the time being

thanks in advance

See here: http://forum.xbmc.org/showthread.php?tid...pid1168021
Reply

Logout Mark Read Team Forum Stats Members Help
Translating executehttpapi to JSON - change audio output0