fix:自定义识别词不处理空格

This commit is contained in:
jxxghp 2024-04-10 07:07:17 +08:00
parent 27cb968a18
commit 18e7099848

View File

@ -26,7 +26,7 @@ class WordsMatcher(metaclass=Singleton):
# 读取自定义识别词 # 读取自定义识别词
words: List[str] = self.systemconfig.get(SystemConfigKey.CustomIdentifiers) or [] words: List[str] = self.systemconfig.get(SystemConfigKey.CustomIdentifiers) or []
for word in words: for word in words:
if not word or word.find('#') == 0: if not word or word.startswith("#"):
continue continue
try: try:
if word.count(" => ") and word.count(" && ") and word.count(" >> ") and word.count(" <> "): if word.count(" => ") and word.count(" && ") and word.count(" >> ") and word.count(" <> "):
@ -54,17 +54,18 @@ class WordsMatcher(metaclass=Singleton):
strings = word.split(" <> ") strings = word.split(" <> ")
offsets = strings[1].split(" >> ") offsets = strings[1].split(" >> ")
strings[1] = offsets[0] strings[1] = offsets[0]
title, message, state = self.__episode_offset(title, strings[0], strings[1], title, message, state = self.__episode_offset(title, strings[0], strings[1], offsets[1])
offsets[1])
else: else:
# 屏蔽词 # 屏蔽词
if not word.strip():
continue
title, message, state = self.__replace_regex(title, word, "") title, message, state = self.__replace_regex(title, word, "")
if state: if state:
appley_words.append(word) appley_words.append(word)
except Exception as err: except Exception as err:
logger.error(f"自定义识别词预处理标题失败:{str(err)} - {traceback.format_exc()}") logger.error(f"自定义识别词 {word} 预处理标题失败:{str(err)}")
return title, appley_words return title, appley_words
@ -79,7 +80,7 @@ class WordsMatcher(metaclass=Singleton):
else: else:
return re.sub(r'%s' % replaced, r'%s' % replace, title), "", True return re.sub(r'%s' % replaced, r'%s' % replace, title), "", True
except Exception as err: 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 return title, str(err), False
@staticmethod @staticmethod
@ -131,5 +132,5 @@ class WordsMatcher(metaclass=Singleton):
title = re.sub(episode_offset_re, r'%s' % episode_num[1], title) title = re.sub(episode_offset_re, r'%s' % episode_num[1], title)
return title, "", True return title, "", True
except Exception as err: 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 return title, str(err), False