mirror of
https://github.com/nims11/IPod-Shuffle-4g.git
synced 2025-12-07 16:08:00 +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):
|
def raises_unicode_error(str):
|
||||||
try:
|
try:
|
||||||
str.encode('latin-1')
|
|
||||||
|
str.encode('ascii')
|
||||||
return False
|
return False
|
||||||
except (UnicodeEncodeError, UnicodeDecodeError):
|
except (UnicodeEncodeError, UnicodeDecodeError):
|
||||||
return True
|
return True
|
||||||
|
|
@ -686,14 +687,15 @@ def check_unicode(path):
|
||||||
ret_flag = True
|
ret_flag = True
|
||||||
if raises_unicode_error(item):
|
if raises_unicode_error(item):
|
||||||
src = os.path.join(path, 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))
|
print('Renaming %s -> %s' % (src, dest))
|
||||||
os.rename(src, dest)
|
os.rename(src, dest)
|
||||||
else:
|
else:
|
||||||
ret_flag = (check_unicode(os.path.join(path, item)) or ret_flag)
|
ret_flag = (check_unicode(os.path.join(path, item)) or ret_flag)
|
||||||
if ret_flag and raises_unicode_error(item):
|
if ret_flag and raises_unicode_error(item):
|
||||||
src = os.path.join(path, 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)
|
dest = os.path.join(path, new_name)
|
||||||
print('Renaming %s -> %s' % (src, dest))
|
print('Renaming %s -> %s' % (src, dest))
|
||||||
os.rename(src, dest)
|
os.rename(src, dest)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue