diff --git a/headphones/helpers.py b/headphones/helpers.py index cfd69872..f3e130ec 100644 --- a/headphones/helpers.py +++ b/headphones/helpers.py @@ -177,6 +177,14 @@ def replace_all(text, dic): text = text.replace(i, j) return text +def replace_illegal_chars(string, type="file"): + if type == "file": + string = re.sub('[\?"*:|<>/]', string) + if type == "folder": + string = re.sub('[:?<>"|]') + + return string + def cleanName(string): pass1 = latinToAscii(string).lower() diff --git a/headphones/postprocessor.py b/headphones/postprocessor.py index 993f09e2..e0c876a6 100644 --- a/headphones/postprocessor.py +++ b/headphones/postprocessor.py @@ -500,9 +500,9 @@ def addAlbumArt(artwork, albumpath, release): '$year': year } - album_art_name = helpers.replace_all(headphones.ALBUM_ART_FORMAT.strip(), values).replace('/','_') + ".jpg" + album_art_name = helpers.replace_all(headphones.ALBUM_ART_FORMAT.strip(), values) + ".jpg" - album_art_name = album_art_name.replace('?','_').replace(':', '_').replace('"','_').replace('*','_').encode(headphones.SYS_ENCODING, 'replace') + album_art_name = helpers.replace_illegal_chars(album_art_name).encode(headphones.SYS_ENCODING, 'replace') if headphones.FILE_UNDERSCORES: album_art_name = album_art_name.replace(' ', '_') @@ -568,7 +568,9 @@ def moveFiles(albumpath, release, tracks): } folder = helpers.replace_all(headphones.FOLDER_FORMAT.strip(), values) - folder = folder.replace('./', '_/').replace(':','_').replace('?','_').replace('/.','/_').replace('<','_').replace('>','_').replace('|','_').replace('"','_') + + folder = helpers.replace_illegal_chars(folder, type="folder") + folder = folder.replace('./', '_/').replace('/.','/_') if folder.endswith('.'): folder = folder[:-1] + '_' diff --git a/headphones/searcher.py b/headphones/searcher.py index 4f4627a9..d20898d4 100644 --- a/headphones/searcher.py +++ b/headphones/searcher.py @@ -611,7 +611,7 @@ def send_to_downloader(data, bestqual, album): return # Get torrent name from .torrent, this is usually used by the torrent client as the folder name - torrent_name = folder_name + '.torrent' + torrent_name = helpers.replace_illegal_chars(folder_name) + '.torrent' download_path = os.path.join(headphones.TORRENTBLACKHOLE_DIR, torrent_name) try: