From e0923807c6024833d8ad9f1f577e47e91ae4b1ec Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Tue, 30 Apr 2024 19:25:09 +0200 Subject: [PATCH 1/3] Fix titles join in path --- scanner/matcher/parser/rules.py | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/scanner/matcher/parser/rules.py b/scanner/matcher/parser/rules.py index 849e5f44..9632cfe6 100644 --- a/scanner/matcher/parser/rules.py +++ b/scanner/matcher/parser/rules.py @@ -54,21 +54,24 @@ class UnlistTitles(Rule): consequence = [RemoveMatch, AppendMatch] def when(self, matches: Matches, context) -> Any: - titles: List[Match] = matches.named("title", lambda x: x.tagged("title")) # type: ignore + fileparts: List[Match] = matches.markers.named("path") # type: ignore - if not titles or len(titles) <= 1: - return + for part in fileparts: + titles: List[Match] = matches.range(part.start, part.end, lambda x: x.name == "title") # type: ignore - title = copy(titles[0]) - for nmatch in titles[1:]: - # Check if titles are next to each other, if they are not ignore it. - next: List[Match] = matches.next(title) # type: ignore - if not next or next[0] != nmatch: - logger.warn(f"Ignoring potential part of title: {nmatch.value}") + if not titles or len(titles) <= 1: continue - title.end = nmatch.end - return [titles, [title]] + title = copy(titles[0]) + for nmatch in titles[1:]: + # Check if titles are next to each other, if they are not ignore it. + next: List[Match] = matches.next(title) # type: ignore + if not next or next[0] != nmatch: + logger.warn(f"Ignoring potential part of title: {nmatch.value}") + continue + title.end = nmatch.end + + return [titles, [title]] class EpisodeTitlePromotion(Rule): From 4c31e8cd7041fd61acd485f53fcbca57995af384 Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Tue, 30 Apr 2024 19:32:52 +0200 Subject: [PATCH 2/3] Fix episode title promotion rule when episode was already defined --- scanner/matcher/parser/rules.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/scanner/matcher/parser/rules.py b/scanner/matcher/parser/rules.py index 9632cfe6..d7a00206 100644 --- a/scanner/matcher/parser/rules.py +++ b/scanner/matcher/parser/rules.py @@ -106,6 +106,11 @@ class EpisodeTitlePromotion(Rule): if not ep_title: return + # Do not promote an episode title if there is already a know episode number + ep_nbr: List[Match] = matches.named("episode") # type: ignore + if ep_nbr and len(ep_nbr) > 0: + return + to_remove = [match for match in ep_title if str(match.value).isdecimal()] to_add = [] for tmatch in to_remove: From d617d8c32a544d1e3075e770378ee75f2529718e Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Tue, 30 Apr 2024 19:34:56 +0200 Subject: [PATCH 3/3] Format code --- scanner/matcher/parser/rules.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scanner/matcher/parser/rules.py b/scanner/matcher/parser/rules.py index d7a00206..5ff1b868 100644 --- a/scanner/matcher/parser/rules.py +++ b/scanner/matcher/parser/rules.py @@ -57,7 +57,9 @@ class UnlistTitles(Rule): fileparts: List[Match] = matches.markers.named("path") # type: ignore for part in fileparts: - titles: List[Match] = matches.range(part.start, part.end, lambda x: x.name == "title") # type: ignore + titles: List[Match] = matches.range( + part.start, part.end, lambda x: x.name == "title" + ) # type: ignore if not titles or len(titles) <= 1: continue