mirror of
https://github.com/KevinMidboe/spotify-downloader.git
synced 2025-10-29 18:00:15 +00:00
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
This commit is contained in:
committed by
Ritiek Malhotra
parent
b12ca8c785
commit
acff5fc8e2
@@ -88,15 +88,16 @@ def format_string(string_format, tags, slugification=False, force_spaces=False):
|
|||||||
format_tags[10] = tags["total_tracks"]
|
format_tags[10] = tags["total_tracks"]
|
||||||
format_tags[11] = tags["external_ids"]["isrc"]
|
format_tags[11] = tags["external_ids"]["isrc"]
|
||||||
|
|
||||||
for tag in format_tags:
|
format_tags_sanitized = {
|
||||||
if slugification:
|
k: sanitize_title(str(v), ok="'-_()[]{}")
|
||||||
format_tags[tag] = sanitize_title(format_tags[tag], ok="'-_()[]{}")
|
if slugification
|
||||||
else:
|
else str(v)
|
||||||
format_tags[tag] = str(format_tags[tag])
|
for k, v in format_tags.items()
|
||||||
|
}
|
||||||
|
|
||||||
for x in formats:
|
for x in formats:
|
||||||
format_tag = "{" + formats[x] + "}"
|
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:
|
if const.args.no_spaces and not force_spaces:
|
||||||
string_format = string_format.replace(" ", "_")
|
string_format = string_format.replace(" ", "_")
|
||||||
@@ -104,12 +105,15 @@ def format_string(string_format, tags, slugification=False, force_spaces=False):
|
|||||||
return string_format
|
return string_format
|
||||||
|
|
||||||
|
|
||||||
def sanitize_title(title, ok="-_()[]{}\/"):
|
def sanitize_title(title, ok="-_()[]{}"):
|
||||||
""" Generate filename of the song to be downloaded. """
|
""" Generate filename of the song to be downloaded. """
|
||||||
|
|
||||||
if const.args.no_spaces:
|
if const.args.no_spaces:
|
||||||
title = title.replace(" ", "_")
|
title = title.replace(" ", "_")
|
||||||
|
|
||||||
|
# replace slashes with "-" to avoid folder creation errors
|
||||||
|
title = title.replace("/", "-").replace("\\", "-")
|
||||||
|
|
||||||
# slugify removes any special characters
|
# slugify removes any special characters
|
||||||
title = slugify(title, ok=ok, lower=False, spaces=True)
|
title = slugify(title, ok=ok, lower=False, spaces=True)
|
||||||
return title
|
return title
|
||||||
|
|||||||
@@ -206,7 +206,6 @@ def main():
|
|||||||
log.debug("Platform: {}".format(platform.platform()))
|
log.debug("Platform: {}".format(platform.platform()))
|
||||||
log.debug(pprint.pformat(const.args.__dict__))
|
log.debug(pprint.pformat(const.args.__dict__))
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if const.args.song:
|
if const.args.song:
|
||||||
download_single(raw_song=const.args.song)
|
download_single(raw_song=const.args.song)
|
||||||
|
|||||||
Reference in New Issue
Block a user