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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
|
# tidal_dl_ng/gui_playlist.py
from typing import TYPE_CHECKING, Any
from PySide6 import QtCore, QtWidgets
from tidalapi import Album, Artist, Mix, Playlist, Track, UserPlaylist
from tidalapi.playlist import Folder
from tidal_dl_ng.constants import FAVORITES, TidalLists
from tidal_dl_ng.helper.gui import get_user_list_media_item, set_user_list_media
from tidal_dl_ng.helper.tidal import (
favorite_function_factory,
items_results_all,
user_media_lists,
)
from tidal_dl_ng.logger import logger_gui
from tidal_dl_ng.model.gui_data import QueueDownloadItem, ResultItem, StatusbarMessage
if TYPE_CHECKING:
from tidal_dl_ng.gui import MainWindow
class GuiPlaylistManager:
"""Manages the playlist, mixes, and favorites GUI and logic."""
def __init__(self, main_window: "MainWindow"):
"""Initialize the playlist manager."""
self.main_window: "MainWindow" = main_window
self.settings = main_window.settings
def init_ui(self):
"""Initialize UI elements related to playlists."""
self._init_tree_lists(self.main_window.tr_lists_user)
def connect_signals(self):
"""Connect signals for playlist-related widgets."""
self.main_window.pb_reload_user_lists.clicked.connect(lambda: self.main_window.thread_it(self.tidal_user_lists))
self.main_window.tr_lists_user.itemClicked.connect(self.on_list_items_show)
self.main_window.tr_lists_user.itemExpanded.connect(self.on_tr_lists_user_expanded)
self.main_window.tr_lists_user.customContextMenuRequested.connect(self.menu_context_tree_lists)
self.main_window.s_populate_tree_lists.connect(self.on_populate_tree_lists)
self.main_window.s_populate_folder_children.connect(self.on_populate_folder_children)
def _init_tree_lists(self, tree: QtWidgets.QTreeWidget) -> None:
"""Initialize the user lists tree widget."""
tree.setColumnWidth(0, 200)
tree.setColumnHidden(1, True)
tree.setColumnWidth(2, 300)
tree.expandAll()
tree.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
def tidal_user_lists(self) -> None:
"""Fetch and emit user playlists, mixes, and favorites from Tidal."""
self.main_window.s_spinner_start.emit(self.main_window.tr_lists_user)
self.main_window.s_pb_reload_status.emit(False)
user_all = user_media_lists(self.main_window.tidal.session)
self.main_window.s_populate_tree_lists.emit(user_all)
def on_populate_tree_lists(self, user_lists: dict[str, list]) -> None:
"""Populate the user lists tree with playlists, mixes, and favorites."""
twi_playlists = self.main_window.tr_lists_user.findItems(TidalLists.Playlists, QtCore.Qt.MatchExactly, 0)[0]
twi_mixes = self.main_window.tr_lists_user.findItems(TidalLists.Mixes, QtCore.Qt.MatchExactly, 0)[0]
twi_favorites = self.main_window.tr_lists_user.findItems(TidalLists.Favorites, QtCore.Qt.MatchExactly, 0)[0]
for twi in [twi_playlists, twi_mixes, twi_favorites]:
for i in reversed(range(twi.childCount())):
twi.removeChild(twi.child(i))
for item in user_lists.get("playlists", []):
if isinstance(item, Folder):
twi_child = QtWidgets.QTreeWidgetItem(twi_playlists)
twi_child.setText(0, f"📁 {item.name}")
set_user_list_media(twi_child, item)
info = f"({item.total_number_of_items} items)" if item.total_number_of_items else ""
twi_child.setText(2, info)
dummy_child = QtWidgets.QTreeWidgetItem(twi_child)
dummy_child.setDisabled(True)
elif isinstance(item, UserPlaylist | Playlist):
twi_child = QtWidgets.QTreeWidgetItem(twi_playlists)
name = item.name or ""
description = f" {item.description}" if item.description else ""
info = f"({item.num_tracks + item.num_videos} Tracks){description}"
twi_child.setText(0, name)
set_user_list_media(twi_child, item)
twi_child.setText(2, info)
for item in user_lists.get("mixes", []):
if isinstance(item, Mix):
twi_child = QtWidgets.QTreeWidgetItem(twi_mixes)
twi_child.setText(0, item.title)
set_user_list_media(twi_child, item)
twi_child.setText(2, item.sub_title)
for key, favorite in FAVORITES.items():
twi_child = QtWidgets.QTreeWidgetItem(twi_favorites)
twi_child.setText(0, favorite["name"])
set_user_list_media(twi_child, key)
self.main_window.s_spinner_stop.emit()
self.main_window.s_pb_reload_status.emit(True)
def menu_context_tree_lists(self, point: QtCore.QPoint) -> None:
"""Show context menu for user lists tree.
Args:
point (QPoint): The point where the menu is requested.
"""
# Infos about the node selected.
index = self.main_window.tr_lists_user.indexAt(point)
# Do not open menu if something went wrong or a parent node is clicked.
if not index.isValid() or not index.parent().data():
return
# Get the media item to determine type
item = self.main_window.tr_lists_user.itemAt(point)
media = get_user_list_media_item(item)
# We build the menu.
menu = QtWidgets.QMenu()
if isinstance(media, Folder):
# Folder-specific menu items
menu.addAction(
"Download All Playlists in Folder",
lambda: self.main_window.thread_it(self.on_download_folder_playlists, point),
)
menu.addAction(
"Download All Albums from Folder",
lambda: self.main_window.thread_it(self.on_download_folder_albums, point),
)
elif isinstance(media, str):
# Favorites items (stored as string keys like "fav_tracks", "fav_albums")
menu.addAction("Download All Items", lambda: self.main_window.thread_it(self.on_download_favorites, point))
menu.addAction(
"Download All Albums from Items",
lambda: self.main_window.thread_it(self.on_download_albums_from_favorites, point),
)
else:
# Playlist/Mix menu items (existing)
menu.addAction("Download Playlist", lambda: self.main_window.thread_download_list_media(point))
menu.addAction(
"Download All Albums in Playlist",
lambda: self.main_window.thread_it(self.on_download_all_albums_from_playlist, point),
)
menu.addAction(
"Copy Share URL", lambda: self.main_window.on_copy_url_share(self.main_window.tr_lists_user, point)
)
menu.exec(self.main_window.tr_lists_user.mapToGlobal(point))
def on_download_list_media(self, point: QtCore.QPoint | None = None) -> None:
"""Download all media items in a selected list.
Args:
point (QPoint | None, optional): The point in the tree. Defaults to None.
"""
items: list[QtWidgets.QTreeWidgetItem] = []
if point:
items = [self.main_window.tr_lists_user.itemAt(point)]
else:
items = self.main_window.tr_lists_user.selectedItems()
if len(items) == 0:
logger_gui.error("Please select a mix or playlist first.")
for item in items:
media = get_user_list_media_item(item)
queue_dl_item: QueueDownloadItem | None = self.main_window.search_manager.media_to_queue_download_model(
media
)
if queue_dl_item:
self.main_window.queue_download_media(queue_dl_item)
def on_download_folder_playlists(self, point: QtCore.QPoint) -> None:
"""Download all playlists in a folder.
Args:
point (QPoint): The point in the tree where the folder was right-clicked.
"""
try:
# Get and validate the folder
item = self.main_window.tr_lists_user.itemAt(point)
media = get_user_list_media_item(item)
if not isinstance(media, Folder):
logger_gui.error("Please select a folder.")
return
# Fetch all playlists in the folder
logger_gui.info(f"Fetching playlists from folder: {media.name}")
playlists = self._get_folder_playlists(media)
if not playlists:
logger_gui.info(f"No playlists found in folder: {media.name}")
return
# Queue each playlist for download
logger_gui.info(f"Queueing {len(playlists)} playlists from folder: {media.name}")
for playlist in playlists:
queue_dl_item: QueueDownloadItem | None = self.main_window.search_manager.media_to_queue_download_model(
playlist
)
if queue_dl_item:
self.main_window.queue_download_media(queue_dl_item)
logger_gui.info(f"✅ Successfully queued {len(playlists)} playlists from folder: {media.name}")
except Exception as e:
logger_gui.exception(f"Error downloading playlists from folder: {e}")
logger_gui.error("Failed to download playlists from folder. See log for details.")
def on_download_folder_albums(self, point: QtCore.QPoint) -> None:
"""Download all unique albums from all playlists in a folder.
Args:
point (QPoint): The point in the tree where the folder was right-clicked.
"""
try:
# Get and validate the folder
item = self.main_window.tr_lists_user.itemAt(point)
media = get_user_list_media_item(item)
if not isinstance(media, Folder):
logger_gui.error("Please select a folder.")
return
# Fetch all playlists in the folder
logger_gui.info(f"Fetching playlists from folder: {media.name}")
playlists = self._get_folder_playlists(media)
if not playlists:
logger_gui.info(f"No playlists found in folder: {media.name}")
return
logger_gui.info(f"Found {len(playlists)} playlists in folder: {media.name}")
# Collect all tracks from all playlists
all_tracks: list[Track] = []
for playlist in playlists:
try:
tracks = self._get_playlist_tracks(playlist)
all_tracks.extend(tracks)
logger_gui.debug(f"Collected {len(tracks)} tracks from playlist: {playlist.name}")
except Exception as e:
logger_gui.error(f"Error getting tracks from playlist '{playlist.name}': {e}")
continue
if not all_tracks:
logger_gui.info(f"No tracks found in folder playlists: {media.name}")
return
logger_gui.info(f"Collected {len(all_tracks)} total tracks from all playlists")
# Extract unique album IDs
album_ids = self.main_window._extract_album_ids_from_tracks(all_tracks)
logger_gui.info(f"Found {len(album_ids)} unique albums across all playlists in folder: {media.name}")
if not album_ids:
logger_gui.info("No albums found to download.")
return
# Load full album objects with rate limiting
albums_dict = self.main_window._load_albums_with_rate_limiting(album_ids)
if not albums_dict:
logger_gui.error("Failed to load any albums.")
return
# Queue the albums for download
self.main_window._queue_loaded_albums(albums_dict)
logger_gui.info(f"✅ Successfully queued {len(albums_dict)} unique albums from folder: {media.name}")
except Exception as e:
logger_gui.exception(f"Error downloading albums from folder: {e}")
logger_gui.error("Failed to download albums from folder. See log for details.")
def on_download_favorites(self, point: QtCore.QPoint) -> None:
"""Download all items from a Favorites category.
Args:
point (QPoint): The point in the tree where the favorites item was right-clicked.
"""
try:
# Get and validate the favorites item
item = self.main_window.tr_lists_user.itemAt(point)
media = get_user_list_media_item(item)
if not isinstance(media, str):
logger_gui.error("Please select a favorites category.")
return
# Get the favorites category name for logging
favorite_name = FAVORITES.get(media, {}).get("name", media)
logger_gui.info(f"Fetching all items from favorites: {favorite_name}")
# Use the factory to get the appropriate favorites function
favorite_function = favorite_function_factory(self.main_window.tidal, media)
# Fetch all items from this favorites category
media_items = favorite_function()
if not media_items:
logger_gui.info(f"No items found in favorites: {favorite_name}")
return
logger_gui.info(f"Found {len(media_items)} items in favorites: {favorite_name}")
# Queue each item for download
queued_count = 0
for media_item in media_items:
queue_dl_item: QueueDownloadItem | None = self.main_window.search_manager.media_to_queue_download_model(
media_item
)
if queue_dl_item:
self.main_window.queue_download_media(queue_dl_item)
queued_count += 1
logger_gui.info(f"✅ Successfully queued {queued_count} items from favorites: {favorite_name}")
except Exception as e:
logger_gui.exception(f"Error downloading favorites: {e}")
logger_gui.error("Failed to download favorites. See log for details.")
def _download_albums_from_fav_artists(self, media_items: list) -> None:
"""Download all albums from favorite artists."""
all_albums = {}
for artist in media_items:
try:
artist_albums = items_results_all(self.main_window.tidal.session, artist)
for album in artist_albums:
if isinstance(album, Album) and album.id:
all_albums[album.id] = album
except Exception as e:
logger_gui.error(f"Error getting albums from artist '{artist.name}': {e}")
if all_albums:
self.main_window._queue_loaded_albums(all_albums)
def _download_albums_from_fav_tracks(self, media_items: list) -> None:
"""Download all albums from favorite tracks."""
album_ids = self.main_window._extract_album_ids_from_tracks(media_items)
if album_ids:
albums_dict = self.main_window._load_albums_with_rate_limiting(album_ids)
if albums_dict:
self.main_window._queue_loaded_albums(albums_dict)
def on_download_albums_from_favorites(self, point: QtCore.QPoint) -> None:
"""Download all unique albums from items in a Favorites category.
Args:
point (QPoint): The point in the tree where the favorites item was right-clicked.
"""
try:
# Get and validate the favorites item
item = self.main_window.tr_lists_user.itemAt(point)
media = get_user_list_media_item(item)
if not isinstance(media, str):
logger_gui.error("Please select a favorites category.")
return
# Get the favorites category name for logging
favorite_name = FAVORITES.get(media, {}).get("name", media)
logger_gui.info(f"Fetching all items from favorites: {favorite_name}")
# Use the factory to get the appropriate favorites function
favorite_function = favorite_function_factory(self.main_window.tidal, media)
# Fetch all items from this favorites category
media_items = favorite_function()
if not media_items:
logger_gui.info(f"No items found in favorites: {favorite_name}")
return
logger_gui.info(f"Found {len(media_items)} items in favorites: {favorite_name}")
# Delegate to appropriate handler based on favorites type
if media == "fav_albums":
self._download_albums_from_favorites_albums(media_items, favorite_name)
elif media == "fav_artists":
self._download_albums_from_favorites_artists(media_items, favorite_name)
else:
self._download_albums_from_favorites_tracks(media_items, favorite_name)
except Exception as e:
logger_gui.exception(f"Error downloading albums from favorites: {e}")
logger_gui.error("Failed to download albums from favorites. See log for details.")
def on_download_all_albums_from_playlist(self, point: QtCore.QPoint) -> None:
"""Download all unique albums from tracks in a playlist."""
item = self.main_window.tr_lists_user.itemAt(point)
media_list = get_user_list_media_item(item)
if not isinstance(media_list, Playlist | UserPlaylist | Mix):
logger_gui.error("Please select a playlist or mix.")
return
media_items = items_results_all(self.main_window.tidal.session, media_list)
album_ids = self.main_window._extract_album_ids_from_tracks(media_items)
if not album_ids:
logger_gui.warning("No albums found in this playlist.")
return
albums_dict = self.main_window._load_albums_with_rate_limiting(album_ids)
if not albums_dict:
logger_gui.error("Failed to load any albums from playlist.")
return
self.main_window._queue_loaded_albums(albums_dict)
message = f"Added {len(albums_dict)} albums to download queue"
self.main_window.s_statusbar_message.emit(StatusbarMessage(message=message, timeout=3000))
def on_tr_lists_user_expanded(self, item: QtWidgets.QTreeWidgetItem) -> None:
"""Handle expansion of folders in the user lists tree.
Args:
item (QTreeWidgetItem): The expanded tree item.
"""
# Check if it's a first-time expansion (has disabled dummy child)
if item.childCount() > 0 and item.child(0).isDisabled():
# Run in thread to avoid blocking UI
self.main_window.thread_it(self.tr_lists_user_load_folder_children, item)
def tr_lists_user_load_folder_children(self, parent_item: QtWidgets.QTreeWidgetItem) -> None:
"""Load and display children of a folder in the user lists tree.
Args:
parent_item (QTreeWidgetItem): The parent folder item.
"""
folder: Folder | None = get_user_list_media_item(parent_item)
if not isinstance(folder, Folder):
return
# Show spinner while loading
self.main_window.s_spinner_start.emit(self.main_window.tr_lists_user)
try:
# Fetch folder contents
folders, playlists = self._fetch_folder_contents(folder)
# Emit signal to populate in main thread
self.main_window.s_populate_folder_children.emit(parent_item, folders, playlists)
finally:
self.main_window.s_spinner_stop.emit()
def on_populate_folder_children(
self, parent_item: QtWidgets.QTreeWidgetItem, folders: list[Folder], playlists: list[Playlist]
) -> None:
"""Populate folder children in the main thread (signal handler).
Args:
parent_item (QTreeWidgetItem): The parent folder item.
folders (list[Folder]): List of sub-folders.
playlists (list[Playlist]): List of playlists.
"""
# Remove dummy child
parent_item.takeChild(0)
# Add sub-folders as children
for sub_folder in folders:
twi_child = QtWidgets.QTreeWidgetItem(parent_item)
twi_child.setText(0, f"📁 {sub_folder.name}")
set_user_list_media(twi_child, sub_folder)
info = f"({sub_folder.total_number_of_items} items)" if sub_folder.total_number_of_items else ""
twi_child.setText(2, info)
# Add dummy child for potential sub-folders
dummy = QtWidgets.QTreeWidgetItem(twi_child)
dummy.setDisabled(True)
# Add playlists as children
for playlist in playlists:
twi_child = QtWidgets.QTreeWidgetItem(parent_item)
name = playlist.name if playlist.name else ""
twi_child.setText(0, name)
set_user_list_media(twi_child, playlist)
info = f"({playlist.num_tracks + playlist.num_videos} Tracks)"
if playlist.description:
info += f" {playlist.description}"
twi_child.setText(2, info)
def _fetch_folder_contents(self, folder: Folder) -> tuple[list[Folder], list[Playlist]]:
"""Fetch contents (sub-folders and playlists) of a folder.
Args:
folder (Folder): The folder to fetch contents for.
Returns:
tuple[list[Folder], list[Playlist]]: Sub-folders and playlists within the folder.
"""
folder_id = folder.id if folder.id else "root"
# Fetch sub-folders with manual pagination
offset = 0
limit = 50
folders = []
while True:
batch = self.main_window.tidal.session.user.favorites.playlist_folders(
limit=limit, offset=offset, parent_folder_id=folder_id
)
if not batch:
break
folders.extend(batch)
if len(batch) < limit:
break
offset += limit
# Fetch playlists in this folder using folder.items() method
offset = 0
playlists = []
while True:
batch = folder.items(offset=offset, limit=limit)
if not batch:
break
playlists.extend(batch)
if len(batch) < limit:
break
offset += limit
return folders, playlists
def _get_folder_playlists(self, folder: Folder) -> list[Playlist]:
"""Fetch all playlists from a folder.
Args:
folder (Folder): The folder to fetch playlists from.
Returns:
list[Playlist]: List of playlists in the folder.
"""
# Use existing method to fetch folder contents
# Since folders can't contain folders, we ignore the folders return value
_, playlists = self._fetch_folder_contents(folder)
logger_gui.debug(f"Found {len(playlists)} playlists in folder: {folder.name}")
return playlists
def _get_playlist_tracks(self, playlist: Playlist | UserPlaylist | Mix) -> list[Track]:
"""Fetch all tracks from a playlist.
Args:
playlist (Playlist | UserPlaylist | Mix): The playlist to fetch tracks from.
Returns:
list[Track]: List of tracks in the playlist.
"""
playlist_name = getattr(playlist, "name", "unknown")
logger_gui.debug(f"Fetching tracks from playlist: {playlist_name}")
media_items = items_results_all(self.main_window.tidal.session, playlist)
# Filter for Track objects only (items_results_all may return Videos too)
tracks = [item for item in media_items if isinstance(item, Track)]
logger_gui.debug(f"Found {len(tracks)} tracks in playlist: {playlist_name}")
return tracks
def on_list_items_show(self, item: QtWidgets.QTreeWidgetItem) -> None:
"""Show the items in the selected playlist or mix.
Args:
item (QtWidgets.QTreeWidgetItem): The selected tree widget item.
"""
self.main_window.thread_it(self.list_items_show, item)
def list_items_show(self, item: QtWidgets.QTreeWidgetItem) -> None:
"""Fetch and display the items in a playlist, mix, or folder.
Args:
item (QtWidgets.QTreeWidgetItem): The tree widget item representing a playlist, mix, or folder.
"""
media_list: Album | Playlist | Folder | str = get_user_list_media_item(item)
# Only if clicked item is not a top level item.
if media_list:
# Show spinner while loading list
self.main_window.s_spinner_start.emit(self.main_window.tr_results)
try:
if isinstance(media_list, Folder):
# Show folder contents
self._show_folder_contents(media_list)
elif isinstance(media_list, str) and media_list.startswith("fav_"):
function_list = favorite_function_factory(self.main_window.tidal, media_list)
self.main_window.list_items_show_result(favorite_function=function_list)
else:
self.main_window.list_items_show_result(media_list)
# Load cover asynchronously to avoid blocking the GUI
if hasattr(self.main_window, "cover_manager"):
self.main_window.cover_manager.load_cover(media_list)
finally:
self.main_window.s_spinner_stop.emit()
def _show_folder_contents(self, folder: Folder) -> None:
"""Display folder contents (nested playlists/folders) in results pane.
Args:
folder (Folder): The folder to display contents for.
"""
# Fetch folder contents using the shared helper method
folders, playlists = self._fetch_folder_contents(folder)
# Combine folders and playlists
items = folders + playlists
# Convert to ResultItems and display
result = self.main_window.search_manager.search_result_to_model(items)
self.main_window.populate_tree_results(result)
def _download_albums_from_favorites_albums(self, media_items: list, favorite_name: str) -> None:
"""Download albums from favorite albums list.
Args:
media_items (list): List of favorite albums.
favorite_name (str): Name of the favorites category for logging.
"""
logger_gui.info(f"Queueing {len(media_items)} albums from favorites: {favorite_name}")
albums_dict = {album.id: album for album in media_items if isinstance(album, Album) and album.id}
self.main_window._queue_loaded_albums(albums_dict)
logger_gui.info(f"✅ Successfully queued {len(albums_dict)} albums from favorites: {favorite_name}")
def _download_albums_from_favorites_artists(self, media_items: list, favorite_name: str) -> None:
"""Download albums from favorite artists list.
Args:
media_items (list): List of favorite artists.
favorite_name (str): Name of the favorites category for logging.
"""
logger_gui.info(f"Fetching albums from {len(media_items)} artists...")
all_albums = {}
for artist in media_items:
if isinstance(artist, Artist):
try:
artist_albums = items_results_all(self.main_window.tidal.session, artist)
for album in artist_albums:
if isinstance(album, Album) and album.id:
all_albums[album.id] = album
logger_gui.debug(f"Found {len(artist_albums)} albums from artist: {artist.name}")
except Exception as e:
logger_gui.error(f"Error getting albums from artist '{artist.name}': {e}")
continue
if not all_albums:
logger_gui.info("No albums found from favorite artists.")
return
logger_gui.info(f"Found {len(all_albums)} unique albums from favorite artists")
self.main_window._queue_loaded_albums(all_albums)
logger_gui.info(f"✅ Successfully queued {len(all_albums)} albums from favorites: {favorite_name}")
def _download_albums_from_favorites_tracks(self, media_items: list, favorite_name: str) -> None:
"""Download albums from favorite tracks/videos/mixes list.
Args:
media_items (list): List of favorite tracks/videos/mixes.
favorite_name (str): Name of the favorites category for logging.
"""
logger_gui.info("Extracting albums from tracks...")
album_ids = self.main_window._extract_album_ids_from_tracks(media_items)
if not album_ids:
logger_gui.info(f"No albums found in favorites: {favorite_name}")
return
logger_gui.info(f"Found {len(album_ids)} unique albums. Loading with rate limiting...")
# Load full album objects with rate limiting
albums_dict = self.main_window._load_albums_with_rate_limiting(album_ids)
if not albums_dict:
logger_gui.error("Failed to load any albums from favorites.")
return
# Queue the albums for download
self.main_window._queue_loaded_albums(albums_dict)
logger_gui.info(f"✅ Successfully queued {len(albums_dict)} unique albums from favorites: {favorite_name}")
def search_populate_results(self, query: str, type_media: Any) -> None:
"""Populate the results tree with search results.
Args:
query (str): The search query.
type_media (SearchTypes): The type of media to search for.
"""
results: list[ResultItem] = self.main_window.search_manager.search(query, [type_media])
self.main_window.populate_tree_results(results)
|