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