feat(file_renamer): Read from list of known actors

This commit is contained in:
abdus committed 2026-10-04 08:24:22 +02:00
1 parent aadb47a955
commit 9e2e098928
1 file changed
+43
+43
View File
@@ -215,6 +215,49 @@ def parse_release(
actors = [] actors = []
title = None title = None
# Prefer known actor names, checking longer names first so a short
# entry cannot consume the beginning of a longer one.
known_names = sorted(
{name.strip() for name in known_actors if name.strip()},
key=lambda name: (-len(name), name.casefold()),
)
words = remaining.split()
def match_known_name(start: int) -> tuple[str, int] | None:
for name in known_names:
name_words = name.split()
end = start + len(name_words)
if [word.casefold() for word in words[start:end]] == [
word.casefold() for word in name_words
]:
return name, end
return None
# Episode codes precede actor names in some sources, for example
# "E1109 Uma Jolie". Keep the code as the title and match actors after it.
actor_start = 0
if words and words[0].startswith("E") and words[0][1:].isdigit():
title = words[0]
actor_start = 1
cursor = actor_start
while known_names and (match := match_known_name(cursor)):
actor, cursor = match
actors.append(actor)
if cursor < len(words) and words[cursor].casefold() == "and":
cursor += 1
if actors:
title_words = words[cursor:]
if title_words:
title = " ".join(([title] if title else []) + title_words)
return Release(
studio=studio,
actors=sorted(set(actors)),
title=title,
released_at=parsed_date.date if parsed_date else None,
)
# PornFidelity.E1109.Uma.Jolie # PornFidelity.E1109.Uma.Jolie
match remaining.split(" "): match remaining.split(" "):
case [episode, *names] if episode.startswith("E") and episode[1:].isdigit(): case [episode, *names] if episode.startswith("E") and episode[1:].isdigit():