44 lines
1.5 KiB
Python
44 lines
1.5 KiB
Python
import subprocess
|
|
from os import environ
|
|
|
|
class Pulse:
|
|
|
|
# this method uses the intern names of the sinks
|
|
# @staticmethod
|
|
# def get_audio_inputs():
|
|
# proc = subprocess.run(['pactl', 'list', 'short', 'sources'], capture_output=True)
|
|
# parts = [line.split('\t') for line in proc.stdout.decode('utf-8').split('\n')]
|
|
# deviceinfos = [{'id': device[0], 'name': device[1]} for device in parts if len(device) > 1]
|
|
# return deviceinfos
|
|
|
|
@staticmethod
|
|
def get_audio_inputs():
|
|
proc = subprocess.run(['pacmd', 'list-sources'], capture_output=True, env={**environ, 'LANG': 'C'})
|
|
lines = proc.stdout.decode('utf-8').split('\n')
|
|
currentSourceID = -1
|
|
currentName = ''
|
|
ismointor = False
|
|
isdefault = False
|
|
description = ''
|
|
devices = []
|
|
for line in lines:
|
|
if line[4:].startswith('index: '):
|
|
#submit old device
|
|
if currentSourceID != -1:
|
|
devices.append({'id': currentSourceID, 'name': currentName, 'monitor': ismointor, 'description': description, 'isdefault': isdefault})
|
|
|
|
ismointor = False
|
|
isdefault = line[2] == '*'
|
|
description = ''
|
|
currentSourceID = int(line[11:])
|
|
elif line.startswith('\tname: '):
|
|
currentName = line[8:-1]
|
|
elif line == '\t\tdevice.class = "monitor"':
|
|
ismointor = True
|
|
elif line.startswith('\t\tdevice.description = "'):
|
|
description = line[24:-1]
|
|
|
|
devices.append({'id': currentSourceID, 'name': currentName, 'monitor': ismointor, 'description': description, 'isdefault': isdefault})
|
|
|
|
return devices
|