diff --git a/tidal_dl_ng/download.py b/tidal_dl_ng/download.py index cc48f4d..fbe3517 100644 --- a/tidal_dl_ng/download.py +++ b/tidal_dl_ng/download.py @@ -30,7 +30,7 @@ from tidal_dl_ng.helper.decryption import decrypt_file, decrypt_security_token from tidal_dl_ng.helper.exceptions import MediaMissing, MediaUnknown, UnknownManifestFormat from tidal_dl_ng.helper.path import check_file_exists, format_path_media, path_file_sanitize -from tidal_dl_ng.helper.tidal import name_builder_item +from tidal_dl_ng.helper.tidal import items_results_all, name_builder_item from tidal_dl_ng.helper.wrapper import WrapperLogger from tidal_dl_ng.metadata import Metadata from tidal_dl_ng.model.gui_data import ProgressBars @@ -306,18 +306,20 @@ def items( # Create file name and path file_name_relative = format_path_media(file_template, media) - # TODO: Extend with pagination support: Iterate through `items` and `tracks`until len(returned list) == 0 - # Get the items and name of the list. + # Get the name of the list and check, if videos should be included. + videos_include: bool = True + if isinstance(media, Mix): - items = media.items() list_media_name = media.title[:30] elif video_download: - items = media.items(limit=100) list_media_name = media.name[:30] else: - items = media.tracks(limit=999) + videos_include = False list_media_name = media.name[:30] + # Get all items of the list. + items = items_results_all(media, videos_include=videos_include) + # Determine where to redirect the progress information. if progress_gui is None: progress_stdout: bool = True diff --git a/tidal_dl_ng/gui.py b/tidal_dl_ng/gui.py index 5d8ee3e..6461fe1 100644 --- a/tidal_dl_ng/gui.py +++ b/tidal_dl_ng/gui.py @@ -2,7 +2,7 @@ import sys from collections.abc import Callable -from helper.tidal import items_all_results, search_all_results +from helper.tidal import items_results_all, search_results_all from tidal_dl_ng.helper.path import get_format_template @@ -272,7 +272,7 @@ def populate_tree_results(self, results: [ResultSearch]): self.tr_results.addTopLevelItem(child) def search(self, query: str, types_media: SearchTypes) -> [ResultSearch]: - result_search: dict[str, [SearchTypes]] = search_all_results( + result_search: dict[str, [SearchTypes]] = search_results_all( session=self.tidal.session, needle=query, types_media=types_media ) result: [ResultSearch] = [] @@ -392,7 +392,7 @@ def list_items_show(self, media_list: Album | Playlist | None = None, point: QtC media_list = item.data(3, QtCore.Qt.ItemDataRole.UserRole) # Get all results - media_items: [Track | Video] = items_all_results(media_list) + media_items: [Track | Video] = items_results_all(media_list) result: [ResultSearch] = self.search_result_to_model(media_items) self.populate_tree_results(result) diff --git a/tidal_dl_ng/helper/tidal.py b/tidal_dl_ng/helper/tidal.py index 1a1fcc1..60f636d 100644 --- a/tidal_dl_ng/helper/tidal.py +++ b/tidal_dl_ng/helper/tidal.py @@ -44,7 +44,7 @@ def get_tidal_media_type(url_media: str) -> MediaType | bool: return result -def search_all_results(session: Session, needle: str, types_media: SearchTypes = None) -> dict[str, [SearchTypes]]: +def search_results_all(session: Session, needle: str, types_media: SearchTypes = None) -> dict[str, [SearchTypes]]: limit: int = 300 offset: int = 0 done: bool = False @@ -72,7 +72,7 @@ def search_all_results(session: Session, needle: str, types_media: SearchTypes = return result -def items_all_results(media_list: [Mix | Playlist | Album]) -> [Track | Video]: +def items_results_all(media_list: [Mix | Playlist | Album], videos_include: bool = True) -> [Track | Video]: limit: int = 100 offset: int = 0 done: bool = False @@ -82,7 +82,11 @@ def items_all_results(media_list: [Mix | Playlist | Album]) -> [Track | Video]: result = media_list.items() else: while not done: - tmp_result: [Track | Video] = media_list.items(limit=limit, offset=offset) + tmp_result: [Track | Video] = ( + media_list.items(limit=limit, offset=offset) + if videos_include + else media_list.tracks(limit=limit, offset=offset) + ) if bool(tmp_result): result += tmp_result