audio-connected 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Morten Lied Johansen
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,43 @@
1
+ Metadata-Version: 2.1
2
+ Name: audio-connected
3
+ Version: 0.1.0
4
+ Summary: Watches PulseAudio events for new sinks connected, and if the name matches the configured name, make that sink the default sink.
5
+ Author: Morten Lied Johansen
6
+ Author-email: mortenjo@ifi.uio.no
7
+ Requires-Python: >=3.11,<4.0
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: Programming Language :: Python :: 3.11
10
+ Requires-Dist: pulsectl (>=23.5.2,<24.0.0)
11
+ Description-Content-Type: text/x-rst
12
+
13
+ ===============
14
+ Audio Connected
15
+ ===============
16
+
17
+ Watches PulseAudio events for new sinks connected, and if the name matches the configured name, make that sink the default sink.
18
+
19
+ Installation
20
+ ============
21
+
22
+ Probably works best when installed with pipx_: `pipx install audio-connected`
23
+
24
+ To make it run on startup, you can add a XDG Autostart entry in `$XDG_CONFIG_HOME/autostart` (`~/.config/autostart` by default).
25
+
26
+ Example:
27
+
28
+ .. code:: ini
29
+
30
+ [Desktop Entry]
31
+ Version=1.5
32
+ Type=Application
33
+ Name=Audio Connected
34
+ Comment=Set EPOS ADAPT 660 headset as default sink when connected
35
+ Exec=audio-connected "EPOS ADAPT 660"
36
+ OnlyShowIn=XFCE;
37
+ StartupNotify=false
38
+ Terminal=false
39
+ Hidden=false
40
+
41
+
42
+ .. _pipx: https://pypa.github.io/pipx/
43
+
@@ -0,0 +1,30 @@
1
+ ===============
2
+ Audio Connected
3
+ ===============
4
+
5
+ Watches PulseAudio events for new sinks connected, and if the name matches the configured name, make that sink the default sink.
6
+
7
+ Installation
8
+ ============
9
+
10
+ Probably works best when installed with pipx_: `pipx install audio-connected`
11
+
12
+ To make it run on startup, you can add a XDG Autostart entry in `$XDG_CONFIG_HOME/autostart` (`~/.config/autostart` by default).
13
+
14
+ Example:
15
+
16
+ .. code:: ini
17
+
18
+ [Desktop Entry]
19
+ Version=1.5
20
+ Type=Application
21
+ Name=Audio Connected
22
+ Comment=Set EPOS ADAPT 660 headset as default sink when connected
23
+ Exec=audio-connected "EPOS ADAPT 660"
24
+ OnlyShowIn=XFCE;
25
+ StartupNotify=false
26
+ Terminal=false
27
+ Hidden=false
28
+
29
+
30
+ .. _pipx: https://pypa.github.io/pipx/
@@ -0,0 +1,47 @@
1
+ #!/usr/bin/env python
2
+
3
+ """Listen for new sinks connected, and if it is the requested sink, make it the default sink.
4
+ """
5
+ import argparse
6
+
7
+ import pulsectl
8
+
9
+
10
+ def get_sink_by_desc(pulse, desc):
11
+ try:
12
+ return [s for s in pulse.sink_list() if desc in s.description][-1]
13
+ except IndexError:
14
+ return None
15
+
16
+
17
+ class Switcher:
18
+ def __init__(self, sink):
19
+ self._triggered = False
20
+ self._sink = sink
21
+
22
+ def callback(self, ev):
23
+ self._triggered = ev.t == pulsectl.PulseEventTypeEnum.new
24
+ raise pulsectl.PulseLoopStop
25
+
26
+ def switch(self, pulse):
27
+ if self._triggered:
28
+ if pulse_sink := get_sink_by_desc(pulse, self._sink):
29
+ pulse.default_set(pulse_sink)
30
+ self._triggered = False
31
+
32
+
33
+ def main():
34
+ parser = argparse.ArgumentParser(description=__doc__)
35
+ parser.add_argument("sink", help="Sink to switch to when connected")
36
+ options = parser.parse_args()
37
+ switcher = Switcher(options.sink)
38
+ with pulsectl.Pulse("audio-connected") as pulse:
39
+ pulse.event_mask_set("sink")
40
+ pulse.event_callback_set(switcher.callback)
41
+ while True:
42
+ pulse.event_listen(timeout=60)
43
+ switcher.switch(pulse)
44
+
45
+
46
+ if __name__ == '__main__':
47
+ main()
@@ -0,0 +1,22 @@
1
+ [tool.poetry]
2
+ name = "audio-connected"
3
+ version = "0.1.0"
4
+ description = "Watches PulseAudio events for new sinks connected, and if the name matches the configured name, make that sink the default sink."
5
+ authors = ["Morten Lied Johansen <mortenjo@ifi.uio.no>"]
6
+ readme = "README.rst"
7
+ packages = [{include = "audio_connected"}]
8
+
9
+ [tool.poetry.dependencies]
10
+ python = "^3.11"
11
+ pulsectl = "^23.5.2"
12
+
13
+
14
+ [tool.poetry.group.dev.dependencies]
15
+ pytest = "^7.4.3"
16
+
17
+ [build-system]
18
+ requires = ["poetry-core"]
19
+ build-backend = "poetry.core.masonry.api"
20
+
21
+ [tool.poetry.scripts]
22
+ audio-connected = "audio_connected:main"