Move season dedup rule to rule.py

This commit is contained in:
Zoe Roux 2024-04-28 13:00:53 +02:00
parent 67cbf674b1
commit cd7bde944e
No known key found for this signature in database
2 changed files with 39 additions and 3 deletions

View File

@ -51,9 +51,6 @@ class Matcher:
if "mimetype" not in raw or not raw["mimetype"].startswith("video"):
return
# Remove seasons in "One Piece (1999) 152.mkv" for example
if raw.get("season") == raw.get("year") and "season" in raw:
del raw["season"]
logger.info("Identied %s: %s", path, raw)

View File

@ -253,3 +253,42 @@ class XemFixup(Rule):
if clean(new_title.value) in context["xem_titles"]:
return [[title, nmatch[0]], [new_title]]
class SeasonYearDedup(Rule):
"""Remove "season" when it's the same as "year"
Example: "One Piece (1999) 152.mkv"
Default:
```json
{
"title": "One Piece",
"year": 1999,
"season": 1999,
"episode": 152,
"container": "mkv",
"mimetype": "video/x-matroska",
"type": "episode"
}
```
Expected:
```json
{
"title": "One Piece",
"year": 1999,
"episode": 152,
"container": "mkv",
"mimetype": "video/x-matroska",
"type": "episode"
}
```
"""
priority = POST_PROCESS
consequence = [RemoveMatch]
def when(self, matches: Matches, context) -> Any:
season: List[Match] = matches.named("season") # type: ignore
year: List[Match] = matches.named("year") # type: ignore
if len(season) == 1 and len(year) == 1 and season[0].value == year[0].value:
return [season]