Skip to content

Commit

Permalink
Avoid trigger of useless rules consequences
Browse files Browse the repository at this point in the history
  • Loading branch information
Toilal committed Aug 30, 2019
1 parent 0e41d2a commit df499c0
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 17 deletions.
4 changes: 3 additions & 1 deletion guessit/rules/processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ def when(self, matches, context):
for match in matches.ending(group.end - 1):
ending.append(match)

return starting, ending
if starting or ending:
return starting, ending
return False

def then(self, matches, when_response, context):
starting, ending = when_response
Expand Down
4 changes: 3 additions & 1 deletion guessit/rules/properties/bit_rate.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,6 @@ def when(self, matches, context):
else:
to_rename.append(match)

return to_rename, to_remove
if to_rename or to_remove:
return to_rename, to_remove
return False
24 changes: 18 additions & 6 deletions guessit/rules/properties/episodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,9 @@ def when(self, matches, context):
if to_append:
to_remove.extend(weak_dup_matches)

return to_remove, to_append
if to_remove or to_append:
return to_remove, to_append
return False


class CountValidator(Rule):
Expand All @@ -464,7 +466,9 @@ def when(self, matches, context):
season_count.append(count)
else:
to_remove.append(count)
return to_remove, episode_count, season_count
if to_remove or episode_count or season_count:
return to_remove, episode_count, season_count
return False


class SeePatternRange(Rule):
Expand Down Expand Up @@ -499,7 +503,9 @@ def when(self, matches, context):

to_remove.append(separator)

return to_remove, to_append
if to_remove or to_append:
return to_remove, to_append
return False


class AbstractSeparatorRange(Rule):
Expand Down Expand Up @@ -555,7 +561,9 @@ def when(self, matches, context):

previous_match = next_match

return to_remove, to_append
if to_remove or to_append:
return to_remove, to_append
return False


class RenameToAbsoluteEpisode(Rule):
Expand Down Expand Up @@ -683,7 +691,9 @@ def when(self, matches, context):
pass

to_remove.extend(weaks)
return to_remove, to_append
if to_remove or to_append:
return to_remove, to_append
return False


class RemoveWeakIfSxxExx(Rule):
Expand Down Expand Up @@ -897,4 +907,6 @@ def when(self, matches, context):
markers.append(marker)
discs.extend(sorted(marker.initiator.children.named('episode'), key=lambda m: m.value))

return discs, markers, to_remove
if discs or markers or to_remove:
return discs, markers, to_remove
return False
8 changes: 6 additions & 2 deletions guessit/rules/properties/language.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,9 @@ def when(self, matches, context):
to_remove.extend(matches.conflicting(lang))
if prefix in to_remove:
to_remove.remove(prefix)
return to_rename, to_remove
if to_rename or to_remove:
return to_rename, to_remove
return False

def then(self, matches, when_response, context):
to_rename, to_remove = when_response
Expand Down Expand Up @@ -427,7 +429,9 @@ def when(self, matches, context):
to_append.append(lang)
if suffix in to_remove:
to_remove.remove(suffix)
return to_append, to_remove
if to_append or to_remove:
return to_append, to_remove
return False

def then(self, matches, when_response, context):
to_rename, to_remove = when_response
Expand Down
12 changes: 8 additions & 4 deletions guessit/rules/properties/release_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,8 @@ def when(self, matches, context): # pylint:disable=inconsistent-return-statemen

if releasegroup.value:
to_append.append(releasegroup)
return to_remove, to_append
if to_remove or to_append:
return to_remove, to_append


class SceneReleaseGroup(Rule):
Expand Down Expand Up @@ -312,11 +313,11 @@ def when(self, matches, context):

# If a release_group is found before, ignore this kind of release_group rule.
if matches.named('release_group'):
return to_remove, to_append
return False

if not matches.named('episode') and not matches.named('season') and matches.named('release_group'):
# This doesn't seems to be an anime, and we already found another release_group.
return to_remove, to_append
return False

for filepart in marker_sorted(matches.markers.named('path'), matches):

Expand All @@ -340,4 +341,7 @@ def when(self, matches, context):
to_append.append(group)
to_remove.extend(matches.range(empty_group.start, empty_group.end,
lambda m: 'weak-language' in m.tags))
return to_remove, to_append

if to_remove or to_append:
return to_remove, to_append
return False
4 changes: 3 additions & 1 deletion guessit/rules/properties/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,9 @@ def when(self, matches, context):
to_remove.append(match)
to_append.append(new_source)

return to_remove, to_append
if to_remove or to_append:
return to_remove, to_append
return False


class ValidateSource(Rule):
Expand Down
6 changes: 4 additions & 2 deletions guessit/rules/properties/title.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ def when(self, matches, context):
to_remove = []

if matches.named(self.match_name, lambda match: 'expected' in match.tags):
return ret, to_remove
return False

fileparts = [filepart for filepart in list(marker_sorted(matches.markers.named('path'), matches))
if not self.filepart_filter or self.filepart_filter(filepart, matches)]
Expand Down Expand Up @@ -284,7 +284,9 @@ def when(self, matches, context):
ret.extend(titles)
to_remove.extend(to_remove_c)

return ret, to_remove
if ret or to_remove:
return ret, to_remove
return False


class TitleFromPosition(TitleBaseRule):
Expand Down

0 comments on commit df499c0

Please sign in to comment.