From 5c8cff00a9ce627b8564dc88d7e4162c95f544ea Mon Sep 17 00:00:00 2001 From: Maximilian Dorninger <97409287+maxdorninger@users.noreply.github.com> Date: Sat, 20 Dec 2025 20:58:06 +0100 Subject: [PATCH] Apply suggestions from code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- media_manager/torrent/utils.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/media_manager/torrent/utils.py b/media_manager/torrent/utils.py index 0ddd0f5..64823a2 100644 --- a/media_manager/torrent/utils.py +++ b/media_manager/torrent/utils.py @@ -210,6 +210,8 @@ def remove_special_chars_and_parentheses(title: str) -> str: # Remove special characters sanitized = remove_special_characters(sanitized) + # Collapse multiple whitespace characters and trim the result + sanitized = re.sub(r"\s+", " ", sanitized).strip() return sanitized @@ -235,7 +237,7 @@ def extract_external_id_from_string(input_string: str) -> tuple[str | None, int :param input_string: The string to extract the ID from. :return: The extracted Metadata Provider and ID or None if not found. """ - match = re.search(r"(tmdb|tvdb)(?:id)?[-_]?([0-9]+)", input_string, re.IGNORECASE) + match = re.search(r"\b(tmdb|tvdb)(?:id)?[-_]?([0-9]+)\b", input_string, re.IGNORECASE) if match: return match.group(1).lower(), int(match.group(2))