aboutsummaryrefslogtreecommitdiff
path: root/inter.py
blob: 4a4cd5b92bd1be979b25af60b8098b5100d1c0ff (plain)
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
from collections import namedtuple
import pacmd

Sink = namedtuple("Sink",
        ["name",  # string
         "description",  # string
         "index",  # int
         "state",  # string
         "muted",  # bool
         "volume"])  # string
SinkInput = namedtuple("SinkInput",
        ["name",  # string
         "driver",  # string
         "sink"])  # int

def list_sinks():
    res = pacmd.list_sinks()
    assert len(res.sections) == 1
    assert res.sections[0].name == "sink"

    ret = []
    for item in res.sections[0].items:
        muted = item.children["muted"].value
        if muted == "yes": muted = True
        elif muted == "no": muted = False
        else: assert False

        sink = Sink(
                item.children["name"].value,
                item.children["properties"].children["device.description"].value,
                item.index,
                item.children["state"].value,
                muted,
                item.children["volume"].value)
        ret.append(sink)

    return ret

def list_sink_inputs():
    res = pacmd.list_sink_inputs()
    assert len(res.sections) == 1
    assert res.sections[0].name == "input"

    ret = []
    for item in res.sections[0].items:
        name = item.children["properties"].children["media.name"].value
        if "application.process.binary" in item.children["properties"].children:
            name += " (" + item.children["properties"].children["application.process.binary"].value + ")"

        si = SinkInput(
                name,
                item.children["driver"].value,
                int(item.children["sink"].value.split()[0]))
        ret.append(si)

    return ret