From 18e70998488cdd3d7b095db8b9a2f29a623cfa8a Mon Sep 17 00:00:00 2001 From: jxxghp Date: Wed, 10 Apr 2024 07:07:17 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9A=E8=87=AA=E5=AE=9A=E4=B9=89?= =?UTF-8?q?=E8=AF=86=E5=88=AB=E8=AF=8D=E4=B8=8D=E5=A4=84=E7=90=86=E7=A9=BA?= =?UTF-8?q?=E6=A0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/core/meta/words.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/app/core/meta/words.py b/app/core/meta/words.py index ae6ed908..7dfb9777 100644 --- a/app/core/meta/words.py +++ b/app/core/meta/words.py @@ -26,7 +26,7 @@ class WordsMatcher(metaclass=Singleton): # 读取自定义识别词 words: List[str] = self.systemconfig.get(SystemConfigKey.CustomIdentifiers) or [] for word in words: - if not word or word.find('#') == 0: + if not word or word.startswith("#"): continue try: if word.count(" => ") and word.count(" && ") and word.count(" >> ") and word.count(" <> "): @@ -54,17 +54,18 @@ class WordsMatcher(metaclass=Singleton): strings = word.split(" <> ") offsets = strings[1].split(" >> ") strings[1] = offsets[0] - title, message, state = self.__episode_offset(title, strings[0], strings[1], - offsets[1]) + title, message, state = self.__episode_offset(title, strings[0], strings[1], offsets[1]) else: # 屏蔽词 + if not word.strip(): + continue title, message, state = self.__replace_regex(title, word, "") if state: appley_words.append(word) except Exception as err: - logger.error(f"自定义识别词预处理标题失败:{str(err)} - {traceback.format_exc()}") + logger.error(f"自定义识别词 {word} 预处理标题失败:{str(err)}") return title, appley_words @@ -79,7 +80,7 @@ class WordsMatcher(metaclass=Singleton): else: return re.sub(r'%s' % replaced, r'%s' % replace, title), "", True except Exception as err: - logger.error(f"自定义识别词正则替换失败:{str(err)} - {traceback.format_exc()}") + logger.warn(f"自定义识别词正则替换失败:{str(err)} - {traceback.format_exc()}") return title, str(err), False @staticmethod @@ -131,5 +132,5 @@ class WordsMatcher(metaclass=Singleton): title = re.sub(episode_offset_re, r'%s' % episode_num[1], title) return title, "", True except Exception as err: - logger.error(f"自定义识别词集数偏移失败:{str(err)} - {traceback.format_exc()}") + logger.warn(f"自定义识别词集数偏移失败:{str(err)} - 前定位词:{front},后定位词:{back},偏移量:{offset}") return title, str(err), False