-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSocoTextualRemote_ListView.py
More file actions
78 lines (61 loc) · 2.43 KB
/
SocoTextualRemote_ListView.py
File metadata and controls
78 lines (61 loc) · 2.43 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
from textual import on
from textual.app import App, ComposeResult
from textual.widgets import ListView, ListItem, Label, Header, Footer, ProgressBar
import soco
TESTING = False
class URLItem(ListItem):
def __init__(self, title: str, url: str) -> None:
super().__init__()
self.title = title
self.url = url
def compose(self) -> ComposeResult:
yield Label(self.title)
class SocoTextualRemote(App[None]):
def compose(self) -> ComposeResult:
yield Label("Chosen will go here", id="result")
yield ListView(
URLItem("SR P1", "x-rincon-mp3radio://https://http-live.sr.se/p1-mp3-192"),
URLItem("SR P2", "x-rincon-mp3radio://https://http-live.sr.se/p2-mp3-192"),
URLItem("SR P3", "x-rincon-mp3radio://https://http-live.sr.se/p3-mp3-192"),
URLItem("FM4", "x-rincon-mp3radio://https://orf-live.ors-shoutcast.at/fm4-q2a"),
)
yield ProgressBar(total=100, show_eta=False)
yield Header()
yield Footer()
BINDINGS = [("s", "stop_sonos", "Stop"), ("+", "vol_up", "Vol +"), ("-", "vol_down", "Vol -"), ("q", "quit", "Quit")]
def action_stop_sonos(self) -> None:
if not TESTING:
sonos_speaker.stop()
else:
print("def action_stop_sonos")
def action_vol_up(self) -> None:
sonos_speaker.volume +=2
self.query_one(ProgressBar).advance(2)
def action_vol_down(self) -> None:
sonos_speaker.volume -=2
self.query_one(ProgressBar).advance(-2)
def action_quit(self) -> None:
self.exit()
def on_mount(self) -> None:
self.title = "🔊 Now playing: "
if not TESTING:
"""TODO: read on how to make below reactive methods"""
self.sub_title = str(track['artist']+" · "+track['title'])
self.query_one(ProgressBar).advance(sonos_speaker.volume)
else:
self.sub_title = "Sonos - TESTING MODE"
@on(ListView.Selected)
def url_choice(self, event: ListView.Selected) -> None:
sonos_speaker.play_uri(event.item.url)
self.query_one("#result", Label).update(event.item.url)
if __name__ == "__main__":
if not TESTING:
sonos_speaker = soco.discovery.any_soco()
try:
track = sonos_speaker.get_current_track_info()
except:
print("Error: speaker not found.")
exit()
else:
pass
SocoTextualRemote().run()