From 2175231bc16440388edd9b69308876342f30c491 Mon Sep 17 00:00:00 2001 From: Aria Stewart Date: Mon, 22 Jan 2024 19:13:02 -0500 Subject: [PATCH] Allow folder formats to specify a subfolder (#581) * Fix Tidal master quality (#571) * Allow folder formats to specify a subfolder --------- Co-authored-by: Jordan Pinnick <46541297+Geometryse@users.noreply.github.com> --- streamrip/client/downloadable.py | 2 +- streamrip/filepath_utils.py | 7 +++++++ streamrip/media/album.py | 4 ++-- streamrip/media/playlist.py | 6 +++--- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/streamrip/client/downloadable.py b/streamrip/client/downloadable.py index fb76614..4a4e2c0 100644 --- a/streamrip/client/downloadable.py +++ b/streamrip/client/downloadable.py @@ -200,7 +200,7 @@ class TidalDownloadable(Downloadable): ): self.session = session codec = codec.lower() - if codec == "flac": + if codec in ("flac", "mqa"): self.extension = "flac" else: self.extension = "m4a" diff --git a/streamrip/filepath_utils.py b/streamrip/filepath_utils.py index ed447b1..7cb67d4 100644 --- a/streamrip/filepath_utils.py +++ b/streamrip/filepath_utils.py @@ -11,3 +11,10 @@ def clean_filename(fn: str, restrict: bool = False) -> str: path = "".join(c for c in path if c in ALLOWED_CHARS) return path + +def clean_filepath(fn: str, restrict: bool = False) -> str: + path = str(sanitize_filepath(fn)) + if restrict: + path = "".join(c for c in path if c in ALLOWED_CHARS) + + return path diff --git a/streamrip/media/album.py b/streamrip/media/album.py index 40f3f2f..446097c 100644 --- a/streamrip/media/album.py +++ b/streamrip/media/album.py @@ -7,7 +7,7 @@ from .. import progress from ..client import Client from ..config import Config from ..db import Database -from ..filepath_utils import clean_filename +from ..filepath_utils import clean_filepath from ..metadata import AlbumMetadata from ..metadata.util import get_album_track_ids from .artwork import download_artwork @@ -89,7 +89,7 @@ class PendingAlbum(Pending): if config.downloads.source_subdirectories: parent = os.path.join(parent, self.client.source.capitalize()) formatter = config.filepaths.folder_format - folder = clean_filename( + folder = clean_filepath( meta.format_folder_path(formatter), config.filepaths.restrict_characters ) diff --git a/streamrip/media/playlist.py b/streamrip/media/playlist.py index 7fccda9..59b7aa6 100644 --- a/streamrip/media/playlist.py +++ b/streamrip/media/playlist.py @@ -16,7 +16,7 @@ from ..config import Config from ..console import console from ..db import Database from ..exceptions import NonStreamableError -from ..filepath_utils import clean_filename +from ..filepath_utils import clean_filepath from ..metadata import ( AlbumMetadata, Covers, @@ -151,7 +151,7 @@ class PendingPlaylist(Pending): meta = PlaylistMetadata.from_resp(resp, self.client.source) name = meta.name parent = self.config.session.downloads.folder - folder = os.path.join(parent, clean_filename(name)) + folder = os.path.join(parent, clean_filepath(name)) tracks = [ PendingPlaylistTrack( id, @@ -223,7 +223,7 @@ class PendingLastfmPlaylist(Pending): results: list[tuple[str | None, bool]] = await asyncio.gather(*requests) parent = self.config.session.downloads.folder - folder = os.path.join(parent, clean_filename(playlist_title)) + folder = os.path.join(parent, clean_filepath(playlist_title)) pending_tracks = [] for pos, (id, from_fallback) in enumerate(results, start=1):