mirror of
https://github.com/nims11/IPod-Shuffle-4g.git
synced 2025-12-07 07:58:01 +09:00
Change encoding to ascii and better renaming
This commit is contained in:
parent
a97a99ab86
commit
e0622651bf
1 changed files with 5 additions and 3 deletions
|
|
@ -32,7 +32,8 @@ def make_dir_if_absent(path):
|
|||
|
||||
def raises_unicode_error(str):
|
||||
try:
|
||||
str.encode('latin-1')
|
||||
|
||||
str.encode('ascii')
|
||||
return False
|
||||
except (UnicodeEncodeError, UnicodeDecodeError):
|
||||
return True
|
||||
|
|
@ -686,14 +687,15 @@ def check_unicode(path):
|
|||
ret_flag = True
|
||||
if raises_unicode_error(item):
|
||||
src = os.path.join(path, item)
|
||||
dest = os.path.join(path, hash_error_unicode(item)) + os.path.splitext(item)[1].lower()
|
||||
new_name = os.path.splitext(item)[0].encode("ascii","ignore").decode("ascii")
|
||||
dest = os.path.join(path, new_name) + os.path.splitext(item)[1].lower()
|
||||
print('Renaming %s -> %s' % (src, dest))
|
||||
os.rename(src, dest)
|
||||
else:
|
||||
ret_flag = (check_unicode(os.path.join(path, item)) or ret_flag)
|
||||
if ret_flag and raises_unicode_error(item):
|
||||
src = os.path.join(path, item)
|
||||
new_name = hash_error_unicode(item)
|
||||
new_name = item.encode("ascii","ignore").decode("ascii")
|
||||
dest = os.path.join(path, new_name)
|
||||
print('Renaming %s -> %s' % (src, dest))
|
||||
os.rename(src, dest)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue