Skip to content
27 changes: 21 additions & 6 deletions tidal_dl_ng/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -1000,31 +1000,36 @@ def _handle_metadata_and_extras(
def _perform_post_processing(
self,
media: Track | Video,
path_media_dst: pathlib.Path,
path_media_src: pathlib.Path,
quality_audio: Quality | None,
quality_video: QualityVideo | None,
quality_audio_old: Quality | None,
quality_video_old: QualityVideo | None,
download_delay: bool,
skip_file: bool,
) -> None:
) -> pathlib.Path | None:
"""Perform post-processing tasks.

Args:
media (Track | Video): Media item.
path_media_dst (pathlib.Path): Destination file path.
path_media_src (pathlib.Path): Source file path.
quality_audio (Quality | None): Audio quality setting.
quality_video (QualityVideo | None): Video quality setting.
quality_audio_old (Quality | None): Previous audio quality.
quality_video_old (QualityVideo | None): Previous video quality.
download_delay (bool): Whether to apply download delay.
skip_file (bool): Whether file was skipped.

Returns:
pathlib.Path | None: The final path if the file was moved, otherwise None.
"""
new_path: pathlib.Path | None = None

# If files needs to be symlinked, do postprocessing here.
if self.settings.data.symlink_to_track and not isinstance(media, Video):
# Determine file extension for symlink
file_extension = path_media_dst.suffix
self.media_move_and_symlink(media, path_media_dst, file_extension)
file_extension = path_media_src.suffix
new_path = self.media_move_and_symlink(media, path_media_src, file_extension)

# Reset quality settings
if quality_audio_old is not None:
Expand All @@ -1045,6 +1050,8 @@ def _perform_post_processing(
self.fn_logger.debug(f"Next download will start in {time_sleep} seconds.")
time.sleep(time_sleep)

return new_path

def media_move_and_symlink(
self, media: Track | Video, path_media_src: pathlib.Path, file_extension: str
) -> pathlib.Path:
Expand Down Expand Up @@ -1374,7 +1381,7 @@ def items(
download_delay: bool = True,
quality_audio: Quality | None = None,
quality_video: QualityVideo | None = None,
) -> None:
) -> pathlib.Path | None:
"""Download all items in an album, playlist, or mix.

Args:
Expand All @@ -1386,6 +1393,9 @@ def items(
download_delay (bool, optional): Whether to delay between downloads. Defaults to True.
quality_audio (Quality | None, optional): Audio quality. Defaults to None.
quality_video (QualityVideo | None, optional): Video quality. Defaults to None.

Returns:
pathlib.Path | None: The path to the created album/playlist directory, or None if failed.
"""
# Validate and prepare media collection
validated_media = self._validate_and_prepare_media(media, media_id, media_type, video_download)
Expand Down Expand Up @@ -1429,6 +1439,11 @@ def items(

self.fn_logger.info(f"Finished list '{list_media_name}'.")

# Return the path to the album/playlist directory
if result_dirs:
return result_dirs[0] # All paths should share the same parent
return None

def _setup_collection_download_context(
self,
media: Album | Playlist | UserPlaylist | Mix,
Expand Down
Loading