summaryrefslogtreecommitdiff
path: root/tidal_dl_ng/helper/tidal.py
diff options
context:
space:
mode:
authorRobert Honz <exislow+github@gmail.com>2024-05-22 06:33:40 +0200
committerRobert Honz <exislow+github@gmail.com>2024-05-22 06:33:40 +0200
commit776542de5c61d207f502d6f4a961b6f3fb12e4cd (patch)
treed07fbc30b036cbbde9e644938ba842e40b6ee349 /tidal_dl_ng/helper/tidal.py
parent3a6bf023d772ccf32c5bd15486a13f5645bfc5f8 (diff)
downloadtidal-dl-ng-776542de5c61d207f502d6f4a961b6f3fb12e4cd.tar.gz
✨ Can download artists. Fixes #102
Diffstat (limited to 'tidal_dl_ng/helper/tidal.py')
-rw-r--r--tidal_dl_ng/helper/tidal.py51
1 files changed, 36 insertions, 15 deletions
diff --git a/tidal_dl_ng/helper/tidal.py b/tidal_dl_ng/helper/tidal.py
index c78b749..129592d 100644
--- a/tidal_dl_ng/helper/tidal.py
+++ b/tidal_dl_ng/helper/tidal.py
@@ -92,7 +92,9 @@ def search_results_all(session: Session, needle: str, types_media: SearchTypes =
return result
-def items_results_all(media_list: [Mix | Playlist | Album], videos_include: bool = True) -> [Track | Video | Album]:
+def items_results_all(
+ media_list: [Mix | Playlist | Album | Artist], videos_include: bool = True
+) -> [Track | Video | Album]:
result: [Track | Video | Album] = []
if isinstance(media_list, Mix):
@@ -107,22 +109,41 @@ def items_results_all(media_list: [Mix | Playlist | Album], videos_include: bool
func_get_items_media.append(media_list.tracks)
else:
func_get_items_media.append(media_list.get_albums)
- func_get_items_media.append(media_list.get_albums_ep_singles)
+ func_get_items_media.append(media_list.get_ep_singles)
- for func_media in func_get_items_media:
- limit: int = 100
- offset: int = 0
- done: bool = False
+ result = paginate_media(func_get_items_media)
- while not done:
- tmp_result: [Track | Video | Album] = func_media(limit=limit, offset=offset)
+ return result
+
+
+def all_artist_album_ids(media_artist: Artist) -> [int | None]:
+ result: [int] = []
+ func_get_items_media: [Callable] = [media_artist.get_albums, media_artist.get_ep_singles]
+ albums: [Album] = paginate_media(func_get_items_media)
+
+ for album in albums:
+ result.append(album.id)
+
+ return result
- if bool(tmp_result):
- result += tmp_result
- # Get the next page in the next iteration.
- offset += limit
- else:
- done = True
+
+def paginate_media(func_get_items_media) -> [Track | Video | Album]:
+ result: [Track | Video | Album] = []
+
+ for func_media in func_get_items_media:
+ limit: int = 100
+ offset: int = 0
+ done: bool = False
+
+ while not done:
+ tmp_result: [Track | Video | Album] = func_media(limit=limit, offset=offset)
+
+ if bool(tmp_result):
+ result += tmp_result
+ # Get the next page in the next iteration.
+ offset += limit
+ else:
+ done = True
return result
@@ -139,7 +160,7 @@ def instantiate_media(
session: Session,
media_type: type[MediaType.TRACK, MediaType.VIDEO, MediaType.ALBUM, MediaType.PLAYLIST, MediaType.MIX],
id_media: str,
-) -> Track | Video | Album | Playlist | Mix:
+) -> Track | Video | Album | Playlist | Mix | Artist:
if media_type == MediaType.TRACK:
media = session.track(id_media, with_album=True)
elif media_type == MediaType.VIDEO: