Skip to content

Commit

Permalink
Proper audio_channels detection and validation
Browse files Browse the repository at this point in the history
  • Loading branch information
ratoaq2 committed Feb 28, 2017
1 parent f2a460f commit c4184af
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 7 deletions.
30 changes: 26 additions & 4 deletions guessit/rules/properties/audio_codec.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,18 @@ def audio_codec_priority(match1, match2):
rebulk.string("HQ", value="HQ", tags="AC3")

rebulk.defaults(name="audio_channels")
rebulk.regex(r'(7[\W_][01](?:ch)?)(?:[^\d]|$)', r'(?<=[^\d\W]{2})(7[01]\b)', value='7.1', children=True)
rebulk.regex(r'(5[\W_][01](?:ch)?)(?:[^\d]|$)', r'(?<=[^\d\W]{2})(5[01]\b)', value='5.1', children=True)
rebulk.regex(r'(2[\W_]0(?:ch)?)(?:[^\d]|$)', r'(?<=[^\d\W]{2})(20\b)', value='2.0', children=True)
rebulk.regex(r'(7[\W_][01](?:ch)?)(?:[^\d]|$)', value='7.1', children=True)
rebulk.regex(r'(5[\W_][01](?:ch)?)(?:[^\d]|$)', value='5.1', children=True)
rebulk.regex(r'(2[\W_]0(?:ch)?)(?:[^\d]|$)', value='2.0', children=True)
rebulk.regex('7[01]', value='7.1', validator=seps_after, tags='weak-audio_channels')
rebulk.regex('5[01]', value='5.1', validator=seps_after, tags='weak-audio_channels')
rebulk.string('20', value='2.0', validator=seps_after, tags='weak-audio_channels')
rebulk.string('7ch', '8ch', value='7.1')
rebulk.string('5ch', '6ch', value='5.1')
rebulk.string('2ch', 'stereo', value='2.0')
rebulk.string('1ch', 'mono', value='1.0')

rebulk.rules(DtsRule, AacRule, Ac3Rule, AudioValidatorRule, HqConflictRule)
rebulk.rules(DtsRule, AacRule, Ac3Rule, AudioValidatorRule, HqConflictRule, AudioChannelsValidatorRule)

return rebulk

Expand Down Expand Up @@ -162,3 +165,22 @@ def when(self, matches, context):

if hq_other:
return hq_other


class AudioChannelsValidatorRule(Rule):
"""
Remove audio_channel if no audio codec as previous match.
"""
priority = 128
consequence = RemoveMatch

def when(self, matches, context):
ret = []

for audio_channel in matches.tagged('weak-audio_channels'):
valid_before = matches.range(audio_channel.start - 1, audio_channel.start,
lambda match: match.name == 'audio_codec')
if not valid_before:
ret.append(audio_channel)

return ret
4 changes: 2 additions & 2 deletions guessit/rules/properties/episodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ def season_episode_conflict_solver(match, other):
:param other:
:return:
"""
if match.name == 'episode' and other.name in \
if match.name == 'episode' and 'weak-audio_channels' not in other.tags and other.name in \
['screen_size', 'video_codec', 'audio_codec', 'audio_channels', 'container', 'date', 'year']:
return match
if match.name == 'season' and other.name in \
if match.name == 'season' and 'weak-audio_channels' not in other.tags and other.name in \
['screen_size', 'video_codec', 'audio_codec', 'audio_channels', 'container', 'date']:
return match
if match.name in ['season', 'episode'] and other.name in ['season', 'episode'] \
Expand Down
22 changes: 21 additions & 1 deletion guessit/test/rules/episodes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -249,4 +249,24 @@

? epi
: options: -t episode
title: epi
title: epi

? Episode20
? Episode 20
: episode: 20

? Episode50
? Episode 50
: episode: 50

? Episode51
? Episode 51
: episode: 51

? Episode70
? Episode 70
: episode: 70

? Episode71
? Episode 71
: episode: 71

0 comments on commit c4184af

Please sign in to comment.