From 73358d1c22003a91792c74d5d12e0f18e34460c4 Mon Sep 17 00:00:00 2001 From: RemixDev Date: Wed, 29 Jul 2020 11:32:25 +0200 Subject: [PATCH] Modified fixLongName to work bytewise This fixes #6 --- deemix/utils/pathtemplates.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/deemix/utils/pathtemplates.py b/deemix/utils/pathtemplates.py index aba57cc..7b21ef6 100644 --- a/deemix/utils/pathtemplates.py +++ b/deemix/utils/pathtemplates.py @@ -19,17 +19,29 @@ def fixName(txt, char='_'): txt = re.sub(r'[\0\/\\:*?"<>|]', char, txt) return txt +def fixEndOfData(bString): + try: + bString.decode() + return True + except: + return False def fixLongName(name): if pathSep in name: name2 = name.split(pathSep) name = "" for txt in name2: - txt = txt[:200] + txt = txt.encode('utf-8')[:200] + while not fixEndOfData(txt): + txt = txt[:-1] + txt = txt.decode() name += txt + pathSep name = name[:-1] else: - name = name[:200] + name = name.encode('utf-8')[:200] + while not fixEndOfData(name): + name = name[:-1] + name = name.decode() return name