From 9321ac03da2aee9e45cf833f503e3b36060eb9ee Mon Sep 17 00:00:00 2001 From: Rikrdoga Date: Fri, 17 Oct 2025 14:05:48 -0600 Subject: feat: Add 'Download Full Album' from track context menu --- tidal_dl_ng/gui.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'tidal_dl_ng/gui.py') diff --git a/tidal_dl_ng/gui.py b/tidal_dl_ng/gui.py index d27f2b6..744cc06 100644 --- a/tidal_dl_ng/gui.py +++ b/tidal_dl_ng/gui.py @@ -583,6 +583,11 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow): # We build the menu. menu = QtWidgets.QMenu() + + media = get_results_media_item(index, self.proxy_tr_results, self.model_tr_results) + if isinstance(media, Track) and media.album: + menu.addAction("Download Full Album", lambda: self.thread_download_album_from_track(point)) + menu.addAction("Copy Share URL", lambda: self.on_copy_url_share(self.tr_results, point)) menu.exec(self.tr_results.mapToGlobal(point)) @@ -1699,6 +1704,39 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow): event.accept() + def thread_download_album_from_track(self, point: QtCore.QPoint) -> None: + """Starts the download of the full album from a selected track in a new thread. + + Args: + point (QPoint): The point in the tree where the user clicked. + """ + self.thread_it(self.on_download_album_from_track, point) + + + def on_download_album_from_track(self, point: QtCore.QPoint) -> None: + """Gets the album from a selected track and adds it to the download queue.""" + index: QtCore.QModelIndex = self.tr_results.indexAt(point) + media_track: Track = get_results_media_item(index, self.proxy_tr_results, self.model_tr_results) + + # Ensure we have a track and an album object with an ID + if isinstance(media_track, Track) and media_track.album and media_track.album.id: + try: + # Use the album ID from the track to fetch the FULL album object from TIDAL + full_album_object = self.tidal.session.album(media_track.album.id) + + # Convert the full album object into a queue item + queue_dl_item: QueueDownloadItem | None = self.media_to_queue_download_model(full_album_object) + + if queue_dl_item: + # Add the item to the download queue + self.queue_download_media(queue_dl_item) + else: + logger_gui.warning(f"Failed to create a queue item for album ID: {full_album_object.id}") + except Exception as e: + logger_gui.error(f"Could not fetch the full album from TIDAL. Error: {e}") + else: + logger_gui.warning("Could not retrieve album information from the selected track.") + # TODO: Comment with Google Docstrings. def gui_activate(tidal: Tidal | None = None): -- cgit v1.3.1 From aaca12cacc7cbb3e20c3c709db15164ee2330d39 Mon Sep 17 00:00:00 2001 From: Robert Honz Date: Mon, 20 Oct 2025 09:37:01 +0200 Subject: fix(gui): 🐛 improve album download action and update docstring MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Refactored the menu action for downloading the full album from a track. * Enhanced the docstring for `on_download_album_from_track` to clarify its functionality and error handling. --- tidal_dl_ng/gui.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'tidal_dl_ng/gui.py') diff --git a/tidal_dl_ng/gui.py b/tidal_dl_ng/gui.py index 744cc06..d0ee637 100644 --- a/tidal_dl_ng/gui.py +++ b/tidal_dl_ng/gui.py @@ -583,11 +583,11 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow): # We build the menu. menu = QtWidgets.QMenu() - media = get_results_media_item(index, self.proxy_tr_results, self.model_tr_results) + if isinstance(media, Track) and media.album: - menu.addAction("Download Full Album", lambda: self.thread_download_album_from_track(point)) - + menu.addAction("Download Full Album", lambda: self.thread_download_album_from_track(point)) + menu.addAction("Copy Share URL", lambda: self.on_copy_url_share(self.tr_results, point)) menu.exec(self.tr_results.mapToGlobal(point)) @@ -1712,9 +1712,14 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow): """ self.thread_it(self.on_download_album_from_track, point) - def on_download_album_from_track(self, point: QtCore.QPoint) -> None: - """Gets the album from a selected track and adds it to the download queue.""" + """Adds the album associated with a selected track to the download queue. + + This method retrieves the album from a track selected in the results tree and attempts to add it to the download queue. If the album cannot be retrieved or an error occurs, a warning or error is logged. + + Args: + point (QtCore.QPoint): The point in the results tree where the user clicked. + """ index: QtCore.QModelIndex = self.tr_results.indexAt(point) media_track: Track = get_results_media_item(index, self.proxy_tr_results, self.model_tr_results) -- cgit v1.3.1