Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix guessit parsing episodes with 1 before release group as multi #7427

Merged
merged 1 commit into from
Nov 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 92 additions & 0 deletions medusa/name_parser/rules/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -906,6 +906,97 @@ def when(self, matches, context):
return to_remove, to_append


class OnePreGroupAsMultiEpisode(Rule):
"""Remove last episode (one) and add the first episode as absolute.

There are animes where the absolute episode is detected as
multi episode because of a number (one) before the group.

Medusa rule:
- The first episode should be added as absolute
- The last episode should be removed
- Episode title should be release group

e.g.: Kemono.Michi.Rise.Up.E03.1080p.WEB.x264.1-URANiME-Obfuscated

guessit -t episode "Kemono.Michi.Rise.Up.E03.1080p.WEB.x264.1-URANiME-Obfuscated"

without this rule:
For: Kemono.Michi.Rise.Up.E03.1080p.WEB.x264.1-URANiME-Obfuscated
GuessIt found: {
"title": "Kemono Michi Rise Up",
"episode": [
3,
1
],
"screen_size": "1080p",
"source": "Web",
"video_codec": "H.264",
"episode_title": "URANiME",
"other": "Obfuscated",
"type": "episode"
}

with this rule:
For: Kemono.Michi.Rise.Up.E03.1080p.WEB.x264.1-URANiME-Obfuscated
GuessIt found: {
"title": "Kemono Michi Rise Up",
"episode": 3,
"absolute_episode": 3,
"screen_size": "1080p",
"source": "Web",
"video_codec": "H.264",
"release_group": "URANiME",
"other": "Obfuscated",
"type": "episode"
}
"""

priority = POST_PROCESS
consequence = [RemoveMatch, AppendMatch]

def when(self, matches, context):
"""Evaluate the rule.

:param matches:
:type matches: rebulk.match.Matches
:param context:
:type context: dict
:return:
"""
titles = matches.named('title')
if not titles:
return

episodes = matches.named('episode')
if not episodes or len(episodes) != 2:
return

is_anime = context.get('show_type') == 'anime' or matches.tagged('anime')
if is_anime or matches.named('season'):
return

sorted_episodes = sorted(episodes)
if sorted_episodes[-1].value != 1:
return

episode = copy.copy(sorted_episodes[0])
episode.name = 'absolute_episode'

to_remove = [sorted_episodes[-1]]
to_append = [episode]

episode_titles = matches.named('episode_title')
if episode_titles:
release_group = copy.copy(episode_titles[0])
release_group.name = 'release_group'

to_remove.append(episode_titles[0])
to_append.append(release_group)

return to_remove, to_append


class PartsAsEpisodeNumbers(Rule):
"""Move part to episode.

Expand Down Expand Up @@ -1491,6 +1582,7 @@ def rules():
AnimeWithSeasonMultipleEpisodeNumbers,
AnimeAbsoluteEpisodeNumbers,
AbsoluteEpisodeNumbers,
OnePreGroupAsMultiEpisode,
PartsAsEpisodeNumbers,
RemoveInvalidEpisodeSeparator,
CreateAliasWithAlternativeTitles,
Expand Down
24 changes: 24 additions & 0 deletions tests/test_guessit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2985,6 +2985,30 @@
release_group: Mad le Zisell
type: episode

? "Kemono.Michi.Rise.Up.E03.1080p.WEB.x264.1-URANiME-Obfuscated"
: title: Kemono Michi Rise Up
absolute_episode: 3
episode: 3
screen_size: 1080p
source: Web
video_codec: H.264
video_encoder: x264
release_group: URANiME
other: Obfuscated
type: episode

? "Kemono.Michi.Rise.Up/Kemono.Michi.Rise.Up.E03.1080p.WEB.x264.1-URANiME-Obfuscated"
: title: Kemono Michi Rise Up
absolute_episode: 3
episode: 3
screen_size: 1080p
source: Web
video_codec: H.264
video_encoder: x264
release_group: URANiME
other: Obfuscated
type: episode

# Anime show containing number in its title and show with :
? /Anime/Mobile Suit Gundam UC RE0096/Season 01/Mobile Suit Gundam UC RE0096 - s01e15 - Title
: title: Mobile Suit Gundam UC RE0096
Expand Down