mirror of
https://github.com/rembo10/headphones.git
synced 2026-05-16 00:25:31 +01:00
Normalize path replacement strings
Potential fix for https://github.com/rembo10/headphones/issues/1824
This commit is contained in:
@@ -19,6 +19,8 @@ import time
|
||||
import shutil
|
||||
import datetime
|
||||
import headphones
|
||||
import unicodedata
|
||||
import sys
|
||||
|
||||
from operator import itemgetter
|
||||
from beets.mediafile import MediaFile, FileTypeError, UnreadableFileError
|
||||
@@ -168,12 +170,17 @@ def piratesize(size):
|
||||
|
||||
return size
|
||||
|
||||
def replace_all(text, dic):
|
||||
def replace_all(text, dic, normalize=False):
|
||||
|
||||
if not text:
|
||||
return ''
|
||||
|
||||
for i, j in dic.iteritems():
|
||||
if normalize:
|
||||
if sys.platform == 'darwin':
|
||||
j = unicodedata.normalize('NFD', j)
|
||||
else:
|
||||
j = unicodedata.normalize('NFC', j)
|
||||
text = text.replace(i, j)
|
||||
return text
|
||||
|
||||
|
||||
@@ -624,9 +624,9 @@ def moveFiles(albumpath, release, tracks):
|
||||
|
||||
for r,d,f in os.walk(albumpath):
|
||||
try:
|
||||
origfolder = os.path.basename(os.path.normpath(r))
|
||||
origfolder = os.path.basename(os.path.normpath(r).decode(headphones.SYS_ENCODING, 'replace'))
|
||||
except:
|
||||
origfolder = ''
|
||||
origfolder = u''
|
||||
|
||||
values = { '$Artist': artist,
|
||||
'$SortArtist': sortname,
|
||||
@@ -644,7 +644,7 @@ def moveFiles(albumpath, release, tracks):
|
||||
'$originalfolder': origfolder.lower()
|
||||
}
|
||||
|
||||
folder = helpers.replace_all(headphones.FOLDER_FORMAT.strip(), values)
|
||||
folder = helpers.replace_all(headphones.FOLDER_FORMAT.strip(), values, normalize=True)
|
||||
|
||||
folder = helpers.replace_illegal_chars(folder, type="folder")
|
||||
folder = folder.replace('./', '_/').replace('/.','/_')
|
||||
|
||||
Reference in New Issue
Block a user