Skip to content

Commit

Permalink
Migrate to rebulk 2.0.0
Browse files Browse the repository at this point in the history
This also enhance some rules in season/episodes handling
  • Loading branch information
Toilal committed Aug 29, 2019
1 parent bc65e99 commit a43966a
Show file tree
Hide file tree
Showing 13 changed files with 210 additions and 133 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ python:
- 3.5
- 3.6
- pypy
- pypy3
# - pypy3
matrix:
include:
- python: 3.7
Expand Down
20 changes: 20 additions & 0 deletions guessit/rules/match_processors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"""
Match processors
"""
from guessit.rules.common import seps


def strip(match, chars=seps):
"""
Strip given characters from match.
:param chars:
:param match:
:return:
"""
while match.input_string[match.start] in chars:
match.start += 1
while match.input_string[match.end - 1] in chars:
match.end -= 1
if not match:
return False
15 changes: 10 additions & 5 deletions guessit/rules/properties/audio_codec.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
"""
audio_codec, audio_profile and audio_channels property
"""
from rebulk.remodule import re

from rebulk import Rebulk, Rule, RemoveMatch
from rebulk.remodule import re

from ..common import dash
from ..common.pattern import is_disabled
Expand All @@ -23,7 +22,9 @@ def audio_codec(config): # pylint:disable=unused-argument
:return: Created Rebulk object
:rtype: Rebulk
"""
rebulk = Rebulk().regex_defaults(flags=re.IGNORECASE, abbreviations=[dash]).string_defaults(ignore_case=True)
rebulk = Rebulk()\
.regex_defaults(flags=re.IGNORECASE, abbreviations=[dash])\
.string_defaults(ignore_case=True)

def audio_codec_priority(match1, match2):
"""
Expand Down Expand Up @@ -61,7 +62,9 @@ def audio_codec_priority(match1, match2):
rebulk.string('PCM', value='PCM')
rebulk.string('LPCM', value='LPCM')

rebulk.defaults(name='audio_profile', disabled=lambda context: is_disabled(context, 'audio_profile'))
rebulk.defaults(clear=True,
name='audio_profile',
disabled=lambda context: is_disabled(context, 'audio_profile'))
rebulk.string('MA', value='Master Audio', tags=['audio_profile.rule', 'DTS-HD'])
rebulk.string('HR', 'HRA', value='High Resolution Audio', tags=['audio_profile.rule', 'DTS-HD'])
rebulk.string('ES', value='Extended Surround', tags=['audio_profile.rule', 'DTS'])
Expand All @@ -70,7 +73,9 @@ def audio_codec_priority(match1, match2):
rebulk.string('HQ', value='High Quality', tags=['audio_profile.rule', 'Dolby Digital'])
rebulk.string('EX', value='EX', tags=['audio_profile.rule', 'Dolby Digital'])

rebulk.defaults(name="audio_channels", disabled=lambda context: is_disabled(context, 'audio_channels'))
rebulk.defaults(clear=True,
name="audio_channels",
disabled=lambda context: is_disabled(context, 'audio_channels'))
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')
Expand Down
3 changes: 2 additions & 1 deletion guessit/rules/properties/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ def container(config):
rebulk.regex(r'\.'+build_or_pattern(torrent)+'$', exts=torrent, tags=['extension', 'torrent'])
rebulk.regex(r'\.'+build_or_pattern(nzb)+'$', exts=nzb, tags=['extension', 'nzb'])

rebulk.defaults(name='container',
rebulk.defaults(clear=True,
name='container',
validator=seps_surround,
formatter=lambda s: s.lower(),
conflict_solver=lambda match, other: match
Expand Down
6 changes: 2 additions & 4 deletions guessit/rules/properties/episode_title.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,7 @@ def __init__(self, previous_names):

def hole_filter(self, hole, matches):
episode = matches.previous(hole,
lambda previous: any(name in previous.names
for name in self.previous_names),
lambda previous: previous.named(*self.previous_names),
0)

crc32 = matches.named('crc32')
Expand Down Expand Up @@ -179,8 +178,7 @@ def when(self, matches, context): # pylint:disable=inconsistent-return-statemen
predicate=lambda match: 'title' in match.tags, index=0)
if main_title:
episode = matches.previous(main_title,
lambda previous: any(name in previous.names
for name in self.previous_names),
lambda previous: previous.named(*self.previous_names),
0)

crc32 = matches.named('crc32')
Expand Down
Loading

0 comments on commit a43966a

Please sign in to comment.