Compare commits

...

4 commits

Author SHA1 Message Date
minecraftchest1@outlook.com
3be229141d get-volume 2025-04-03 13:50:13 -05:00
minecraftchest1@outlook.com
d00cc46aaf Add optoon to get audio sinks and the default audio sink. 2025-04-03 13:17:56 -05:00
minecraftchest1@outlook.com
6ddd91e339 add pycache to gitignore 2025-04-03 13:17:22 -05:00
minecraftchest1@outlook.com
f1df74bcfc Format output for pipewire-list. 2025-04-03 10:33:06 -05:00
5 changed files with 60 additions and 5 deletions

1
.gitignore vendored
View file

@ -1 +1,2 @@
.venv/
**/__pycache__/

23
main.py
View file

@ -24,11 +24,22 @@ def bluetooth_connect(args):
print("%s",process.stderr)
def pipewire_list(args):
print(args)
print("ID | Description")
print("----------------")
sinks = Pipewire.get_sinks()
for sink in sinks:
print(sink['info']['props']['node.description'])
print(str(sink['id']) + " | " + sink['info']['props']['node.description'])
def pipewire_get_default_sink(args):
print("ID | Description")
print("----------------")
sink = Pipewire.get_default_audio_sink()
print(str(sink['id']) + " | " + sink['info']['props']['node.description'])
def pipewire_get_volume(args):
print(Pipewire.get_volume())
def main():
argparser = argparse.ArgumentParser(description='CarPI CLI.')
@ -41,11 +52,17 @@ def main():
action_bt_connect = actions.add_parser('bluetooth-connect', help='connect to a bluetooth device')
action_bt_connect.set_defaults(func=bluetooth_connect)
action_bt_connect.add_argument('address', help='The bluetooth address of the device to connect to.')
action_bt_connect.add_argument('address', help='the bluetooth address of the device to connect to.')
action_pw_list = actions.add_parser('pipewire-list', help='list pipewire objects')
action_pw_list.set_defaults(func=pipewire_list)
action_pw_get_default_sink = actions.add_parser('pipewire-get-default-sink', help='show the default audio sink')
action_pw_get_default_sink.set_defaults(func=pipewire_get_default_sink)
action_pw_get_volume = actions.add_parser('pipewire-get-volume', help='get volume of the specified device')
action_pw_get_volume.set_defaults(func=pipewire_get_volume)
args = argparser.parse_args()
args.func(args)

0
src/bluetooth.py Normal file
View file

View file

@ -38,5 +38,11 @@ class Pipewire:
for node in nodes:
if (node['type'] == 'PipeWire:Interface:Node' and
node['info']["props"]['node.name'] == default_skink):
print(node['info']['props']['node.description'])
return(node)
return(node)
def get_volume(id=None):
if id == None:
id = "@DEFAULT_AUDIO_SINK@"
return subprocess.run(["wpctl", "get-volume", id],
stdout=subprocess.PIPE, text=True).stdout.split()[1]

31
tmp.py Normal file
View file

@ -0,0 +1,31 @@
import json
import subprocess
import pprint
pwdump = subprocess.run(['pw-dump'], stdout=subprocess.PIPE, text=True)
nodes = json.loads(pwdump.stdout)
# LIST SINKS
#for node in nodes:
# try:
# if node['type'] == 'PipeWire:Interface:Node':
# if node['info']["props"]['media.class'] == 'Audio/Sink':
# print(node['info']['props']['node.description'])
# except KeyError:
# pass
# RETURN DESCRIPTION OF DEFAULT AUDIO DEVICE
for node in nodes:
if (node['type'] == 'PipeWire:Interface:Metadata' and
node['props']['metadata.name'] == 'default'):
for metadata in node['metadata']:
if metadata['key'] == 'default.audio.sink':
default_skink = metadata['value']['name']
break
for node in nodes:
if (node['type'] == 'PipeWire:Interface:Node' and
node['info']["props"]['node.name'] == default_skink):
print(node['info']['props']['n