5151def list_validate (lst ):
5252 if isinstance (lst , str ):
5353 lst = [lst ]
54+ if isinstance (lst , int ):
55+ lst = [str (lst )]
5456 if len (lst ) == 0 :
5557 raise ValueError ("An empty list was provided." )
5658 return lst
@@ -555,7 +557,10 @@ def artists_paginated(
555557 :param order_direction: Optional; A :class:`OrderDirection` describing the ordering direction when sorting by `order`. eg.: "ASC", "DESC"
556558 :return: A :class:`list` :class:`~tidalapi.artist.Artist` objects containing the favorite artists.
557559 """
558- return get_items (self .session .user .favorites .artists , order , order_direction )
560+ count = self .session .user .favorites .get_artists_count ()
561+ return get_items (
562+ self .session .user .favorites .artists , count , order , order_direction
563+ )
559564
560565 def artists (
561566 self ,
@@ -587,6 +592,21 @@ def artists(
587592 ),
588593 )
589594
595+ def get_artists_count (
596+ self ,
597+ ) -> int :
598+ """Get the total number of artists in the user's collection.
599+
600+ This performs a minimal API request (limit=1) to fetch metadata about the
601+ artists without retrieving all of them. The API response contains
602+ 'totalNumberOfItems', which represents the total items (artists) available.
603+ :return: The number of items available.
604+ """
605+ params = {"limit" : 1 , "offset" : 0 }
606+
607+ json_obj = self .requests .map_request (f"{ self .base_url } /artists" , params = params )
608+ return json_obj .get ("totalNumberOfItems" , 0 )
609+
590610 def albums_paginated (
591611 self ,
592612 order : Optional [AlbumOrder ] = None ,
@@ -598,7 +618,10 @@ def albums_paginated(
598618 :param order_direction: Optional; A :class:`OrderDirection` describing the ordering direction when sorting by `order`. eg.: "ASC", "DESC"
599619 :return: A :class:`list` :class:`~tidalapi.album.Album` objects containing the favorite albums.
600620 """
601- return get_items (self .session .user .favorites .albums , order , order_direction )
621+ count = self .session .user .favorites .get_artists_count ()
622+ return get_items (
623+ self .session .user .favorites .albums , count , order , order_direction
624+ )
602625
603626 def albums (
604627 self ,
@@ -628,19 +651,36 @@ def albums(
628651 ),
629652 )
630653
654+ def get_albums_count (
655+ self ,
656+ ) -> int :
657+ """Get the total number of albums in the user's collection.
658+
659+ This performs a minimal API request (limit=1) to fetch metadata about the albums
660+ without retrieving all of them. The API response contains 'totalNumberOfItems',
661+ which represents the total items (albums) available.
662+ :return: The number of items available.
663+ """
664+ params = {"limit" : 1 , "offset" : 0 }
665+
666+ json_obj = self .requests .map_request (f"{ self .base_url } /albums" , params = params )
667+ return json_obj .get ("totalNumberOfItems" , 0 )
668+
631669 def playlists_paginated (
632670 self ,
633671 order : Optional [PlaylistOrder ] = None ,
634672 order_direction : Optional [OrderDirection ] = None ,
635673 ) -> List ["Playlist" ]:
636- """Get the users favorite playlists relative to the root folder, using
637- pagination.
674+ """Get the users favorite playlists, using pagination.
638675
639676 :param order: Optional; A :class:`PlaylistOrder` describing the ordering type when returning the user favorite playlists. eg.: "NAME, "DATE"
640677 :param order_direction: Optional; A :class:`OrderDirection` describing the ordering direction when sorting by `order`. eg.: "ASC", "DESC"
641678 :return: A :class:`list` :class:`~tidalapi.playlist.Playlist` objects containing the favorite playlists.
642679 """
643- return get_items (self .session .user .favorites .playlists , order , order_direction )
680+ count = self .session .user .favorites .get_playlists_count ()
681+ return get_items (
682+ self .session .user .favorites .playlists , count , order , order_direction
683+ )
644684
645685 def playlists (
646686 self ,
@@ -666,10 +706,14 @@ def playlists(
666706 }
667707 if order :
668708 params ["order" ] = order .value
709+ else :
710+ params ["order" ] = PlaylistOrder .DateCreated .value
669711 if order_direction :
670712 params ["orderDirection" ] = order_direction .value
713+ else :
714+ params ["orderDirection" ] = OrderDirection .Descending .value
671715
672- endpoint = "my-collection/playlists"
716+ endpoint = "my-collection/playlists/folders "
673717 return cast (
674718 List ["Playlist" ],
675719 self .session .request .map_request (
@@ -724,19 +768,41 @@ def playlist_folders(
724768 ),
725769 )
726770
771+ def get_playlists_count (self ) -> int :
772+ """Get the total number of playlists in the user's root collection.
773+
774+ This performs a minimal API request (limit=1) to fetch metadata about the
775+ playlists without retrieving all of them. The API response contains
776+ 'totalNumberOfItems', which represents the total playlists available.
777+ :return: The number of items available.
778+ """
779+ params = {"folderId" : "root" , "offset" : 0 , "limit" : 1 , "includeOnly" : "" }
780+
781+ endpoint = "my-collection/playlists/folders"
782+ json_obj = self .session .request .map_request (
783+ url = urljoin (
784+ self .session .config .api_v2_location ,
785+ endpoint ,
786+ ),
787+ params = params ,
788+ )
789+ return json_obj .get ("totalNumberOfItems" , 0 )
790+
727791 def tracks_paginated (
728792 self ,
729793 order : Optional [ItemOrder ] = None ,
730794 order_direction : Optional [OrderDirection ] = None ,
731795 ) -> List ["Playlist" ]:
732- """Get the users favorite playlists relative to the root folder, using
733- pagination.
796+ """Get the users favorite tracks, using pagination.
734797
735798 :param order: Optional; A :class:`ItemOrder` describing the ordering type when returning the user favorite tracks. eg.: "NAME, "DATE"
736799 :param order_direction: Optional; A :class:`OrderDirection` describing the ordering direction when sorting by `order`. eg.: "ASC", "DESC"
737800 :return: A :class:`list` :class:`~tidalapi.playlist.Playlist` objects containing the favorite tracks.
738801 """
739- return get_items (self .session .user .favorites .tracks , order , order_direction )
802+ count = self .session .user .favorites .get_tracks_count ()
803+ return get_items (
804+ self .session .user .favorites .tracks , count , order , order_direction
805+ )
740806
741807 def tracks (
742808 self ,
@@ -766,6 +832,21 @@ def tracks(
766832 ),
767833 )
768834
835+ def get_tracks_count (
836+ self ,
837+ ) -> int :
838+ """Get the total number of tracks in the user's collection.
839+
840+ This performs a minimal API request (limit=1) to fetch metadata about the tracks
841+ without retrieving all of them. The API response contains 'totalNumberOfItems',
842+ which represents the total items (tracks) available.
843+ :return: The number of items available.
844+ """
845+ params = {"limit" : 1 , "offset" : 0 }
846+
847+ json_obj = self .requests .map_request (f"{ self .base_url } /tracks" , params = params )
848+ return json_obj .get ("totalNumberOfItems" , 0 )
849+
769850 def videos (
770851 self ,
771852 limit : Optional [int ] = None ,
0 commit comments