summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tidal_dl_ng/cli.py33
-rw-r--r--tidal_dl_ng/helper/path.py2
-rw-r--r--tidal_dl_ng/helper/tidal.py51
3 files changed, 61 insertions, 25 deletions
diff --git a/tidal_dl_ng/cli.py b/tidal_dl_ng/cli.py
index c4f8b31..5abda11 100644
--- a/tidal_dl_ng/cli.py
+++ b/tidal_dl_ng/cli.py
@@ -13,7 +13,12 @@ from tidal_dl_ng.config import Settings, Tidal
from tidal_dl_ng.constants import CTX_TIDAL, MediaType
from tidal_dl_ng.download import Download
from tidal_dl_ng.helper.path import get_format_template, path_file_settings
-from tidal_dl_ng.helper.tidal import get_tidal_media_id, get_tidal_media_type
+from tidal_dl_ng.helper.tidal import (
+ all_artist_album_ids,
+ get_tidal_media_id,
+ get_tidal_media_type,
+ instantiate_media,
+)
from tidal_dl_ng.helper.wrapper import LoggerWrapped
from tidal_dl_ng.model.cfg import HelpSettings
@@ -192,14 +197,24 @@ def download(
dl.item(
media_id=item_id, media_type=media_type, file_template=file_template, download_delay=download_delay
)
- elif media_type in [MediaType.ALBUM, MediaType.PLAYLIST, MediaType.MIX]:
- dl.items(
- media_id=item_id,
- media_type=media_type,
- file_template=file_template,
- video_download=ctx.obj[CTX_TIDAL].settings.data.video_download,
- download_delay=settings.data.download_delay,
- )
+ elif media_type in [MediaType.ALBUM, MediaType.PLAYLIST, MediaType.MIX, MediaType.ARTIST]:
+ item_ids: [int] = []
+
+ if media_type == MediaType.ARTIST:
+ media = instantiate_media(ctx.obj[CTX_TIDAL].session, media_type, item_id)
+ media_type = MediaType.ALBUM
+ item_ids = item_ids + all_artist_album_ids(media)
+ else:
+ item_ids.append(item_id)
+
+ for item_id in item_ids:
+ dl.items(
+ media_id=item_id,
+ media_type=media_type,
+ file_template=file_template,
+ video_download=ctx.obj[CTX_TIDAL].settings.data.video_download,
+ download_delay=settings.data.download_delay,
+ )
# Stop Progress display.
progress.stop()
diff --git a/tidal_dl_ng/helper/path.py b/tidal_dl_ng/helper/path.py
index e6a162e..23316d6 100644
--- a/tidal_dl_ng/helper/path.py
+++ b/tidal_dl_ng/helper/path.py
@@ -165,7 +165,7 @@ def get_format_template(
if isinstance(media, Track) or media == MediaType.TRACK:
result = settings.data.format_track
- elif isinstance(media, Album) or media == MediaType.ALBUM:
+ elif isinstance(media, Album) or media == MediaType.ALBUM or media == MediaType.ARTIST:
result = settings.data.format_album
elif isinstance(media, Playlist | UserPlaylist) or media == MediaType.PLAYLIST:
result = settings.data.format_playlist
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: