From acff5fc8e2a00ee08d84ea37010194fce24d634e Mon Sep 17 00:00:00 2001 From: Manveer Basra Date: Sun, 21 Oct 2018 04:51:31 -0400 Subject: [PATCH] Check and replace slashes with dashes to avoid directory creation error (#402) * Added check for track titles containing slashes * Revert white-space typos * Added check for windows backslash * Added check for non-string filename titles --- spotdl/internals.py | 18 +++++++++++------- spotdl/spotdl.py | 1 - 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/spotdl/internals.py b/spotdl/internals.py index 980fb96..a195ca9 100755 --- a/spotdl/internals.py +++ b/spotdl/internals.py @@ -88,15 +88,16 @@ def format_string(string_format, tags, slugification=False, force_spaces=False): format_tags[10] = tags["total_tracks"] format_tags[11] = tags["external_ids"]["isrc"] - for tag in format_tags: - if slugification: - format_tags[tag] = sanitize_title(format_tags[tag], ok="'-_()[]{}") - else: - format_tags[tag] = str(format_tags[tag]) + format_tags_sanitized = { + k: sanitize_title(str(v), ok="'-_()[]{}") + if slugification + else str(v) + for k, v in format_tags.items() + } for x in formats: format_tag = "{" + formats[x] + "}" - string_format = string_format.replace(format_tag, format_tags[x]) + string_format = string_format.replace(format_tag, format_tags_sanitized[x]) if const.args.no_spaces and not force_spaces: string_format = string_format.replace(" ", "_") @@ -104,12 +105,15 @@ def format_string(string_format, tags, slugification=False, force_spaces=False): return string_format -def sanitize_title(title, ok="-_()[]{}\/"): +def sanitize_title(title, ok="-_()[]{}"): """ Generate filename of the song to be downloaded. """ if const.args.no_spaces: title = title.replace(" ", "_") + # replace slashes with "-" to avoid folder creation errors + title = title.replace("/", "-").replace("\\", "-") + # slugify removes any special characters title = slugify(title, ok=ok, lower=False, spaces=True) return title diff --git a/spotdl/spotdl.py b/spotdl/spotdl.py index 2aa9264..72201db 100755 --- a/spotdl/spotdl.py +++ b/spotdl/spotdl.py @@ -206,7 +206,6 @@ def main(): log.debug("Platform: {}".format(platform.platform())) log.debug(pprint.pformat(const.args.__dict__)) - try: if const.args.song: download_single(raw_song=const.args.song)