forked from B-S-L/script.switch.audio.device.shortcut
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddon.py
More file actions
64 lines (47 loc) · 2.47 KB
/
Copy pathaddon.py
File metadata and controls
64 lines (47 loc) · 2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import xbmc
import xbmcaddon
import json
import sys
__addon__ = xbmcaddon.Addon()
__addonname__ = __addon__.getAddonInfo('name')
__icon__ = __addon__.getAddonInfo('icon')
REMOTE_DBG = False
if REMOTE_DBG:
try:
import pydevd
pydevd.settrace(stdoutToServer=True, stderrToServer=True)
except:
xbmcgui.Dialog().ok(addonname, "debug mode not workng")
sys.exit(1)
req = xbmc.executeJSONRPC('{"jsonrpc":"2.0","method":"Settings.GetSettings","id":1}')
jsonRPCRes = json.loads(req);
settingsList = jsonRPCRes["result"]["settings"]
audioSetting = [item for item in settingsList if item["id"] == "audiooutput.audiodevice"][0]
audioDeviceOptions = audioSetting["options"];
activeAudioDeviceValue = audioSetting["value"];
activeAudioDeviceId = [index for (index, option) in enumerate(audioDeviceOptions) if option["value"] == activeAudioDeviceValue][0];
#default cycle through sound devices
#nextIndex = ( activeAudioDeviceId + 1 ) % len(audioDeviceOptions)
#changed to switch between two devices and enable/disable passthrough as needed.
if activeAudioDeviceId < 3:
#disable passthrough for Analod/External USB @ Index 3
changeReq1 = xbmc.executeJSONRPC('{"jsonrpc":"2.0","method":"Settings.SetSettingValue","params":{"setting":"audiooutput.passthrough","value":%s},"id":1}' % "false")
changeReq2 = xbmc.executeJSONRPC('{"jsonrpc":"2.0","method":"Settings.SetSettingValue","params":{"setting":"audiooutput.stereoupmix","value":%s},"id":1}' % "true")
nextIndex = 3
else:
#enable passthrough for HDMI @ Index 2 (change as required, Default=0,PCM=1,HDMI=2)
changeReq1 = xbmc.executeJSONRPC('{"jsonrpc":"2.0","method":"Settings.SetSettingValue","params":{"setting":"audiooutput.passthrough","value":%s},"id":1}' % "true")
changeReq2 = xbmc.executeJSONRPC('{"jsonrpc":"2.0","method":"Settings.SetSettingValue","params":{"setting":"audiooutput.stereoupmix","value":%s},"id":1}' % "false")
nextIndex = 2
nextValue = audioDeviceOptions[nextIndex]["value"]
nextName = audioDeviceOptions[nextIndex]["label"]
changeReq = xbmc.executeJSONRPC('{"jsonrpc":"2.0","method":"Settings.SetSettingValue","params":{"setting":"audiooutput.audiodevice","value":"%s"},"id":1}' % nextValue)
try:
changeResJson = json.loads(changeReq);
changeResJson1 = json.loads(changeReq1);
if changeResJson["result"] != True:
raise Exception
except:
sys.stderr.write("Error switching audio output device")
raise Exception
xbmc.executebuiltin('Notification("%s","Output-Device: %s",2000,"%s")' % (__addonname__, nextName, __icon__ ))