Skip to content

Commit

Permalink
fix(episode): ignore absolute_episode guess when SxxExx match is avai…
Browse files Browse the repository at this point in the history
…lable in filepart

Close #712
  • Loading branch information
Toilal committed Feb 18, 2023
1 parent e717928 commit 4aa5012
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
20 changes: 14 additions & 6 deletions guessit/rules/properties/episodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -582,17 +582,25 @@ class RenameToAbsoluteEpisode(Rule):
The matches in the group with higher episode values are renamed to absolute_episode.
"""

consequence = RenameMatch('absolute_episode')
consequence = [RenameMatch('absolute_episode'), RemoveMatch]

def when(self, matches, context): # pylint:disable=inconsistent-return-statements
initiators = {match.initiator for match in matches.named('episode')
if len(match.initiator.children.named('episode')) > 1}
if len(initiators) != 2:
ret = []
ret = ([], [])
for filepart in matches.markers.named('path'):
sxxexx_episode_matches = matches.range(filepart.start + 1, filepart.end,
predicate=lambda m: m.name == 'episode' and
'SxxExx' in m.tags)
if matches.range(filepart.start + 1, filepart.end, predicate=lambda m: m.name == 'episode'):
ret.extend(
matches.starting(filepart.start, predicate=lambda m: m.initiator.name == 'weak_episode'))
absolute_episode_candidate = matches.starting(filepart.start,
predicate=lambda
m: m.initiator.name == 'weak_episode')
if sxxexx_episode_matches:
ret[1].extend(absolute_episode_candidate)
else:
ret[0].extend(absolute_episode_candidate)
return ret

initiators = sorted(initiators, key=lambda item: item.end)
Expand All @@ -601,9 +609,9 @@ def when(self, matches, context): # pylint:disable=inconsistent-return-statemen
second_range = matches.named('episode', predicate=lambda m: m.initiator == initiators[1])
if len(first_range) == len(second_range):
if second_range[0].value > first_range[0].value:
return second_range
return second_range, []
if first_range[0].value > second_range[0].value:
return first_range
return first_range, []


class EpisodeNumberSeparatorRange(AbstractSeparatorRange):
Expand Down
3 changes: 1 addition & 2 deletions guessit/test/episodes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4062,8 +4062,7 @@
type: episode

? 165.Show Name.s08e014
: absolute_episode: 165
title: Show Name
: title: 165 Show Name
season: 8
episode: 14
type: episode
Expand Down

0 comments on commit 4aa5012

Please sign in to comment.