Skip to content

Commit fe28ba2

Browse files
authored
Fix Tags and add URLS (#603)
1 parent 6cc7078 commit fe28ba2

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

plugins/nfoSceneParser/nfoParser.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,7 @@ def parse(self):
193193
# Below are NFO extensions or liberal tag interpretations (not part of the nfo spec)
194194
"movie": self._nfo_root.findtext("set/name") or self._get_default("title", "nfo"),
195195
"scene_index": self._nfo_root.findtext("set/index") or None,
196-
# TODO: read multiple URL tags into array
197-
"urls": None if not self._nfo_root.findtext("url") else [self._nfo_root.findtext("url")],
196+
"urls": [url.text for url in self._nfo_root.findall("url") if url.text],
198197

199198
}
200199
return file_data

plugins/nfoSceneParser/nfoSceneParser.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import config
66
import log
77
import re
8+
import unicodedata
89
from abstractParser import AbstractParser
910
from nfoParser import NfoParser
1011
from reParser import RegExParser
@@ -135,7 +136,7 @@ def __find_create_scene_data(self):
135136
map(lambda p: p.get("id"), self._scene["performers"]))
136137
scene_tag_ids = list(map(lambda t: t.get("id"), self._scene["tags"]))
137138
# in "reload" mode, removes the reload marker tag as part of the scene update
138-
if config.reload_tag and self._reload_tag_id:
139+
if config.reload_tag and self._reload_tag_id and self._reload_tag_id in scene_tag_ids:
139140
scene_tag_ids.remove(self._reload_tag_id)
140141
# Currently supports only one movie (the first one...)
141142
scene_movie_id = scene_movie_index = None
@@ -178,14 +179,21 @@ def levenshtein_distance(self, str1, str2, ):
178179
def __is_matching(self, text1, text2, tolerance=False):
179180
if not text1 or not text2:
180181
return text1 == text2
182+
183+
# Normalize Unicode to handle emoji and special character variations
184+
normalized_text1 = unicodedata.normalize('NFC', text1).strip()
185+
normalized_text2 = unicodedata.normalize('NFC', text2).strip()
186+
181187
if tolerance:
182-
distance = self.levenshtein_distance(text1.lower(), text2.lower())
183-
match = distance < (config.levenshtein_distance_tolerance * log10(len(text1)))
188+
distance = self.levenshtein_distance(normalized_text1.lower(), normalized_text2.lower())
189+
# Ensure minimum tolerance for very short strings (like single emoji)
190+
tolerance_threshold = max(config.levenshtein_distance_tolerance * log10(max(len(normalized_text1), 2)), 1)
191+
match = distance < tolerance_threshold
184192
if match and distance:
185-
log.LogDebug(f"Matched with distance {distance}: '{text1}' with '{text2}'")
193+
log.LogDebug(f"Matched with distance {distance}: '{normalized_text1}' with '{normalized_text2}'")
186194
return match
187195
else:
188-
return text1.lower() == text2.lower()
196+
return normalized_text1.lower() == normalized_text2.lower()
189197

190198
def __find_create_performers(self):
191199
performer_ids = []

0 commit comments

Comments
 (0)