From 5821a79af958b024c1c0ce47a9b218bd80f08ec7 Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Fri, 2 Feb 2024 17:16:04 +0100 Subject: [PATCH] Add episode title promotion rule --- scanner/scanner/parser/rules.py | 56 +++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/scanner/scanner/parser/rules.py b/scanner/scanner/parser/rules.py index 62212468..0845b095 100644 --- a/scanner/scanner/parser/rules.py +++ b/scanner/scanner/parser/rules.py @@ -6,6 +6,62 @@ from rebulk.match import Matches, Match from copy import copy +class EpisodeTitlePromotion(Rule): + """Promote "episode_title" to "episode" when the title is in fact the episode number + + Example: '[Erai-raws] Youkoso Jitsuryoku Shijou Shugi no Kyoushitsu e S3 - 05 [1080p][Multiple Subtitle][0DDEAFCD].mkv' + + Default: + ```json + { + "release_group": "Erai-raws", + "title": "Youkoso Jitsuryoku Shijou Shugi no Kyoushitsu e", + "season": 3, + "episode_title": "05", + "screen_size": "1080p", + "subtitle_language": "Multiple languages", + "crc32": "0DDEAFCD", + "container": "mkv", + "mimetype": "video/x-matroska", + "type": "episode" + } + ``` + + Expected: + ```json + { + "release_group": "Erai-raws", + "title": "Youkoso Jitsuryoku Shijou Shugi no Kyoushitsu e", + "season": 3, + "episode": 5, + "screen_size": "1080p", + "subtitle_language": "Multiple languages", + "crc32": "0DDEAFCD", + "container": "mkv", + "mimetype": "video/x-matroska", + "type": "episode" + } + ``` + """ + + priority = POST_PROCESS + consequence = [RemoveMatch, AppendMatch] + + def when(self, matches: Matches, context) -> Any: + ep_title: List[Match] = matches.named("episode_title") # type: ignore + if not ep_title: + return + + to_remove = [match for match in ep_title if str(match.value).isdecimal()] + to_add = [] + for tmatch in to_remove: + match = copy(tmatch) + match.name = "episode" + match.value = int(str(tmatch.value)) + to_add.append(match) + return [to_remove, to_add] + + class MultipleSeasonRule(Rule): """Understand `abcd Season 2 - 5.mkv` as S2E5