summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWinman486 <harpsystems@gmail.com>2025-10-20 16:12:46 -0500
committerWinman486 <harpsystems@gmail.com>2025-10-20 16:12:46 -0500
commit3c835c2d196f02871a1be23430223538bf2cd226 (patch)
tree8d021fa04776f7bf67911dd4fd54a3e6f3dc912b
parent90ff7ea52ef7dd3c02afc313da4682b1fcb799eb (diff)
parent0afd65c89b9033a5a9505dc193699396666e16f2 (diff)
downloadtidal-dl-ng-3c835c2d196f02871a1be23430223538bf2cd226.tar.gz
Merge upstream/master and resolve conflicts
- Resolved conflict in dialog_settings.py (kept both cb_use_primary_album_artist and cb_mark_explicit checkboxes) - Fixed code quality issues found by make check: * Removed duplicate on_download_album_from_track function (F811) * Updated isinstance calls to use X | Y syntax instead of (X, Y) (UP038) * Fixed unused loop variable album_stub (B007) * Applied automatic formatting fixes (black, prettier, trailing whitespace) - Only remaining issue is C901 complexity warning in on_download_all_albums_from_playlist (expected per maintainer feedback)
-rw-r--r--pyproject.toml2
-rw-r--r--tidal_dl_ng/dialog.py1
-rw-r--r--tidal_dl_ng/download.py6
-rw-r--r--tidal_dl_ng/gui.py165
-rw-r--r--tidal_dl_ng/helper/path.py2
-rw-r--r--tidal_dl_ng/model/cfg.py6
-rw-r--r--tidal_dl_ng/ui/dialog_settings.py17
-rw-r--r--tidal_dl_ng/ui/dialog_settings.ui10
8 files changed, 112 insertions, 97 deletions
diff --git a/pyproject.toml b/pyproject.toml
index 4b7f2b7..0a5edae 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -1,7 +1,7 @@
[project]
name = "tidal-dl-ng"
authors = [{ name = "Robert Honz", email = "<cen.sored@gmail.com>" }]
-version = "0.29.0"
+version = "0.30.0"
description = "TIDAL Medial Downloader Next Generation!"
readme = "README.md"
license = "AGPL-3.0-only"
diff --git a/tidal_dl_ng/dialog.py b/tidal_dl_ng/dialog.py
index 8b194f4..0bf9b2a 100644
--- a/tidal_dl_ng/dialog.py
+++ b/tidal_dl_ng/dialog.py
@@ -181,6 +181,7 @@ class DialogPreferences(QtWidgets.QDialog):
"video_convert_mp4",
"extract_flac",
"metadata_cover_embed",
+ "mark_explicit",
"cover_album_file",
"skip_existing",
"symlink_to_track",
diff --git a/tidal_dl_ng/download.py b/tidal_dl_ng/download.py
index f0bb883..bcb9d4c 100644
--- a/tidal_dl_ng/download.py
+++ b/tidal_dl_ng/download.py
@@ -1232,7 +1232,7 @@ class Download:
target_upc: dict[str, str] = METADATA_LOOKUP_UPC[metadata_target_upc]
explicit: bool = track.explicit if hasattr(track, "explicit") else False
title = name_builder_title(track)
- title += METADATA_EXPLICIT if explicit else ""
+ title += METADATA_EXPLICIT if explicit and self.settings.data.mark_explicit else ""
# `None` values are not allowed.
m: Metadata = Metadata(
@@ -1564,7 +1564,9 @@ class Download:
path_tracks.sort()
elif not is_album:
# If it is not an album sort by creation time
- path_tracks.sort(key=lambda x: os.path.getctime(x))
+ path_tracks.sort(
+ key=lambda x: x.stat().st_birthtime if hasattr(x.stat(), "st_birthtime") else x.stat().st_ctime
+ )
# Write data to m3u file
with path_playlist.open(mode="w", encoding="utf-8") as f:
diff --git a/tidal_dl_ng/gui.py b/tidal_dl_ng/gui.py
index 3b21df3..0dc319d 100644
--- a/tidal_dl_ng/gui.py
+++ b/tidal_dl_ng/gui.py
@@ -588,10 +588,15 @@ 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))
# Add "Download Full Album" option if it's a track or video with an album
- if isinstance(media, (Track, Video)) and hasattr(media, "album") and media.album:
+ if isinstance(media, Track | Video) and hasattr(media, "album") and media.album:
menu.addAction("Download Full Album", lambda: self.thread_it(self.on_download_album_from_track, point))
menu.exec(self.tr_results.mapToGlobal(point))
@@ -623,7 +628,7 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
def on_queue_download_remove_item(self, item: QtWidgets.QTreeWidgetItem) -> None:
"""Remove a specific item from the download queue.
-
+
Args:
item (QTreeWidgetItem): The item to remove.
"""
@@ -642,7 +647,7 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
def on_download_all_albums_from_playlist(self, point: QtCore.QPoint) -> None:
"""Download all unique albums from tracks in a playlist.
-
+
Args:
point (QPoint): The point in the tree where the playlist was right-clicked.
"""
@@ -650,158 +655,100 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
# Get the playlist
item = self.tr_lists_user.itemAt(point)
media_list = get_user_list_media_item(item)
-
- if not isinstance(media_list, (Playlist, UserPlaylist, Mix)):
+
+ if not isinstance(media_list, Playlist | UserPlaylist | Mix):
logger_gui.error("Please select a playlist or mix.")
return
-
+
# Get all items from the playlist
logger_gui.info(f"Fetching all tracks from: {media_list.name}")
media_items = items_results_all(media_list)
-
+
# Extract unique album IDs from tracks
album_ids = {}
for media_item in media_items:
- if isinstance(media_item, (Track, Video)) and hasattr(media_item, 'album') and media_item.album:
+ if isinstance(media_item, Track | Video) and hasattr(media_item, "album") and media_item.album:
try:
# Access album.id carefully as it might trigger API calls
album_id = media_item.album.id
if album_id:
album_ids[album_id] = media_item.album
except Exception as e:
- logger_gui.debug(f"Skipping track with unavailable album: {str(e)}")
+ logger_gui.debug(f"Skipping track with unavailable album: {e!s}")
continue
-
+
if not album_ids:
logger_gui.warning("No albums found in this playlist.")
return
-
+
logger_gui.info(f"Found {len(album_ids)} unique albums. Loading with rate limiting...")
-
+
# Load albums with rate limiting
albums_dict = {}
- for idx, (album_id, album_stub) in enumerate(album_ids.items(), start=1):
+ for idx, album_id in enumerate(album_ids.keys(), start=1):
try:
# Add delay every 20 albums to avoid rate limiting
if idx > 1 and (idx - 1) % 20 == 0:
logger_gui.info(f"🛑 RATE LIMITING: Processed {idx - 1} albums, pausing for 3 seconds...")
time.sleep(3)
-
+
# Check session validity before making API calls
if not self.tidal.session.check_login():
logger_gui.error("Session expired. Please restart the application and login again.")
return
-
+
# Reload full album object
album = self.tidal.session.album(album_id)
albums_dict[album.id] = album
- logger_gui.debug(f"Loaded album {idx}/{len(album_ids)}: {name_builder_artist(album)} - {album.name}")
-
+ logger_gui.debug(
+ f"Loaded album {idx}/{len(album_ids)}: {name_builder_artist(album)} - {album.name}"
+ )
+
except Exception as e:
error_msg = str(e)
# Check for OAuth/authentication errors
if "401" in error_msg or "OAuth" in error_msg or "token" in error_msg.lower():
logger_gui.error(f"Authentication error: {error_msg}")
logger_gui.error("Your session has expired. Please restart the application and login again.")
- self.s_statusbar_message.emit(StatusbarMessage(message="Session expired - please restart and login", timeout=5000))
+ self.s_statusbar_message.emit(
+ StatusbarMessage(message="Session expired - please restart and login", timeout=5000)
+ )
return
logger_gui.warning(f"Failed to load album {album_id}: {error_msg}")
- logger_gui.info("Note: Some albums may be unavailable due to region restrictions or removal from TIDAL. This is normal.")
+ logger_gui.info(
+ "Note: Some albums may be unavailable due to region restrictions or removal from TIDAL. This is normal."
+ )
continue
-
+
if not albums_dict:
logger_gui.error("Failed to load any albums from playlist.")
return
-
+
# Prepare all queue items first
logger_gui.info(f"Successfully loaded {len(albums_dict)} albums. Preparing queue items...")
-
+
queue_items = []
for album in albums_dict.values():
queue_dl_item = self.media_to_queue_download_model(album)
if queue_dl_item:
queue_items.append((queue_dl_item, album))
logger_gui.debug(f"Prepared: {name_builder_artist(album)} - {album.name}")
-
+
# Add all items to queue at once
logger_gui.info(f"Adding {len(queue_items)} albums to queue...")
for queue_dl_item, album in queue_items:
self.queue_download_media(queue_dl_item)
logger_gui.info(f"Added: {name_builder_artist(album)} - {album.name}")
-
+
# Show confirmation
message = f"Added {len(queue_items)} albums to download queue"
self.s_statusbar_message.emit(StatusbarMessage(message=message, timeout=3000))
logger_gui.info(message)
-
- except Exception as e:
- error_msg = f"Error downloading albums from playlist: {str(e)}"
- logger_gui.error(error_msg)
- self.s_statusbar_message.emit(StatusbarMessage(message=error_msg, timeout=3000))
- def on_download_album_from_track(self, point: QtCore.QPoint) -> None:
- """Download the full album from a selected track.
-
- Args:
- point (QPoint): The point in the tree where the track was right-clicked.
- """
- try:
- # Get the selected track/video
- index = self.tr_results.indexAt(point)
-
- if not index.isValid():
- logger_gui.error("Invalid selection.")
- return
-
- # Get the media item (Track or Video)
- media = get_results_media_item(index, self.proxy_tr_results, self.model_tr_results)
-
- # Verify it's a Track or Video with an album
- if not isinstance(media, (Track, Video)):
- logger_gui.error("Selected item is not a track or video.")
- return
-
- if not hasattr(media, 'album') or not media.album:
- logger_gui.error("Selected track does not have an associated album.")
- return
-
- # Get the album
- album = media.album
-
- # Reload the complete album object from TIDAL's API
- album = self.tidal.session.album(album.id)
-
- # Debug logging for album object
- logger_gui.info(f"Album object: {album}")
- logger_gui.info(f"Album name: {album.name}")
- logger_gui.info(f"Album ID: {album.id}")
- logger_gui.info(f"Album available: {getattr(album, 'available', 'unknown')}")
-
- # Create a queue download item for the album
- queue_dl_item = self.media_to_queue_download_model(album)
-
- if queue_dl_item:
- # Add to download queue
- self.queue_download_media(queue_dl_item)
-
- # Show confirmation message
- artist_name = name_builder_artist(album)
- message = f"Album added to queue: {artist_name} - {album.name}"
-
- self.s_statusbar_message.emit(
- StatusbarMessage(message=message, timeout=3000)
- )
-
- logger_gui.info(message)
- else:
- logger_gui.error(f"Unable to add album to queue: {album.name}")
-
except Exception as e:
- error_msg = f"Error downloading album from track: {str(e)}"
+ error_msg = f"Error downloading albums from playlist: {e!s}"
logger_gui.error(error_msg)
- self.s_statusbar_message.emit(
- StatusbarMessage(message=error_msg, timeout=3000)
- )
+ self.s_statusbar_message.emit(StatusbarMessage(message=error_msg, timeout=3000))
def on_copy_url_share(
self, tree_target: QtWidgets.QTreeWidget | QtWidgets.QTreeView, point: QtCore.QPoint = None
@@ -1908,6 +1855,44 @@ 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:
+ """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)
+
+ # 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):
diff --git a/tidal_dl_ng/helper/path.py b/tidal_dl_ng/helper/path.py
index f83e5b7..9227ee3 100644
--- a/tidal_dl_ng/helper/path.py
+++ b/tidal_dl_ng/helper/path.py
@@ -219,7 +219,7 @@ def _format_artist_names(
"""
if name == "artist_name" and isinstance(media, Track | Video):
# For folder paths, use album artist if setting is enabled
- if use_primary_album_artist and hasattr(media, 'album') and media.album and media.album.artists:
+ if use_primary_album_artist and hasattr(media, "album") and media.album and media.album.artists:
return media.album.artists[0].name
# Otherwise use track artists as before
if hasattr(media, "artists"):
diff --git a/tidal_dl_ng/model/cfg.py b/tidal_dl_ng/model/cfg.py
index 4797fb5..1c87992 100644
--- a/tidal_dl_ng/model/cfg.py
+++ b/tidal_dl_ng/model/cfg.py
@@ -12,7 +12,9 @@ class Settings:
skip_existing: bool = True
lyrics_embed: bool = False
lyrics_file: bool = False
- use_primary_album_artist: bool = False # When True, uses first album artist instead of track artists for folder paths
+ use_primary_album_artist: bool = (
+ False # When True, uses first album artist instead of track artists for folder paths
+ )
# TODO: Implement API KEY selection.
# api_key_index: bool = 0
# TODO: Implement album info download to separate file.
@@ -36,6 +38,7 @@ class Settings:
path_binary_ffmpeg: str = ""
metadata_cover_dimension: CoverDimensions = CoverDimensions.Px320
metadata_cover_embed: bool = True
+ mark_explicit: bool = False
cover_album_file: bool = True
extract_flac: bool = True
downloads_simultaneous_per_track_max: int = 20
@@ -96,6 +99,7 @@ class HelpSettings:
"The dimensions of the cover image embedded into the track. Possible values: 320x320, 640x640x 1280x1280."
)
metadata_cover_embed: str = "Embed album cover into file."
+ mark_explicit: str = "Mark explicit tracks with '🅴' in track title (only applies to metadata)."
cover_album_file: str = "Save cover to 'cover.jpg', if an album is downloaded."
extract_flac: str = "Extract FLAC audio tracks from MP4 containers and save them as `*.flac` (uses FFmpeg)."
downloads_simultaneous_per_track_max: str = "Maximum number of simultaneous chunk downloads per track."
diff --git a/tidal_dl_ng/ui/dialog_settings.py b/tidal_dl_ng/ui/dialog_settings.py
index 07fd217..ebdbcd4 100644
--- a/tidal_dl_ng/ui/dialog_settings.py
+++ b/tidal_dl_ng/ui/dialog_settings.py
@@ -1,7 +1,7 @@
################################################################################
## Form generated from reading UI file 'dialog_settings.ui'
##
-## Created by: Qt User Interface Compiler version 6.8.1
+## Created by: Qt User Interface Compiler version 6.10.0
##
## WARNING! All changes made in this file will be lost when recompiling UI file!
################################################################################
@@ -198,6 +198,20 @@ class Ui_DialogSettings:
self.lv_flags.addLayout(self.horizontalLayout_12)
+ self.horizontalLayout_13 = QHBoxLayout()
+ self.horizontalLayout_13.setObjectName("horizontalLayout_13")
+
+ self.lv_mark_explicit = QVBoxLayout()
+ self.lv_mark_explicit.setObjectName("lv_mark_explicit")
+ self.cb_mark_explicit = QCheckBox(self.gb_flags)
+ self.cb_mark_explicit.setObjectName("cb_mark_explicit")
+
+ self.lv_mark_explicit.addWidget(self.cb_mark_explicit)
+
+ self.horizontalLayout_13.addLayout(self.lv_mark_explicit)
+
+ self.lv_flags.addLayout(self.horizontalLayout_13)
+
self.lv_main.addWidget(self.gb_flags)
self.gb_choices = QGroupBox(DialogSettings)
@@ -603,6 +617,7 @@ class Ui_DialogSettings:
self.cb_skip_existing.setText(QCoreApplication.translate("DialogSettings", "CheckBox", None))
self.cb_symlink_to_track.setText(QCoreApplication.translate("DialogSettings", "CheckBox", None))
self.cb_playlist_create.setText(QCoreApplication.translate("DialogSettings", "CheckBox", None))
+ self.cb_mark_explicit.setText(QCoreApplication.translate("DialogSettings", "CheckBox", None))
self.gb_choices.setTitle(QCoreApplication.translate("DialogSettings", "Choices", None))
self.l_icon_quality_audio.setText(QCoreApplication.translate("DialogSettings", "TextLabel", None))
self.l_quality_audio.setText(QCoreApplication.translate("DialogSettings", "TextLabel", None))
diff --git a/tidal_dl_ng/ui/dialog_settings.ui b/tidal_dl_ng/ui/dialog_settings.ui
index 5287e38..95c6b52 100644
--- a/tidal_dl_ng/ui/dialog_settings.ui
+++ b/tidal_dl_ng/ui/dialog_settings.ui
@@ -250,7 +250,15 @@
</layout>
</item>
<item>
- <layout class="QVBoxLayout" name="verticalLayout_4"/>
+ <layout class="QVBoxLayout" name="lv_mark_explicit">
+ <item>
+ <widget class="QCheckBox" name="cb_mark_explicit">
+ <property name="text">
+ <string>CheckBox</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
</item>
</layout>
</item>