noneto-cli 1.1.1__py3-none-any.whl
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.
- noneto/__init__.py +1 -0
- noneto/__main__.py +3 -0
- noneto/app.py +113 -0
- noneto/assets/noneto.ico +0 -0
- noneto/audio/__init__.py +1 -0
- noneto/audio/controller.py +427 -0
- noneto/audio/inspector.py +21 -0
- noneto/audio/ipc_unix.py +29 -0
- noneto/audio/ipc_windows.py +94 -0
- noneto/audio/lifetime.py +68 -0
- noneto/audio/media_controls.py +107 -0
- noneto/audio/mpv_install.py +71 -0
- noneto/audio/player.py +222 -0
- noneto/audio/pulse_tap.py +120 -0
- noneto/audio/spectrum.py +44 -0
- noneto/audio/streams.py +101 -0
- noneto/audio/tap.py +208 -0
- noneto/audio/windows_identity.py +79 -0
- noneto/audio/windows_media.py +157 -0
- noneto/auth/__init__.py +1 -0
- noneto/auth/dpapi.py +28 -0
- noneto/auth/service.py +53 -0
- noneto/auth/storage.py +120 -0
- noneto/diagnostics.py +115 -0
- noneto/errors.py +12 -0
- noneto/i18n.py +199 -0
- noneto/platform/__init__.py +1 -0
- noneto/platform/paths.py +27 -0
- noneto/security.py +59 -0
- noneto/services/__init__.py +1 -0
- noneto/services/covers.py +88 -0
- noneto/services/executor.py +83 -0
- noneto/services/library.py +110 -0
- noneto/services/tidal.py +188 -0
- noneto/settings.py +48 -0
- noneto/state/__init__.py +1 -0
- noneto/state/queue.py +130 -0
- noneto/state/writer.py +38 -0
- noneto/ui/__init__.py +1 -0
- noneto/ui/common.py +36 -0
- noneto/ui/cover.py +88 -0
- noneto/ui/dialogs.py +107 -0
- noneto/ui/linux_login.py +57 -0
- noneto/ui/login_window.py +201 -0
- noneto/ui/lyrics.py +142 -0
- noneto/ui/player.py +172 -0
- noneto/ui/quality.py +75 -0
- noneto/ui/queue.py +34 -0
- noneto/ui/terminal.py +65 -0
- noneto/ui/themes.py +352 -0
- noneto/ui/top.py +39 -0
- noneto/ui/tracks.py +139 -0
- noneto/ui/tui.py +601 -0
- noneto/ui/visualizer.py +343 -0
- noneto_cli-1.1.1.dist-info/METADATA +222 -0
- noneto_cli-1.1.1.dist-info/RECORD +59 -0
- noneto_cli-1.1.1.dist-info/WHEEL +4 -0
- noneto_cli-1.1.1.dist-info/entry_points.txt +2 -0
- noneto_cli-1.1.1.dist-info/licenses/LICENSE +21 -0
noneto/ui/tui.py
ADDED
|
@@ -0,0 +1,601 @@
|
|
|
1
|
+
"""Mouse and keyboard interface; all account and playback work is injected.
|
|
2
|
+
|
|
3
|
+
NonetoApp composes the pieces and runs the workflows (library, search, playlists, media
|
|
4
|
+
loading). Each piece lives in its own module:
|
|
5
|
+
|
|
6
|
+
top.py logo, Library ▾, search box quality.py quality badge
|
|
7
|
+
tracks.py Songs table queue.py Queue tab
|
|
8
|
+
lyrics.py Lyrics tab (layouts, lyrics) visualizer.py track aura under the lyrics
|
|
9
|
+
cover.py both covers (image or blocks) player.py player bar and its controls
|
|
10
|
+
dialogs.py modal dialogs themes.py palettes
|
|
11
|
+
"""
|
|
12
|
+
import asyncio
|
|
13
|
+
|
|
14
|
+
from rich.cells import cell_len
|
|
15
|
+
from rich.text import Text
|
|
16
|
+
from textual import on, work
|
|
17
|
+
from textual.app import App
|
|
18
|
+
from textual.binding import Binding
|
|
19
|
+
from textual.containers import Horizontal, Vertical
|
|
20
|
+
from textual.message import Message
|
|
21
|
+
from textual.screen import ModalScreen
|
|
22
|
+
from textual.widgets import Button, Footer, Input, Label, ListItem, ListView, Static, TabbedContent, TabPane
|
|
23
|
+
|
|
24
|
+
from ..diagnostics import failure
|
|
25
|
+
from ..errors import AppError, error_label
|
|
26
|
+
from ..i18n import _
|
|
27
|
+
from . import cover, dialogs, lyrics, player, quality, queue, top, tracks, visualizer
|
|
28
|
+
from .common import Changes, artist, clean
|
|
29
|
+
from .cover import CoverArt
|
|
30
|
+
from .dialogs import ChoosePlaylist, CreatePlaylist, LibraryScreen
|
|
31
|
+
from .lyrics import LAYOUTS, LyricsPanel
|
|
32
|
+
from .player import PlayerBar, playback_mode
|
|
33
|
+
from .quality import QualityBadge
|
|
34
|
+
from .queue import QueueList
|
|
35
|
+
from .themes import CUSTOM_THEMES, TIDAL_DARK, available_themes
|
|
36
|
+
from .top import TopBar
|
|
37
|
+
from .tracks import TrackTable
|
|
38
|
+
from .visualizer import MODE_LABELS, Visualizer, available_visualizer_modes
|
|
39
|
+
|
|
40
|
+
BASE_CSS = """
|
|
41
|
+
Screen { background: $background; color: $foreground; }
|
|
42
|
+
Button { min-width: 3; height: 1; border: none; margin-right: 1; }
|
|
43
|
+
Button.-primary { background: $primary; color: $button-color-foreground; }
|
|
44
|
+
"""
|
|
45
|
+
VIEWS_CSS = """
|
|
46
|
+
#views-wrap, #views { height: 1fr; }
|
|
47
|
+
#views-wrap { margin-top: 1; }
|
|
48
|
+
#hint { position: absolute; height: 1; padding: 0 1; color: $text-muted;
|
|
49
|
+
text-wrap: nowrap; text-overflow: ellipsis; }
|
|
50
|
+
#views ContentSwitcher { height: 1fr; }
|
|
51
|
+
TabPane { height: 1fr; padding: 0; }
|
|
52
|
+
#playlist-results { height: 1fr; background: $background; }
|
|
53
|
+
#more { width: 100%; margin: 0; }
|
|
54
|
+
"""
|
|
55
|
+
STATUS_CSS = """
|
|
56
|
+
#song-actions { height: 1; background: $surface; padding: 0 1; }
|
|
57
|
+
#action-target { width: 1fr; height: 1; color: $text-muted; }
|
|
58
|
+
#song-actions Button { background: $panel; }
|
|
59
|
+
#statusbar { height: 1; padding: 0 1; }
|
|
60
|
+
#message { width: 1fr; height: 1; color: $text-muted; }
|
|
61
|
+
#mode { width: auto; height: 1; color: $text-muted; padding-left: 2; }
|
|
62
|
+
Footer { background: $background; }
|
|
63
|
+
"""
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
class Views(TabbedContent):
|
|
67
|
+
"""Tabs that report their size after layout, unlike App resize events."""
|
|
68
|
+
|
|
69
|
+
class Resized(Message):
|
|
70
|
+
pass
|
|
71
|
+
|
|
72
|
+
def on_resize(self):
|
|
73
|
+
self.post_message(self.Resized())
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
class NonetoApp(App):
|
|
77
|
+
TITLE = "Noneto CLI"
|
|
78
|
+
ENABLE_COMMAND_PALETTE = False
|
|
79
|
+
CSS = "".join((BASE_CSS, top.CSS, quality.CSS, VIEWS_CSS, tracks.CSS, queue.CSS, lyrics.CSS,
|
|
80
|
+
cover.CSS, visualizer.CSS, player.CSS, STATUS_CSS, dialogs.CSS))
|
|
81
|
+
BINDINGS = [Binding("ctrl+q,ctrl+c", "quit", _("Quit"), priority=True),
|
|
82
|
+
Binding("ctrl+f", "search", _("Search"), priority=True),
|
|
83
|
+
Binding("ctrl+l", "library", _("Library"), priority=True),
|
|
84
|
+
Binding("ctrl+n", "new_playlist", _("New playlist")),
|
|
85
|
+
Binding("space", "pause", _("Pause")), Binding("ctrl+right", "next", _("Next")),
|
|
86
|
+
Binding("ctrl+t", "next_theme", _("Theme")),
|
|
87
|
+
Binding("ctrl+g", "next_visualizer", _("Aura")),
|
|
88
|
+
Binding("ctrl+o", "toggle_lyrics_layout", _("Cover"))]
|
|
89
|
+
|
|
90
|
+
def __init__(self, library, playback, quality="HI_RES_LOSSLESS", initial_playlist=None, user_name=None,
|
|
91
|
+
theme=None, on_theme=None, visualizer_mode=None, on_visualizer_mode=None, artwork=None,
|
|
92
|
+
lyrics_layout=None, on_lyrics_layout=None):
|
|
93
|
+
super().__init__()
|
|
94
|
+
for custom_theme in CUSTOM_THEMES.values():
|
|
95
|
+
self.register_theme(custom_theme)
|
|
96
|
+
themes = available_themes()
|
|
97
|
+
modes = available_visualizer_modes()
|
|
98
|
+
self.theme = theme if theme in themes else TIDAL_DARK.name
|
|
99
|
+
self.on_theme = on_theme # persists the choice; the UI itself never writes files
|
|
100
|
+
self.visualizer_mode = visualizer_mode if visualizer_mode in modes else "classic"
|
|
101
|
+
self.on_visualizer_mode = on_visualizer_mode
|
|
102
|
+
self.lyrics_layout = lyrics_layout if lyrics_layout in LAYOUTS else "lyrics"
|
|
103
|
+
self.on_lyrics_layout = on_lyrics_layout
|
|
104
|
+
self.library, self.playback = library, playback
|
|
105
|
+
self.covers = CoverArt(artwork) # artwork from terminal_artwork(); None draws half blocks
|
|
106
|
+
self.quality, self.initial_playlist = quality, initial_playlist
|
|
107
|
+
self.user_name = user_name
|
|
108
|
+
self.playlists = []
|
|
109
|
+
self.current_playlist = None
|
|
110
|
+
self.playlist_results = []
|
|
111
|
+
self._loading_playlists = False
|
|
112
|
+
self.search_query = ""
|
|
113
|
+
self._generation = 0
|
|
114
|
+
self._loading_more = False
|
|
115
|
+
self._writing = False
|
|
116
|
+
self._refreshing = False
|
|
117
|
+
self._last_error = ""
|
|
118
|
+
self._current_track_id = None
|
|
119
|
+
self._view_requests = set()
|
|
120
|
+
self._media_requests = set()
|
|
121
|
+
self._media_generation = 0
|
|
122
|
+
self._source_name = ""
|
|
123
|
+
self._queue_signature = None
|
|
124
|
+
self._visualizer_on = False
|
|
125
|
+
self._changes = Changes()
|
|
126
|
+
self._hint_text = ""
|
|
127
|
+
self._table = None # set on mount
|
|
128
|
+
|
|
129
|
+
def compose(self):
|
|
130
|
+
yield TopBar(self.user_name, self.quality, id="top")
|
|
131
|
+
with Vertical(id="views-wrap"):
|
|
132
|
+
with Views(id="views", initial="songs-view"):
|
|
133
|
+
with TabPane(_("Songs"), id="songs-view"):
|
|
134
|
+
yield TrackTable(id="tracks", cursor_type="row", zebra_stripes=True)
|
|
135
|
+
yield Button(_("More results"), id="more")
|
|
136
|
+
with TabPane("Playlists", id="playlists-view"):
|
|
137
|
+
yield ListView(id="playlist-results")
|
|
138
|
+
yield Static(_("No playlists in this search."), id="empty-results", markup=False)
|
|
139
|
+
yield Button(_("More results"), id="more-playlists")
|
|
140
|
+
with TabPane(_("Queue"), id="queue-view"):
|
|
141
|
+
yield QueueList(id="rail")
|
|
142
|
+
with TabPane(_("Lyrics"), id="lyrics-view"):
|
|
143
|
+
yield LyricsPanel(self.covers, self.lyrics_layout, id="lyrics-pane")
|
|
144
|
+
yield Visualizer(lambda count: self.playback.bands(count), mode=self.visualizer_mode, id="visualizer")
|
|
145
|
+
# Overlaid on the free end of the tab row; _place_hint keeps it clear of the tabs.
|
|
146
|
+
yield Static("", id="hint", markup=False)
|
|
147
|
+
with Horizontal(id="song-actions"):
|
|
148
|
+
yield Static(_("Select a song"), id="action-target", markup=False)
|
|
149
|
+
yield Button(_("+ Queue"), id="track-enqueue")
|
|
150
|
+
yield Button("+ Playlist", id="track-add")
|
|
151
|
+
yield PlayerBar(self.covers.widget("mini-cover", 6, 3), id="player")
|
|
152
|
+
with Horizontal(id="statusbar"):
|
|
153
|
+
yield Static(_("Loading library…"), id="message", markup=False)
|
|
154
|
+
yield Static("", id="mode", markup=False)
|
|
155
|
+
yield Footer()
|
|
156
|
+
|
|
157
|
+
def _handle_exception(self, error):
|
|
158
|
+
# Textual's default fatal screen includes locals. Account objects must never
|
|
159
|
+
# reach that renderer, even when an unexpected programming error occurs.
|
|
160
|
+
failure("ui.fatal", error)
|
|
161
|
+
if self._exception is None:
|
|
162
|
+
self._exception = error
|
|
163
|
+
self._exception_event.set()
|
|
164
|
+
self.exit(return_code=1, message=_("The interface closed because of an error. See the Noneto CLI logs."))
|
|
165
|
+
|
|
166
|
+
async def on_mount(self):
|
|
167
|
+
self._table = self.query_one(TrackTable)
|
|
168
|
+
self._player = self.query_one(PlayerBar)
|
|
169
|
+
self._lyrics = self.query_one(LyricsPanel)
|
|
170
|
+
self._queue = self.query_one(QueueList)
|
|
171
|
+
self._quality = self.query_one(QualityBadge)
|
|
172
|
+
self._hint = self.query_one("#hint", Static)
|
|
173
|
+
self._mode = self.query_one("#mode", Static)
|
|
174
|
+
self._action_target = self.query_one("#action-target", Static)
|
|
175
|
+
self._message_widget = self.query_one("#message", Static)
|
|
176
|
+
self._views = self.query_one("#views", TabbedContent)
|
|
177
|
+
self._update_action_target()
|
|
178
|
+
self.query_one("#more", Button).display = False
|
|
179
|
+
self.query_one("#more-playlists", Button).display = False
|
|
180
|
+
self._views.hide_tab("playlists-view")
|
|
181
|
+
self.set_interval(0.25, self.update_player)
|
|
182
|
+
self.refresh_library(initial=True)
|
|
183
|
+
|
|
184
|
+
@property
|
|
185
|
+
def tracks(self):
|
|
186
|
+
return self._table.tracks
|
|
187
|
+
|
|
188
|
+
def hint(self, value):
|
|
189
|
+
self._hint_text = clean(value)
|
|
190
|
+
self._hint.update(self._hint_text)
|
|
191
|
+
self._place_hint()
|
|
192
|
+
|
|
193
|
+
def _place_hint(self):
|
|
194
|
+
wrap = self.query_one("#views-wrap").region
|
|
195
|
+
tabs_end = max((tab.region.right for tab in self.query("#views Tab")), default=wrap.x)
|
|
196
|
+
width = min(max(0, wrap.right - tabs_end - 1), cell_len(self._hint_text) + 2)
|
|
197
|
+
self._hint.styles.width = width
|
|
198
|
+
self._hint.styles.offset = (wrap.width - width, 0)
|
|
199
|
+
self._hint.display = width > 4
|
|
200
|
+
|
|
201
|
+
@on(Views.Resized)
|
|
202
|
+
def _views_resized(self):
|
|
203
|
+
self._place_hint()
|
|
204
|
+
self._update_visualizer()
|
|
205
|
+
|
|
206
|
+
@on(TabbedContent.TabActivated)
|
|
207
|
+
def _tab_changed(self):
|
|
208
|
+
self.call_after_refresh(self._update_visualizer)
|
|
209
|
+
if self._views.active == "songs-view":
|
|
210
|
+
self.call_after_refresh(self._table.focus)
|
|
211
|
+
elif self._views.active == "playlists-view":
|
|
212
|
+
self.call_after_refresh(self.query_one("#playlist-results", ListView).focus)
|
|
213
|
+
|
|
214
|
+
def _update_visualizer(self):
|
|
215
|
+
show = self.query_one(Visualizer).fit(self.query_one("#views ContentSwitcher").size,
|
|
216
|
+
self._views.active == "lyrics-view")
|
|
217
|
+
if show != self._visualizer_on:
|
|
218
|
+
self._visualizer_on = show
|
|
219
|
+
self.control("visualizer", show)
|
|
220
|
+
|
|
221
|
+
async def api(self, operation, *args):
|
|
222
|
+
future = self.library.submit(operation, *args)
|
|
223
|
+
requests = (self._media_requests if operation in ("lyrics", "artwork") else
|
|
224
|
+
self._view_requests if operation in ("tracks", "search", "search_playlists") else None)
|
|
225
|
+
if requests is not None:
|
|
226
|
+
requests.add(future)
|
|
227
|
+
try:
|
|
228
|
+
return await asyncio.wrap_future(future)
|
|
229
|
+
finally:
|
|
230
|
+
if requests is not None:
|
|
231
|
+
requests.discard(future)
|
|
232
|
+
|
|
233
|
+
@staticmethod
|
|
234
|
+
def _cancel_requests(requests):
|
|
235
|
+
for future in tuple(requests):
|
|
236
|
+
future.cancel()
|
|
237
|
+
|
|
238
|
+
async def on_unmount(self):
|
|
239
|
+
self._cancel_requests(self._view_requests)
|
|
240
|
+
self._cancel_requests(self._media_requests)
|
|
241
|
+
if self._table is not None: # a failed compose must not hide its own error
|
|
242
|
+
await self._table.cancel_fill()
|
|
243
|
+
|
|
244
|
+
def message(self, value):
|
|
245
|
+
self._message_widget.update(clean(value))
|
|
246
|
+
|
|
247
|
+
def report(self, error):
|
|
248
|
+
failure("ui.failed", error)
|
|
249
|
+
self.message(str(error) if isinstance(error, AppError) else _("Could not complete: {label}. You can try again.", label=error_label(error)))
|
|
250
|
+
|
|
251
|
+
@work
|
|
252
|
+
async def refresh_library(self, initial=False, select=None):
|
|
253
|
+
if self._refreshing:
|
|
254
|
+
return
|
|
255
|
+
self._refreshing = True
|
|
256
|
+
try:
|
|
257
|
+
playlists = await self.api("playlists")
|
|
258
|
+
self.playlists = playlists
|
|
259
|
+
self.message(_("{count} playlists · Click Library to open another", count=len(playlists)))
|
|
260
|
+
if select is not None:
|
|
261
|
+
self.open_playlist(select)
|
|
262
|
+
elif initial and self.initial_playlist:
|
|
263
|
+
self.open_playlist(await self.api("playlist", self.initial_playlist))
|
|
264
|
+
elif initial and playlists:
|
|
265
|
+
self.open_playlist(playlists[0])
|
|
266
|
+
except Exception as error:
|
|
267
|
+
self.report(error)
|
|
268
|
+
finally:
|
|
269
|
+
self._refreshing = False
|
|
270
|
+
|
|
271
|
+
def action_library(self):
|
|
272
|
+
if not isinstance(self.screen, ModalScreen):
|
|
273
|
+
self.push_screen(LibraryScreen(self.playlists, self._writing), self.library_choice)
|
|
274
|
+
|
|
275
|
+
def library_choice(self, choice):
|
|
276
|
+
action, playlist = choice or (None, None)
|
|
277
|
+
if action == "open":
|
|
278
|
+
self.open_playlist(playlist)
|
|
279
|
+
elif action == "new":
|
|
280
|
+
self.action_new_playlist()
|
|
281
|
+
elif action == "refresh":
|
|
282
|
+
self.refresh_library()
|
|
283
|
+
|
|
284
|
+
def begin_view(self, heading):
|
|
285
|
+
self._cancel_requests(self._view_requests)
|
|
286
|
+
self._generation += 1
|
|
287
|
+
self._loading_more = False
|
|
288
|
+
self._loading_playlists = False
|
|
289
|
+
self._table.reset()
|
|
290
|
+
self._update_action_target()
|
|
291
|
+
self.query_one("#library", Button).label = Text(f"{clean(heading)[:26]} ▾")
|
|
292
|
+
self.hint(_("Loading…"))
|
|
293
|
+
self.query_one("#more", Button).display = False
|
|
294
|
+
self.query_one("#more", Button).disabled = False
|
|
295
|
+
self.query_one("#more-playlists", Button).disabled = False
|
|
296
|
+
self._views.active = "songs-view"
|
|
297
|
+
return self._generation
|
|
298
|
+
|
|
299
|
+
def open_playlist(self, playlist):
|
|
300
|
+
self.current_playlist = playlist
|
|
301
|
+
self.search_query = ""
|
|
302
|
+
self._views.hide_tab("playlists-view")
|
|
303
|
+
generation = self.begin_view(playlist.name)
|
|
304
|
+
self.call_after_refresh(self._table.focus)
|
|
305
|
+
self.load_tracks(playlist, generation)
|
|
306
|
+
|
|
307
|
+
@work
|
|
308
|
+
async def load_tracks(self, playlist, generation):
|
|
309
|
+
try:
|
|
310
|
+
tracks = await self.api("tracks", playlist)
|
|
311
|
+
if generation == self._generation:
|
|
312
|
+
self.show_tracks(tracks)
|
|
313
|
+
except Exception as error:
|
|
314
|
+
if generation == self._generation:
|
|
315
|
+
self.report(error)
|
|
316
|
+
self.hint(_("Could not load. Open it again to retry."))
|
|
317
|
+
|
|
318
|
+
def show_tracks(self, tracks, append=False):
|
|
319
|
+
self._table.show(tracks, append)
|
|
320
|
+
source = clean(self.current_playlist.name) if self.current_playlist else _("Search results")
|
|
321
|
+
self.hint(_("{source} · {count} songs", source=source[:30], count=len(self.tracks)) if self.tracks
|
|
322
|
+
else _("No songs. Search for music and add it to a playlist."))
|
|
323
|
+
self._update_action_target()
|
|
324
|
+
|
|
325
|
+
@on(Input.Submitted, "#search")
|
|
326
|
+
@on(Button.Pressed, "#search-button")
|
|
327
|
+
def search(self):
|
|
328
|
+
query = self.query_one("#search", Input).value.strip()
|
|
329
|
+
if query:
|
|
330
|
+
self.current_playlist = None
|
|
331
|
+
self.search_query = query
|
|
332
|
+
generation = self.begin_view(_("Results: {query}", query=query))
|
|
333
|
+
self.playlist_results = []
|
|
334
|
+
self.query_one("#playlist-results", ListView).clear()
|
|
335
|
+
self.query_one("#empty-results", Static).update(_("Loading…"))
|
|
336
|
+
self.query_one("#empty-results").display = True
|
|
337
|
+
self.query_one("#more-playlists", Button).display = False
|
|
338
|
+
self._views.show_tab("playlists-view")
|
|
339
|
+
self.search_page(query, generation, 0)
|
|
340
|
+
self.search_playlist_page(query, generation, 0)
|
|
341
|
+
|
|
342
|
+
@work
|
|
343
|
+
async def search_playlist_page(self, query, generation, offset):
|
|
344
|
+
self._loading_playlists = True
|
|
345
|
+
try:
|
|
346
|
+
playlists = await self.api("search_playlists", query, offset)
|
|
347
|
+
if generation != self._generation:
|
|
348
|
+
return
|
|
349
|
+
self.playlist_results.extend(playlists)
|
|
350
|
+
results = self.query_one("#playlist-results", ListView)
|
|
351
|
+
await results.extend(ListItem(Label(Text(clean(p.name)))) for p in playlists)
|
|
352
|
+
if generation != self._generation:
|
|
353
|
+
return
|
|
354
|
+
if self.playlist_results and results.index is None:
|
|
355
|
+
results.index = 0
|
|
356
|
+
self.query_one("#empty-results", Static).update(_("No playlists in this search."))
|
|
357
|
+
self.query_one("#empty-results").display = not self.playlist_results
|
|
358
|
+
self.query_one("#more-playlists", Button).display = len(playlists) == 50
|
|
359
|
+
except Exception as error:
|
|
360
|
+
if generation == self._generation:
|
|
361
|
+
self.report(error)
|
|
362
|
+
self.query_one("#empty-results", Static).update(_("Search failed. Press Search to retry."))
|
|
363
|
+
finally:
|
|
364
|
+
if generation == self._generation:
|
|
365
|
+
self._loading_playlists = False
|
|
366
|
+
self.query_one("#more-playlists", Button).disabled = False
|
|
367
|
+
|
|
368
|
+
@on(ListView.Selected, "#playlist-results")
|
|
369
|
+
def open_search_playlist(self, event):
|
|
370
|
+
index = event.list_view.index
|
|
371
|
+
if index is not None and 0 <= index < len(self.playlist_results):
|
|
372
|
+
self.open_playlist(self.playlist_results[index])
|
|
373
|
+
|
|
374
|
+
@work
|
|
375
|
+
async def search_page(self, query, generation, offset):
|
|
376
|
+
try:
|
|
377
|
+
tracks = await self.api("search", query, offset)
|
|
378
|
+
if generation == self._generation:
|
|
379
|
+
self.show_tracks(tracks, append=offset > 0)
|
|
380
|
+
self.query_one("#more", Button).display = len(tracks) == 50
|
|
381
|
+
except Exception as error:
|
|
382
|
+
if generation == self._generation:
|
|
383
|
+
self.report(error)
|
|
384
|
+
self.hint(_("Search failed. Press Search to retry."))
|
|
385
|
+
finally:
|
|
386
|
+
if generation == self._generation:
|
|
387
|
+
self._loading_more = False
|
|
388
|
+
self.query_one("#more", Button).disabled = False
|
|
389
|
+
|
|
390
|
+
def selected_track(self):
|
|
391
|
+
return self._table.selected()
|
|
392
|
+
|
|
393
|
+
def _update_action_target(self):
|
|
394
|
+
track = self.selected_track()
|
|
395
|
+
target = Text()
|
|
396
|
+
if track:
|
|
397
|
+
target.append(_("Selected "))
|
|
398
|
+
target.append(clean(track.name), style="bold")
|
|
399
|
+
target.append(f" · {artist(track)}")
|
|
400
|
+
else:
|
|
401
|
+
target.append(_("Select a song"))
|
|
402
|
+
self._action_target.update(target)
|
|
403
|
+
self.query_one("#track-add", Button).disabled = track is None or self._writing
|
|
404
|
+
self.query_one("#track-enqueue", Button).disabled = track is None
|
|
405
|
+
|
|
406
|
+
def control(self, action, value=None):
|
|
407
|
+
try:
|
|
408
|
+
self.playback.send(action, value)
|
|
409
|
+
except Exception as error:
|
|
410
|
+
self.report(error)
|
|
411
|
+
|
|
412
|
+
@on(TrackTable.RowSelected)
|
|
413
|
+
def play_selected(self):
|
|
414
|
+
self._update_action_target()
|
|
415
|
+
if self.selected_track() is not None:
|
|
416
|
+
self._source_name = (clean(self.current_playlist.name) if self.current_playlist else
|
|
417
|
+
_("Search results") if self.search_query else _("Queue"))
|
|
418
|
+
self.control("play", (tuple(self.tracks), self._table.cursor_row))
|
|
419
|
+
|
|
420
|
+
@on(TrackTable.RowHighlighted)
|
|
421
|
+
def selected_row_changed(self):
|
|
422
|
+
self._update_action_target()
|
|
423
|
+
|
|
424
|
+
def action_search(self):
|
|
425
|
+
if not isinstance(self.screen, ModalScreen):
|
|
426
|
+
self.query_one("#search", Input).focus()
|
|
427
|
+
|
|
428
|
+
def action_pause(self):
|
|
429
|
+
state = self.playback.snapshot()
|
|
430
|
+
if state.status in ("Playing", "Paused"):
|
|
431
|
+
self.control("pause")
|
|
432
|
+
elif self.selected_track() is not None:
|
|
433
|
+
self.play_selected()
|
|
434
|
+
|
|
435
|
+
def action_next(self):
|
|
436
|
+
self.control("next")
|
|
437
|
+
|
|
438
|
+
def action_next_theme(self):
|
|
439
|
+
themes = available_themes()
|
|
440
|
+
for custom_theme in CUSTOM_THEMES.values():
|
|
441
|
+
if custom_theme.name not in self.available_themes:
|
|
442
|
+
self.register_theme(custom_theme)
|
|
443
|
+
self.theme = themes[(themes.index(self.theme) + 1) % len(themes)] if self.theme in themes else themes[0]
|
|
444
|
+
self.message(_("Theme: {name} · Ctrl+T to change", name=self.theme))
|
|
445
|
+
if self.on_theme is not None:
|
|
446
|
+
try:
|
|
447
|
+
self.on_theme(self.theme)
|
|
448
|
+
except OSError as error:
|
|
449
|
+
failure("settings.failed", error)
|
|
450
|
+
|
|
451
|
+
@on(Visualizer.Clicked)
|
|
452
|
+
def action_next_visualizer(self):
|
|
453
|
+
modes = available_visualizer_modes()
|
|
454
|
+
self.visualizer_mode = (modes[(modes.index(self.visualizer_mode) + 1) % len(modes)]
|
|
455
|
+
if self.visualizer_mode in modes else modes[0])
|
|
456
|
+
self.query_one(Visualizer).set_mode(self.visualizer_mode)
|
|
457
|
+
label = MODE_LABELS.get(self.visualizer_mode)
|
|
458
|
+
self.message(_("Track aura: {name} · Ctrl+G to change",
|
|
459
|
+
name=_(label) if label else self.visualizer_mode))
|
|
460
|
+
if self.on_visualizer_mode is not None:
|
|
461
|
+
try:
|
|
462
|
+
self.on_visualizer_mode(self.visualizer_mode)
|
|
463
|
+
except OSError as error:
|
|
464
|
+
failure("settings.failed", error)
|
|
465
|
+
|
|
466
|
+
@on(LyricsPanel.CoverClicked)
|
|
467
|
+
def action_toggle_lyrics_layout(self):
|
|
468
|
+
self.lyrics_layout = "cover" if self.lyrics_layout == "lyrics" else "lyrics"
|
|
469
|
+
self._lyrics.set_layout(self.lyrics_layout)
|
|
470
|
+
self.message(_("Lyrics tab: cover only · Ctrl+O to change") if self.lyrics_layout == "cover"
|
|
471
|
+
else _("Lyrics tab: cover and lyrics · Ctrl+O to change"))
|
|
472
|
+
if self.on_lyrics_layout is not None:
|
|
473
|
+
try:
|
|
474
|
+
self.on_lyrics_layout(self.lyrics_layout)
|
|
475
|
+
except OSError as error:
|
|
476
|
+
failure("settings.failed", error)
|
|
477
|
+
|
|
478
|
+
def action_new_playlist(self):
|
|
479
|
+
if not self._writing:
|
|
480
|
+
self.push_screen(CreatePlaylist(), self.create_playlist)
|
|
481
|
+
|
|
482
|
+
@work
|
|
483
|
+
async def create_playlist(self, title):
|
|
484
|
+
if title is None or self._writing:
|
|
485
|
+
return
|
|
486
|
+
self._writing = True
|
|
487
|
+
self._update_action_target()
|
|
488
|
+
try:
|
|
489
|
+
playlist = await self.api("create", title)
|
|
490
|
+
self.message(_("Playlist created in your TIDAL account."))
|
|
491
|
+
self.refresh_library(select=playlist)
|
|
492
|
+
except Exception as error:
|
|
493
|
+
self.report(error)
|
|
494
|
+
self.message(_("The creation was not confirmed. Refresh the library before retrying."))
|
|
495
|
+
finally:
|
|
496
|
+
self._writing = False
|
|
497
|
+
self._update_action_target()
|
|
498
|
+
|
|
499
|
+
@work
|
|
500
|
+
async def add_track(self, track):
|
|
501
|
+
if self._writing:
|
|
502
|
+
return
|
|
503
|
+
self._writing = True
|
|
504
|
+
self._update_action_target()
|
|
505
|
+
try:
|
|
506
|
+
own = [p for p in self.playlists if self.library.catalog.editable(p)]
|
|
507
|
+
if not own:
|
|
508
|
+
self.message(_("First create a playlist of your own from Library."))
|
|
509
|
+
return
|
|
510
|
+
playlist = await self.push_screen_wait(ChoosePlaylist(own))
|
|
511
|
+
if playlist is not None:
|
|
512
|
+
result = await self.api("add", playlist, track)
|
|
513
|
+
self.message(_("Song added.") if result else _("No changes: the song is already there or unavailable."))
|
|
514
|
+
if self.current_playlist and str(self.current_playlist.id) == str(playlist.id):
|
|
515
|
+
self.open_playlist(playlist)
|
|
516
|
+
except Exception as error:
|
|
517
|
+
self.report(error)
|
|
518
|
+
finally:
|
|
519
|
+
self._writing = False
|
|
520
|
+
self._update_action_target()
|
|
521
|
+
|
|
522
|
+
@on(Button.Pressed)
|
|
523
|
+
def button(self, event):
|
|
524
|
+
# Player controls are handled by PlayerBar and never reach here.
|
|
525
|
+
identifier = event.button.id
|
|
526
|
+
if identifier == "library":
|
|
527
|
+
self.action_library()
|
|
528
|
+
elif identifier == "more-playlists" and not self._loading_playlists:
|
|
529
|
+
event.button.disabled = True
|
|
530
|
+
self.search_playlist_page(self.search_query, self._generation, len(self.playlist_results))
|
|
531
|
+
elif identifier == "more" and not self._loading_more:
|
|
532
|
+
self._loading_more = True
|
|
533
|
+
event.button.disabled = True
|
|
534
|
+
self.search_page(self.search_query, self._generation, len(self.tracks))
|
|
535
|
+
elif identifier == "track-add":
|
|
536
|
+
track = self.selected_track()
|
|
537
|
+
if track is not None:
|
|
538
|
+
self.add_track(track)
|
|
539
|
+
elif identifier == "track-enqueue":
|
|
540
|
+
track = self.selected_track()
|
|
541
|
+
if track is not None:
|
|
542
|
+
self.control("enqueue", track)
|
|
543
|
+
self.message(_("Song added to the end of the queue."))
|
|
544
|
+
|
|
545
|
+
def update_player(self):
|
|
546
|
+
state = self.playback.snapshot()
|
|
547
|
+
track = None
|
|
548
|
+
if 0 <= state.index < len(state.tracks):
|
|
549
|
+
track = state.tracks[state.index]
|
|
550
|
+
track_id = getattr(track, "id", None)
|
|
551
|
+
if track_id != self._current_track_id:
|
|
552
|
+
self._cancel_requests(self._media_requests)
|
|
553
|
+
self._current_track_id = track_id
|
|
554
|
+
self._table.set_current(track_id)
|
|
555
|
+
self._media_generation += 1
|
|
556
|
+
self._lyrics.reset(playing=track is not None)
|
|
557
|
+
self.covers.show()
|
|
558
|
+
if track:
|
|
559
|
+
self.load_media(track, self._media_generation)
|
|
560
|
+
self._player.show(state, track, self._source_name)
|
|
561
|
+
queue_signature = (id(state.tracks), state.index)
|
|
562
|
+
if queue_signature != self._queue_signature:
|
|
563
|
+
self._queue_signature = queue_signature
|
|
564
|
+
next_tracks = state.tracks[max(0, state.index + 1):]
|
|
565
|
+
self._views.get_tab("queue-view").label = _("Queue · {count}", count=len(next_tracks)) if next_tracks else _("Queue")
|
|
566
|
+
self.call_after_refresh(self._place_hint)
|
|
567
|
+
self._queue.show(next_tracks)
|
|
568
|
+
self._lyrics.follow(state.position)
|
|
569
|
+
self._changes.show(self._mode, playback_mode(state), layout=True) # auto width
|
|
570
|
+
self._quality.show(state.audio, track)
|
|
571
|
+
if state.error and state.error != self._last_error:
|
|
572
|
+
self.message(state.error)
|
|
573
|
+
self._last_error = state.error
|
|
574
|
+
|
|
575
|
+
@work(group="media", exclusive=True)
|
|
576
|
+
async def load_media(self, track, generation):
|
|
577
|
+
if generation != self._media_generation:
|
|
578
|
+
return
|
|
579
|
+
# Queue artwork metadata before lyrics, then download independently.
|
|
580
|
+
await asyncio.gather(self._load_cover(track, generation), self._load_lyrics(track, generation))
|
|
581
|
+
|
|
582
|
+
async def _load_lyrics(self, track, generation):
|
|
583
|
+
try:
|
|
584
|
+
plain, subtitles, rtl = await self.api("lyrics", track)
|
|
585
|
+
if generation == self._media_generation:
|
|
586
|
+
self._lyrics.load(plain, subtitles, self.playback.snapshot().position)
|
|
587
|
+
except Exception as error:
|
|
588
|
+
if generation == self._media_generation:
|
|
589
|
+
failure("lyrics.unavailable", error)
|
|
590
|
+
self._lyrics.unavailable()
|
|
591
|
+
|
|
592
|
+
async def _load_cover(self, track, generation):
|
|
593
|
+
if generation != self._media_generation:
|
|
594
|
+
return
|
|
595
|
+
try:
|
|
596
|
+
art = await self.api("artwork", track)
|
|
597
|
+
if generation == self._media_generation:
|
|
598
|
+
self.covers.show(art)
|
|
599
|
+
except Exception as error:
|
|
600
|
+
if generation == self._media_generation:
|
|
601
|
+
failure("cover.unavailable", error)
|