Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow folder formats to specify a subfolder #581

Merged
merged 2 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion streamrip/client/downloadable.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def __init__(
):
self.session = session
codec = codec.lower()
if codec == "flac":
if codec in ("flac", "mqa"):
self.extension = "flac"
else:
self.extension = "m4a"
Expand Down
7 changes: 7 additions & 0 deletions streamrip/filepath_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions streamrip/media/album.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
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
Expand Down Expand Up @@ -89,7 +89,7 @@ def _album_folder(self, parent: str, meta: AlbumMetadata) -> str:
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
)

Expand Down
6 changes: 3 additions & 3 deletions streamrip/media/playlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
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,
Expand Down Expand Up @@ -151,7 +151,7 @@ async def resolve(self) -> Playlist | None:
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,
Expand Down Expand Up @@ -223,7 +223,7 @@ def callback():
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):
Expand Down