30
30
import coloredlogs .converter
31
31
from rich .progress import Progress
32
32
from tidalapi import Album , Mix , Playlist , Quality , Track , UserPlaylist , Video
33
+ from tidalapi .artist import Artist
33
34
from tidalapi .session import SearchTypes
34
35
35
36
from tidal_dl_ng .config import Settings , Tidal
@@ -178,10 +179,10 @@ def _populate_quality(self, ui_target: QtWidgets.QComboBox, options: type[Qualit
178
179
179
180
def _populate_search_types (self , ui_target : QtWidgets .QComboBox , options : SearchTypes ):
180
181
for item in options :
181
- if item and item . __name__ != "Artist" :
182
+ if item :
182
183
ui_target .addItem (item .__name__ , item )
183
184
184
- self .cb_search_type .setCurrentIndex (1 )
185
+ self .cb_search_type .setCurrentIndex (2 )
185
186
186
187
def _init_tree_results (self , tree : QtWidgets .QTableWidget ):
187
188
tree .setColumnHidden (5 , True )
@@ -321,10 +322,14 @@ def populate_tree_results(self, results: [ResultItem], parent: QtWidgets.QTreeWi
321
322
self .s_tr_results_add_top_level_item .emit (child )
322
323
323
324
def populate_tree_result_child (self , item : [Track | Video | Mix | Album | Playlist ], index_count_digits : int ):
325
+ duration : str = ""
326
+
324
327
# TODO: Duration needs to be calculated later to properly fill with zeros.
325
- # Format seconds to mm:ss.
326
- m , s = divmod (item .duration_sec , 60 )
327
- duration : str = f"{ m :02d} :{ s :02d} "
328
+ if item .duration_sec > - 1 :
329
+ # Format seconds to mm:ss.
330
+ m , s = divmod (item .duration_sec , 60 )
331
+ duration : str = f"{ m :02d} :{ s :02d} "
332
+
328
333
# Since sorting happens only by string, we need to pad the index and add 1 (to avoid start at 0)
329
334
index : str = str (item .position + 1 ).zfill (index_count_digits )
330
335
@@ -337,7 +342,7 @@ def populate_tree_result_child(self, item: [Track | Video | Mix | Album | Playli
337
342
child .setText (4 , duration )
338
343
child .setData (5 , QtCore .Qt .ItemDataRole .UserRole , item .obj )
339
344
340
- if isinstance (item .obj , Mix | Playlist | Album ):
345
+ if isinstance (item .obj , Mix | Playlist | Album | Artist ):
341
346
# Add a disabled dummy child, so expansion arrow will appear. This Child will be replaced on expansion.
342
347
child_dummy : QtWidgets .QTreeWidgetItem = QtWidgets .QTreeWidgetItem ()
343
348
@@ -442,6 +447,17 @@ def search_result_to_model(self, items: [*SearchTypes]) -> [ResultItem]:
442
447
obj = item ,
443
448
)
444
449
450
+ result .append (result_item )
451
+ elif isinstance (item , Artist ):
452
+ result_item : ResultItem = ResultItem (
453
+ position = idx ,
454
+ artist = item .name ,
455
+ title = "" ,
456
+ album = "" ,
457
+ duration_sec = - 1 ,
458
+ obj = item ,
459
+ )
460
+
445
461
result .append (result_item )
446
462
447
463
return result
@@ -521,7 +537,7 @@ def on_list_items_show(self, item: QtWidgets.QTreeWidgetItem):
521
537
522
538
def list_items_show_result (
523
539
self ,
524
- media_list : Album | Playlist | Mix | None = None ,
540
+ media_list : Album | Playlist | Mix | Artist | None = None ,
525
541
point : QtCore .QPoint | None = None ,
526
542
parent : QtWidgets .QTreeWidgetItem = None ,
527
543
) -> None :
@@ -530,7 +546,7 @@ def list_items_show_result(
530
546
media_list = item .data (3 , QtCore .Qt .ItemDataRole .UserRole )
531
547
532
548
# Get all results
533
- media_items : [Track | Video ] = items_results_all (media_list )
549
+ media_items : [Track | Video | Album ] = items_results_all (media_list )
534
550
result : [ResultItem ] = self .search_result_to_model (media_items )
535
551
536
552
self .populate_tree_results (result , parent = parent )
@@ -551,10 +567,30 @@ def on_download_results(self):
551
567
if len (items ) == 0 :
552
568
logger_gui .error ("Please select a row first." )
553
569
else :
570
+ # If it is an artist resolve it with all available albums of him
571
+ if len (items ) == 1 :
572
+ tmp_media : QtWidgets .QTreeWidgetItem = items [0 ].data (5 , QtCore .Qt .ItemDataRole .UserRole )
573
+
574
+ if isinstance (tmp_media , Artist ):
575
+ tmp_children : [QtWidgets .QTreeWidgetItem ] = []
576
+ is_dummy_child = not bool (items [0 ].child (0 ).data (5 , QtCore .Qt .ItemDataRole .UserRole ))
577
+
578
+ # Use the expand function to retrieve all albums.
579
+ if is_dummy_child :
580
+ self .on_tr_results_expanded (items [0 ])
581
+
582
+ count_children : int = items [0 ].childCount ()
583
+
584
+ # Get all children.
585
+ for idx in range (count_children ):
586
+ tmp_children .append (items [0 ].child (idx ))
587
+
588
+ items : [Album ] = tmp_children
589
+
554
590
items_pos_last = len (items ) - 1
555
591
556
592
for item in items :
557
- media : Track | Album | Playlist | Video = item .data (5 , QtCore .Qt .ItemDataRole .UserRole )
593
+ media : Track | Album | Playlist | Video | Artist = item .data (5 , QtCore .Qt .ItemDataRole .UserRole )
558
594
# Skip only if Track item, skip option set and the item is not the last in the list.
559
595
download_delay : bool = bool (
560
596
isinstance (media , Track | Video )
@@ -567,7 +603,9 @@ def on_download_results(self):
567
603
self .pb_download .setText ("Download" )
568
604
self .pb_download .setEnabled (True )
569
605
570
- def download (self , media : Track | Album | Playlist | Video | Mix , dl : Download , delay_track : bool = False ) -> None :
606
+ def download (
607
+ self , media : Track | Album | Playlist | Video | Mix | Artist , dl : Download , delay_track : bool = False
608
+ ) -> None :
571
609
self .s_pb_reset .emit ()
572
610
self .s_statusbar_message .emit (StatusbarMessage (message = "Download started..." ))
573
611
@@ -597,7 +635,7 @@ def on_tr_results_expanded(self, list_item: QtWidgets.QTreeWidgetItem) -> None:
597
635
598
636
if load_children :
599
637
list_item .removeChild (list_item .child (0 ))
600
- media_list : [Mix | Album | Playlist ] = list_item .data (5 , QtCore .Qt .ItemDataRole .UserRole )
638
+ media_list : [Mix | Album | Playlist | Artist ] = list_item .data (5 , QtCore .Qt .ItemDataRole .UserRole )
601
639
602
640
self .list_items_show_result (media_list = media_list , parent = list_item )
603
641
0 commit comments