-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddon.py
More file actions
119 lines (108 loc) · 4.33 KB
/
addon.py
File metadata and controls
119 lines (108 loc) · 4.33 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# -*- coding: utf-8 -*-
#
# Copyright (C) 2017 Arne Svenson
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from __future__ import unicode_literals
import sys
import traceback
import xbmc, xbmcgui
from resources.lib.sysvolume.mixer import Mixer
from resources.lib.sysvolume import debug, config
from resources.lib.sysvolume.config import settings, _T
#------------------------------------------------------------------------------
# Public Functions
#------------------------------------------------------------------------------
def get_argv(idx, default=''):
retval = default
try:
retval = sys.argv[idx]
except:
pass
return retval
def get_argv_int(idx, default=0):
retval = default
try:
retval = int(sys.argv[idx])
except:
pass
return retval
def show_progress(mixer):
if settings.show_progress:
dia = xbmcgui.DialogProgressBG()
dia.create(heading=settings.addon_name)
dia.update(percent=mixer.volume, message='[%s] %s: %s%% %s' % (settings.device_name,
settings.mixer_name,
mixer.volume, _T(30104) if mixer.muted else ''))
xbmc.sleep(settings.progress_time)
dia.close()
def select_device():
debug.logInfo('Selecting mixer device')
devices = Mixer.getDevices()
devkeys = list(devices.keys())
devlist = []
for key in devkeys:
deviceName = '[%s] %s' % (key, devices[key]['name'])
debug.logInfo('Found device: %s' % deviceName)
devlist.append(deviceName)
for mixer in devices[key]['mixer']:
debug.logInfo('Found mixer: %s' % mixer)
if len(devlist) == 0:
xbmcgui.Dialog().ok(_T(30101), _T(30102))
else:
device = xbmcgui.Dialog().select(_T(30101), devlist)
if device >= 0:
mixers = devices[devkeys[device]]['mixer']
if len(mixers) > 0:
mixer = xbmcgui.Dialog().select(_T(30103), mixers)
mixer_name = mixers[mixer]
else:
mixer_name = ''
config.setSetting('device_name', devkeys[device].encode('utf-8'))
config.setSetting('mixer_name', mixer_name.encode('utf-8'))
debug.logInfo("Selected device '%s' with mixer '%s'" % (devkeys[device], mixer_name))
#------------------------------------------------------------------------------
# MAIN
#------------------------------------------------------------------------------
if __name__ == '__main__':
try:
mixer = Mixer.create(settings.device_name, settings.mixer_name,
settings.step_up, settings.step_down,
settings.max_volume)
cmd = get_argv(1, '').lower()
if cmd == 'up':
mixer.volumeUp(step=get_argv_int(2, default=settings.step_up))
show_progress(mixer)
elif cmd == 'down':
mixer.volumeDown(step=get_argv_int(2, default=settings.step_down))
show_progress(mixer)
elif cmd == 'change':
mixer.changeVolume(step=get_argv_int(2, default=0))
show_progress(mixer)
elif cmd == 'set':
mixer.setVolume(volume=get_argv_int(2, default=mixer.volume))
show_progress(mixer)
elif cmd == 'mute':
newMute = get_argv(2, default= 'true' if mixer.muted else 'false').lower()
mixer.setMute(mute= True if newMute == 'true' else False)
show_progress(mixer)
elif cmd == 'mutetoggle':
mixer.muteToggle()
show_progress(mixer)
else:
select_device()
pass
except Exception as e:
debug.logException(e)
traceback.print_exc()