sonosify 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.
- sonosify-0.1.0/.gitignore +96 -0
- sonosify-0.1.0/.pre-commit-config.yaml +28 -0
- sonosify-0.1.0/PKG-INFO +170 -0
- sonosify-0.1.0/README.md +158 -0
- sonosify-0.1.0/examples/discover.py +13 -0
- sonosify-0.1.0/examples/now_playing.py +20 -0
- sonosify-0.1.0/examples/play_radio.py +20 -0
- sonosify-0.1.0/examples/watch.py +23 -0
- sonosify-0.1.0/main.py +13 -0
- sonosify-0.1.0/plans/EMULATE_SOCO.md +150 -0
- sonosify-0.1.0/pyproject.toml +56 -0
- sonosify-0.1.0/sonosify/__init__.py +67 -0
- sonosify-0.1.0/sonosify/_parsing.py +22 -0
- sonosify-0.1.0/sonosify/cli.py +645 -0
- sonosify-0.1.0/sonosify/client.py +373 -0
- sonosify-0.1.0/sonosify/controller.py +85 -0
- sonosify-0.1.0/sonosify/didl.py +89 -0
- sonosify-0.1.0/sonosify/discovery.py +192 -0
- sonosify-0.1.0/sonosify/errors.py +31 -0
- sonosify-0.1.0/sonosify/events.py +350 -0
- sonosify-0.1.0/sonosify/models.py +57 -0
- sonosify-0.1.0/sonosify/soap.py +104 -0
- sonosify-0.1.0/sonosify/spotify.py +61 -0
- sonosify-0.1.0/sonosify/topology.py +69 -0
- sonosify-0.1.0/tests/test_client_open.py +39 -0
- sonosify-0.1.0/tests/test_controller.py +70 -0
- sonosify-0.1.0/tests/test_discovery.py +45 -0
- sonosify-0.1.0/tests/test_events.py +118 -0
- sonosify-0.1.0/tests/test_parsing.py +28 -0
- sonosify-0.1.0/tests/test_soap.py +38 -0
- sonosify-0.1.0/tests/test_spotify.py +30 -0
- sonosify-0.1.0/tests/test_topology.py +39 -0
- sonosify-0.1.0/uv.lock +471 -0
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
temp/
|
|
7
|
+
|
|
8
|
+
# Virtual environments
|
|
9
|
+
venv/
|
|
10
|
+
env/
|
|
11
|
+
.venv/
|
|
12
|
+
.env/
|
|
13
|
+
|
|
14
|
+
# Mkdocs
|
|
15
|
+
site/
|
|
16
|
+
|
|
17
|
+
# Distribution / packaging
|
|
18
|
+
build/
|
|
19
|
+
develop-eggs/
|
|
20
|
+
dist/
|
|
21
|
+
downloads/
|
|
22
|
+
eggs/
|
|
23
|
+
.eggs/
|
|
24
|
+
lib/
|
|
25
|
+
lib64/
|
|
26
|
+
parts/
|
|
27
|
+
sdist/
|
|
28
|
+
var/
|
|
29
|
+
*.egg-info/
|
|
30
|
+
.installed.cfg
|
|
31
|
+
*.egg
|
|
32
|
+
|
|
33
|
+
# PyInstaller
|
|
34
|
+
*.manifest
|
|
35
|
+
*.spec
|
|
36
|
+
|
|
37
|
+
# Installer logs
|
|
38
|
+
pip-log.txt
|
|
39
|
+
pip-delete-this-directory.txt
|
|
40
|
+
|
|
41
|
+
# Unit test / coverage reports
|
|
42
|
+
htmlcov/
|
|
43
|
+
.tox/
|
|
44
|
+
.nox/
|
|
45
|
+
.coverage
|
|
46
|
+
.coverage.*
|
|
47
|
+
.cache
|
|
48
|
+
nosetests.xml
|
|
49
|
+
coverage.xml
|
|
50
|
+
*.cover
|
|
51
|
+
.hypothesis/
|
|
52
|
+
.pytest_cache/
|
|
53
|
+
|
|
54
|
+
# Jupyter Notebook checkpoints
|
|
55
|
+
.ipynb_checkpoints
|
|
56
|
+
|
|
57
|
+
# pyenv
|
|
58
|
+
.python-version
|
|
59
|
+
|
|
60
|
+
# mypy
|
|
61
|
+
.mypy_cache/
|
|
62
|
+
.dmypy.json
|
|
63
|
+
dmypy.json
|
|
64
|
+
|
|
65
|
+
# Pyre
|
|
66
|
+
.pyre/
|
|
67
|
+
|
|
68
|
+
# Pytype
|
|
69
|
+
.pytype/
|
|
70
|
+
|
|
71
|
+
# Cython debug symbols
|
|
72
|
+
cython_debug/
|
|
73
|
+
|
|
74
|
+
# VS Code
|
|
75
|
+
.vscode/
|
|
76
|
+
|
|
77
|
+
# JetBrains IDEs (PyCharm, etc.)
|
|
78
|
+
.idea/
|
|
79
|
+
|
|
80
|
+
# MacOS
|
|
81
|
+
.DS_Store
|
|
82
|
+
|
|
83
|
+
# Windows
|
|
84
|
+
Thumbs.db
|
|
85
|
+
ehthumbs.db
|
|
86
|
+
desktop.ini
|
|
87
|
+
|
|
88
|
+
# dotenv files
|
|
89
|
+
.env
|
|
90
|
+
|
|
91
|
+
docs/node_modules/
|
|
92
|
+
|
|
93
|
+
.ruff_cache/
|
|
94
|
+
bandit-report.json
|
|
95
|
+
|
|
96
|
+
.claude/
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
default_language_version:
|
|
2
|
+
python: python3.14
|
|
3
|
+
|
|
4
|
+
repos:
|
|
5
|
+
- repo: https://github.com/pre-commit/pre-commit-hooks
|
|
6
|
+
rev: v5.0.0
|
|
7
|
+
hooks:
|
|
8
|
+
- id: trailing-whitespace
|
|
9
|
+
- id: end-of-file-fixer
|
|
10
|
+
- id: check-yaml
|
|
11
|
+
- id: check-toml
|
|
12
|
+
- id: check-added-large-files
|
|
13
|
+
- id: check-merge-conflict
|
|
14
|
+
- id: mixed-line-ending
|
|
15
|
+
args: [--fix=lf]
|
|
16
|
+
- id: debug-statements
|
|
17
|
+
|
|
18
|
+
- repo: https://github.com/astral-sh/ruff-pre-commit
|
|
19
|
+
rev: v0.15.19
|
|
20
|
+
hooks:
|
|
21
|
+
- id: ruff
|
|
22
|
+
args: [--fix]
|
|
23
|
+
- id: ruff-format
|
|
24
|
+
|
|
25
|
+
- repo: https://github.com/astral-sh/uv-pre-commit
|
|
26
|
+
rev: 0.9.2
|
|
27
|
+
hooks:
|
|
28
|
+
- id: uv-lock
|
sonosify-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: sonosify
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Programmatic Python API for discovering and controlling Sonos speakers.
|
|
5
|
+
Requires-Python: >=3.14
|
|
6
|
+
Requires-Dist: httpx>=0.28.1
|
|
7
|
+
Requires-Dist: pydantic>=2.13.4
|
|
8
|
+
Provides-Extra: cli
|
|
9
|
+
Requires-Dist: rich>=13.0; extra == 'cli'
|
|
10
|
+
Requires-Dist: typer>=0.12.0; extra == 'cli'
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
|
|
13
|
+
# sonosify
|
|
14
|
+
|
|
15
|
+
Programmatic Python API for discovering and controlling Sonos speakers on a local network.
|
|
16
|
+
|
|
17
|
+
This package ports the API core of `steipete/sonoscli` into Python. An optional
|
|
18
|
+
command-line interface is available via the `cli` extra (see below).
|
|
19
|
+
|
|
20
|
+
```python
|
|
21
|
+
import asyncio
|
|
22
|
+
|
|
23
|
+
from sonosify import SonosController
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
async def main():
|
|
27
|
+
sonos = SonosController()
|
|
28
|
+
system = await sonos.discover()
|
|
29
|
+
|
|
30
|
+
print([speaker.room_name for speaker in system.speakers])
|
|
31
|
+
|
|
32
|
+
async with await sonos.client("Kitchen") as kitchen:
|
|
33
|
+
await kitchen.pause()
|
|
34
|
+
await kitchen.set_volume(25)
|
|
35
|
+
print(await kitchen.now_playing())
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
asyncio.run(main())
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Lower-level direct device access is also available:
|
|
42
|
+
|
|
43
|
+
```python
|
|
44
|
+
import asyncio
|
|
45
|
+
|
|
46
|
+
from sonosify import SonosClient
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
async def main():
|
|
50
|
+
async with SonosClient("192.168.1.42") as speaker:
|
|
51
|
+
await speaker.play_uri("https://example.com/live.mp3", radio=True, title="Example Radio")
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
asyncio.run(main())
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Live updates use Sonos UPnP event subscriptions:
|
|
58
|
+
|
|
59
|
+
```python
|
|
60
|
+
import asyncio
|
|
61
|
+
|
|
62
|
+
from sonosify import AVTransportEvent, RenderingControlEvent, SonosController
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
async def main():
|
|
66
|
+
sonos = SonosController()
|
|
67
|
+
async with sonos.watch("Kitchen") as watcher:
|
|
68
|
+
async for event in watcher:
|
|
69
|
+
match event:
|
|
70
|
+
case AVTransportEvent(transport_state=state, track=track):
|
|
71
|
+
print(state, track.title if track else "")
|
|
72
|
+
case RenderingControlEvent(volume=volume, muted=muted):
|
|
73
|
+
print(volume, muted)
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
asyncio.run(main())
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
The watch API starts a local HTTP callback server. Your OS firewall may ask whether Python can accept incoming connections.
|
|
80
|
+
|
|
81
|
+
See `examples/` for runnable scripts:
|
|
82
|
+
|
|
83
|
+
```powershell
|
|
84
|
+
uv run python examples/discover.py
|
|
85
|
+
uv run python examples/now_playing.py Kitchen
|
|
86
|
+
uv run python examples/watch.py Kitchen
|
|
87
|
+
uv run python examples/play_radio.py Kitchen https://example.com/live.mp3 "Example Radio"
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## Command-line interface
|
|
91
|
+
|
|
92
|
+
Install the optional CLI dependencies (Typer + Rich):
|
|
93
|
+
|
|
94
|
+
```powershell
|
|
95
|
+
uv pip install -e ".[cli]"
|
|
96
|
+
# or, from PyPI: pip install "sonosify[cli]"
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
This exposes a `sonosify` command:
|
|
100
|
+
|
|
101
|
+
```powershell
|
|
102
|
+
sonosify discover # list speakers on the network
|
|
103
|
+
sonosify now-playing Kitchen # show the current track
|
|
104
|
+
sonosify play Kitchen # resume playback
|
|
105
|
+
sonosify pause Kitchen # pause playback
|
|
106
|
+
sonosify stop Kitchen # stop playback
|
|
107
|
+
sonosify next Kitchen # skip to the next track
|
|
108
|
+
sonosify previous Kitchen # skip to the previous track
|
|
109
|
+
sonosify volume Kitchen 25 # set volume (omit the number to read it)
|
|
110
|
+
sonosify volume 25 # set volume on the configured default speaker
|
|
111
|
+
sonosify volume-up Kitchen 10 # raise volume by N percentage points (default 5)
|
|
112
|
+
sonosify volume-down Kitchen 10 # lower volume by N percentage points (default 5)
|
|
113
|
+
sonosify mute Kitchen --on # --on / --off, or omit to toggle
|
|
114
|
+
sonosify queue Kitchen # show the queue
|
|
115
|
+
sonosify favorites list Kitchen # list favorites
|
|
116
|
+
sonosify favorites play Kitchen "Jazz" # play a favorite by name
|
|
117
|
+
sonosify enqueue x-file-cifs://... --room Kitchen
|
|
118
|
+
sonosify open https://example.com/live.mp3 --room Kitchen --radio --title "Example Radio"
|
|
119
|
+
sonosify track 6NmXV4o6bmp704aPGyTVVG --room Kitchen
|
|
120
|
+
sonosify track 6NmXV4o6bmp704aPGyTVVG --room Kitchen --enqueue
|
|
121
|
+
sonosify watch Kitchen # stream live events (Ctrl+C to stop)
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### Targeting a speaker
|
|
125
|
+
|
|
126
|
+
Every command accepts an optional room name as its first argument, or `--ip <address>`
|
|
127
|
+
to skip name matching entirely.
|
|
128
|
+
|
|
129
|
+
### Default speaker
|
|
130
|
+
|
|
131
|
+
Set a default speaker once and omit the room name from then on:
|
|
132
|
+
|
|
133
|
+
```powershell
|
|
134
|
+
sonosify config set --room Kitchen # or: sonosify config set --ip 192.168.1.42
|
|
135
|
+
sonosify config show # show current defaults
|
|
136
|
+
sonosify config clear # remove defaults
|
|
137
|
+
|
|
138
|
+
sonosify play # now targets Kitchen automatically
|
|
139
|
+
sonosify volume 25 # set Kitchen to 25
|
|
140
|
+
sonosify volume-up
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
An explicit room name or `--ip` on a command always overrides the configured default.
|
|
144
|
+
The config is stored as JSON in your platform's app-config directory.
|
|
145
|
+
|
|
146
|
+
### Output format
|
|
147
|
+
|
|
148
|
+
Use `--format` (before the command) for machine-readable output in scripts:
|
|
149
|
+
|
|
150
|
+
```powershell
|
|
151
|
+
sonosify --format json discover # JSON array of speakers
|
|
152
|
+
sonosify --format tsv queue Kitchen # tab-separated rows
|
|
153
|
+
sonosify --format json now-playing # JSON object
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
`plain` (the default) renders rich tables and colored text for interactive use.
|
|
157
|
+
|
|
158
|
+
### Debugging
|
|
159
|
+
|
|
160
|
+
Add `--debug` (before the command) to print the underlying SOAP request/response
|
|
161
|
+
traces to stderr:
|
|
162
|
+
|
|
163
|
+
```powershell
|
|
164
|
+
sonosify --debug volume Kitchen
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
`sonosify track ...` expects a track id, track URI, or track URL. Playback works when
|
|
168
|
+
the corresponding music service is already linked on your Sonos household.
|
|
169
|
+
|
|
170
|
+
Exports are collected in `sonosify.__init__` for library consumers.
|
sonosify-0.1.0/README.md
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
# sonosify
|
|
2
|
+
|
|
3
|
+
Programmatic Python API for discovering and controlling Sonos speakers on a local network.
|
|
4
|
+
|
|
5
|
+
This package ports the API core of `steipete/sonoscli` into Python. An optional
|
|
6
|
+
command-line interface is available via the `cli` extra (see below).
|
|
7
|
+
|
|
8
|
+
```python
|
|
9
|
+
import asyncio
|
|
10
|
+
|
|
11
|
+
from sonosify import SonosController
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
async def main():
|
|
15
|
+
sonos = SonosController()
|
|
16
|
+
system = await sonos.discover()
|
|
17
|
+
|
|
18
|
+
print([speaker.room_name for speaker in system.speakers])
|
|
19
|
+
|
|
20
|
+
async with await sonos.client("Kitchen") as kitchen:
|
|
21
|
+
await kitchen.pause()
|
|
22
|
+
await kitchen.set_volume(25)
|
|
23
|
+
print(await kitchen.now_playing())
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
asyncio.run(main())
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Lower-level direct device access is also available:
|
|
30
|
+
|
|
31
|
+
```python
|
|
32
|
+
import asyncio
|
|
33
|
+
|
|
34
|
+
from sonosify import SonosClient
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
async def main():
|
|
38
|
+
async with SonosClient("192.168.1.42") as speaker:
|
|
39
|
+
await speaker.play_uri("https://example.com/live.mp3", radio=True, title="Example Radio")
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
asyncio.run(main())
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Live updates use Sonos UPnP event subscriptions:
|
|
46
|
+
|
|
47
|
+
```python
|
|
48
|
+
import asyncio
|
|
49
|
+
|
|
50
|
+
from sonosify import AVTransportEvent, RenderingControlEvent, SonosController
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
async def main():
|
|
54
|
+
sonos = SonosController()
|
|
55
|
+
async with sonos.watch("Kitchen") as watcher:
|
|
56
|
+
async for event in watcher:
|
|
57
|
+
match event:
|
|
58
|
+
case AVTransportEvent(transport_state=state, track=track):
|
|
59
|
+
print(state, track.title if track else "")
|
|
60
|
+
case RenderingControlEvent(volume=volume, muted=muted):
|
|
61
|
+
print(volume, muted)
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
asyncio.run(main())
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
The watch API starts a local HTTP callback server. Your OS firewall may ask whether Python can accept incoming connections.
|
|
68
|
+
|
|
69
|
+
See `examples/` for runnable scripts:
|
|
70
|
+
|
|
71
|
+
```powershell
|
|
72
|
+
uv run python examples/discover.py
|
|
73
|
+
uv run python examples/now_playing.py Kitchen
|
|
74
|
+
uv run python examples/watch.py Kitchen
|
|
75
|
+
uv run python examples/play_radio.py Kitchen https://example.com/live.mp3 "Example Radio"
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Command-line interface
|
|
79
|
+
|
|
80
|
+
Install the optional CLI dependencies (Typer + Rich):
|
|
81
|
+
|
|
82
|
+
```powershell
|
|
83
|
+
uv pip install -e ".[cli]"
|
|
84
|
+
# or, from PyPI: pip install "sonosify[cli]"
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
This exposes a `sonosify` command:
|
|
88
|
+
|
|
89
|
+
```powershell
|
|
90
|
+
sonosify discover # list speakers on the network
|
|
91
|
+
sonosify now-playing Kitchen # show the current track
|
|
92
|
+
sonosify play Kitchen # resume playback
|
|
93
|
+
sonosify pause Kitchen # pause playback
|
|
94
|
+
sonosify stop Kitchen # stop playback
|
|
95
|
+
sonosify next Kitchen # skip to the next track
|
|
96
|
+
sonosify previous Kitchen # skip to the previous track
|
|
97
|
+
sonosify volume Kitchen 25 # set volume (omit the number to read it)
|
|
98
|
+
sonosify volume 25 # set volume on the configured default speaker
|
|
99
|
+
sonosify volume-up Kitchen 10 # raise volume by N percentage points (default 5)
|
|
100
|
+
sonosify volume-down Kitchen 10 # lower volume by N percentage points (default 5)
|
|
101
|
+
sonosify mute Kitchen --on # --on / --off, or omit to toggle
|
|
102
|
+
sonosify queue Kitchen # show the queue
|
|
103
|
+
sonosify favorites list Kitchen # list favorites
|
|
104
|
+
sonosify favorites play Kitchen "Jazz" # play a favorite by name
|
|
105
|
+
sonosify enqueue x-file-cifs://... --room Kitchen
|
|
106
|
+
sonosify open https://example.com/live.mp3 --room Kitchen --radio --title "Example Radio"
|
|
107
|
+
sonosify track 6NmXV4o6bmp704aPGyTVVG --room Kitchen
|
|
108
|
+
sonosify track 6NmXV4o6bmp704aPGyTVVG --room Kitchen --enqueue
|
|
109
|
+
sonosify watch Kitchen # stream live events (Ctrl+C to stop)
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### Targeting a speaker
|
|
113
|
+
|
|
114
|
+
Every command accepts an optional room name as its first argument, or `--ip <address>`
|
|
115
|
+
to skip name matching entirely.
|
|
116
|
+
|
|
117
|
+
### Default speaker
|
|
118
|
+
|
|
119
|
+
Set a default speaker once and omit the room name from then on:
|
|
120
|
+
|
|
121
|
+
```powershell
|
|
122
|
+
sonosify config set --room Kitchen # or: sonosify config set --ip 192.168.1.42
|
|
123
|
+
sonosify config show # show current defaults
|
|
124
|
+
sonosify config clear # remove defaults
|
|
125
|
+
|
|
126
|
+
sonosify play # now targets Kitchen automatically
|
|
127
|
+
sonosify volume 25 # set Kitchen to 25
|
|
128
|
+
sonosify volume-up
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
An explicit room name or `--ip` on a command always overrides the configured default.
|
|
132
|
+
The config is stored as JSON in your platform's app-config directory.
|
|
133
|
+
|
|
134
|
+
### Output format
|
|
135
|
+
|
|
136
|
+
Use `--format` (before the command) for machine-readable output in scripts:
|
|
137
|
+
|
|
138
|
+
```powershell
|
|
139
|
+
sonosify --format json discover # JSON array of speakers
|
|
140
|
+
sonosify --format tsv queue Kitchen # tab-separated rows
|
|
141
|
+
sonosify --format json now-playing # JSON object
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
`plain` (the default) renders rich tables and colored text for interactive use.
|
|
145
|
+
|
|
146
|
+
### Debugging
|
|
147
|
+
|
|
148
|
+
Add `--debug` (before the command) to print the underlying SOAP request/response
|
|
149
|
+
traces to stderr:
|
|
150
|
+
|
|
151
|
+
```powershell
|
|
152
|
+
sonosify --debug volume Kitchen
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
`sonosify track ...` expects a track id, track URI, or track URL. Playback works when
|
|
156
|
+
the corresponding music service is already linked on your Sonos household.
|
|
157
|
+
|
|
158
|
+
Exports are collected in `sonosify.__init__` for library consumers.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
|
|
3
|
+
from sonosify import discover
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
async def main() -> None:
|
|
7
|
+
system = await discover()
|
|
8
|
+
for speaker in system.speakers:
|
|
9
|
+
coordinator = "coordinator" if speaker.is_coordinator else "member"
|
|
10
|
+
print(f"{speaker.room_name:24} {speaker.ip:15} {coordinator}")
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
asyncio.run(main())
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
import sys
|
|
3
|
+
|
|
4
|
+
from sonosify import SonosController
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
async def main() -> None:
|
|
8
|
+
room = sys.argv[1] if len(sys.argv) > 1 else None
|
|
9
|
+
sonos = SonosController()
|
|
10
|
+
async with await sonos.client(room) as client:
|
|
11
|
+
state = await client.now_playing()
|
|
12
|
+
|
|
13
|
+
print(state.state)
|
|
14
|
+
if state.track:
|
|
15
|
+
print(state.track.title)
|
|
16
|
+
print(state.track.creator)
|
|
17
|
+
print(state.track.album)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
asyncio.run(main())
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
import sys
|
|
3
|
+
|
|
4
|
+
from sonosify import SonosController
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
async def main() -> None:
|
|
8
|
+
if len(sys.argv) < 3:
|
|
9
|
+
raise SystemExit("usage: python examples/play_radio.py ROOM STREAM_URL [TITLE]")
|
|
10
|
+
|
|
11
|
+
room = sys.argv[1]
|
|
12
|
+
stream_url = sys.argv[2]
|
|
13
|
+
title = sys.argv[3] if len(sys.argv) > 3 else stream_url
|
|
14
|
+
|
|
15
|
+
sonos = SonosController()
|
|
16
|
+
async with await sonos.client(room) as client:
|
|
17
|
+
await client.play_uri(stream_url, radio=True, title=title)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
asyncio.run(main())
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
import sys
|
|
3
|
+
|
|
4
|
+
from sonosify import AVTransportEvent, RenderingControlEvent, SonosController
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
async def main() -> None:
|
|
8
|
+
room = sys.argv[1] if len(sys.argv) > 1 else None
|
|
9
|
+
sonos = SonosController()
|
|
10
|
+
|
|
11
|
+
async with sonos.watch(room) as watcher:
|
|
12
|
+
print(f"watching {watcher.ip}; press Ctrl+C to stop")
|
|
13
|
+
async for event in watcher:
|
|
14
|
+
match event:
|
|
15
|
+
case AVTransportEvent(transport_state=state, track=track):
|
|
16
|
+
print("transport", state, track.title if track else "")
|
|
17
|
+
case RenderingControlEvent(volume=volume, muted=muted):
|
|
18
|
+
print("rendering", "volume=", volume, "muted=", muted)
|
|
19
|
+
case _:
|
|
20
|
+
print(event.service, event.values)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
asyncio.run(main())
|
sonosify-0.1.0/main.py
ADDED