Make character replacement a bit more systematic & uniform throughout

This commit is contained in:
rembo10
2014-04-08 12:08:28 -07:00
parent f51962f645
commit 00c545b37e
3 changed files with 14 additions and 4 deletions
+8
View File
@@ -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()
+5 -3
View File
@@ -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] + '_'
+1 -1
View File
@@ -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: