diff --git a/modules/image_processor3.py b/modules/image_processor3.py index 10bd044..7636866 100644 --- a/modules/image_processor3.py +++ b/modules/image_processor3.py @@ -448,6 +448,9 @@ class ImageProcessor3: def update_toggle_states(self, toggle_states): self.toggle_states = toggle_states + if 'unwanted_words' in self.toggle_states: + self.unwanted_texts = self.toggle_states['unwanted_words'] + # 1. 멤버십 및 권한 정보 업데이트 self.is_member_valid = self.toggle_states.get('membership_level', 'basic') == 'vip' or self.authenticated_by_admin @@ -1499,52 +1502,27 @@ class ImageProcessor3: def process_translated_texts(self, translated_texts, local_image_path, index): """ - 번역된 단어 리스트(translated_texts)에서 unwanted_texts의 원본값이 - 앞이나 뒤에 포함되면 치환값으로 바꿉니다. + 번역된 텍스트 리스트(translated_texts)에서 unwanted_texts의 원본값이 + 포함되면 치환값으로 바꿉니다. 치환값이 '이미지삭제'라면 None 반환(이미지 제외) """ new_texts = [] for i, text in enumerate(translated_texts): self.logger.log(f"[치환 처리 {i+1}] 원본 텍스트: '{text}'", level=logging.DEBUG) - # 텍스트를 빈칸으로 분리 - words = text.split() - self.logger.log(f"[치환 처리 {i+1}] 분리된 단어: {words}", level=logging.DEBUG) - - processed_words = [] + final_text = text text_replaced = False - for word_idx, word in enumerate(words): - word_replaced = False - - # unwanted_texts와 매칭 확인 + if isinstance(self.unwanted_texts, dict) and self.unwanted_texts: for origin, replace in self.unwanted_texts.items(): - if word.startswith(origin) or word.endswith(origin) or word == origin: - self.logger.log(f"[치환 처리 {i+1}] 단어 '{word}' -> '{replace}' (원본: '{origin}')", level=logging.DEBUG) - + if origin in final_text: if replace == "이미지삭제": - self.logger.log(f"이미지 {index+1} 제외됨: {local_image_path}", level=logging.DEBUG) + self.logger.log(f"이미지 {index+1} 제외됨 (키워드 '{origin}' 감지): {local_image_path}", level=logging.DEBUG) return None - # 단어 치환 - if word == origin: - new_word = replace - elif word.startswith(origin): - new_word = replace + word[len(origin):] - elif word.endswith(origin): - new_word = word[:-len(origin)] + replace - - processed_words.append(new_word) - word_replaced = True + final_text = final_text.replace(origin, replace) text_replaced = True - self.logger.log(f"[치환 처리 {i+1}] 단어 치환 완료: '{word}' -> '{new_word}'", level=logging.DEBUG) - break - - if not word_replaced: - processed_words.append(word) - - # 처리된 단어들을 다시 합치기 - final_text = ' '.join(processed_words) + new_texts.append(final_text) if text_replaced: