From 26da00f1a27576ffb6169908eaa7cf334410a93f Mon Sep 17 00:00:00 2001 From: Nathan Thomas Date: Tue, 14 Jun 2022 12:35:08 -0700 Subject: [PATCH] Add option to not truncate filname #340 --- rip/config.toml | 5 ++++- rip/core.py | 1 + streamrip/media.py | 12 ++++++++---- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/rip/config.toml b/rip/config.toml index 8f37bf0..7549e7b 100644 --- a/rip/config.toml +++ b/rip/config.toml @@ -153,6 +153,9 @@ folder_format = "{albumartist} - {title} ({year}) [{container}] [{bit_depth}B-{s track_format = "{tracknumber}. {artist} - {title}{explicit}" # Only allow printable ASCII characters in filenames. restrict_characters = false +# Truncate the filename if it is greater than 120 characters +# Setting this to false may cause downloads to fail on some systems +truncate = true # Last.fm playlists are downloaded by searching for the titles of the tracks @@ -169,4 +172,4 @@ progress_bar = "dainty" [misc] # Metadata to identify this config file. Do not change. -version = "1.9.2" +version = "1.9.6" diff --git a/rip/core.py b/rip/core.py index dd33652..3f075a8 100644 --- a/rip/core.py +++ b/rip/core.py @@ -216,6 +216,7 @@ class RipCore(list): concurrency = session["downloads"]["concurrency"] return { "restrict_filenames": filepaths["restrict_characters"], + "truncate_filenames": filepaths["truncate"], "parent_folder": session["downloads"]["folder"], "folder_format": filepaths["folder_format"], "track_format": filepaths["track_format"], diff --git a/streamrip/media.py b/streamrip/media.py index afff293..f9eba6a 100644 --- a/streamrip/media.py +++ b/streamrip/media.py @@ -1516,7 +1516,9 @@ class Album(Tracklist, Media): parent_folder = kwargs.get("parent_folder", "StreamripDownloads") if self.folder_format: self.folder = self._get_formatted_folder( - parent_folder, restrict=kwargs.get("restrict_filenames", False) + parent_folder, + restrict=kwargs.get("restrict_filenames", False), + truncate=kwargs.get("truncate_filenames", True), ) else: self.folder = parent_folder @@ -1660,7 +1662,9 @@ class Album(Tracklist, Media): logger.debug("Formatter: %s", fmt) return fmt - def _get_formatted_folder(self, parent_folder: str, restrict: bool = False) -> str: + def _get_formatted_folder( + self, parent_folder: str, restrict: bool = False, truncate: bool = True + ) -> str: """Generate the folder name for this album. :param parent_folder: @@ -1675,8 +1679,8 @@ class Album(Tracklist, Media): self._get_formatter(), restrict=restrict, ) - if len(formatted_folder) > 120: - formatted_folder = f"{formatted_folder[:120]}..." + if truncate and len(formatted_folder) > 120: + formatted_folder = formatted_folder[:120] return os.path.join(parent_folder, formatted_folder)