diff options
author | Anthony Wang | 2024-02-25 19:49:32 -0500 |
---|---|---|
committer | Anthony Wang | 2024-02-25 19:49:32 -0500 |
commit | 32560ebd9d85ac3eada1bdea9590ff195cba24bf (patch) | |
tree | 741506a15e78d842910bcf1bef143bbdea0a04c2 /static | |
parent | 060256369b2983990daf9db6f37d54ca7d356700 (diff) |
PulseAudioDB
Diffstat (limited to 'static')
-rw-r--r-- | static/src/padb.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/static/src/padb.py b/static/src/padb.py new file mode 100644 index 0000000..2d55212 --- /dev/null +++ b/static/src/padb.py @@ -0,0 +1,28 @@ +import subprocess + + +class PulseAudioDB: + def __getitem__(self, key): + try: + return int(subprocess.check_output(['pactl', 'get-sink-volume', key]).split()[2]) + except: + raise KeyError + def __setitem__(self, key, value): + run = lambda x: subprocess.run(x, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) + if run(['pactl', 'set-sink-volume', key, str(value)]).returncode: + # Key doesn't exist yet + run(['pactl', 'load-module', 'module-null-sink', 'channels=1', 'sink_name=' + key]) + run(['pactl', 'set-sink-volume', key, str(value)]) + + +padb = PulseAudioDB() + +N = 200 +for i in range(N): + padb['a' + str(i)] = i + +ans = 0 +for i in range(N): + ans += padb['a' + str(i)] + +print(ans) |