mirror of
https://github.com/zoriya/guessit.git
synced 2026-05-31 17:53:08 +00:00
Enhance season/episode guess validation
This commit is contained in:
@@ -15,7 +15,7 @@ from .title import TitleFromPosition
|
||||
from ..common import dash, alt_dash, seps
|
||||
from ..common.formatters import strip
|
||||
from ..common.numeral import numeral, parse_numeral
|
||||
from ..common.validators import compose, seps_surround
|
||||
from ..common.validators import compose, seps_surround, seps_before
|
||||
from ...reutils import build_or_pattern
|
||||
|
||||
|
||||
@@ -58,15 +58,6 @@ def episodes():
|
||||
season_episode_seps.extend(seps)
|
||||
season_episode_seps.extend(['x', 'X', 'e', 'E'])
|
||||
|
||||
def season_episode_validator(match):
|
||||
"""
|
||||
Validator for season/episode matches
|
||||
"""
|
||||
if match.name in ['season', 'episode'] and match.initiator.start:
|
||||
return match.initiator.input_string[match.initiator.start] in season_episode_seps \
|
||||
or match.initiator.input_string[match.initiator.start - 1] in season_episode_seps
|
||||
return True
|
||||
|
||||
season_words = ['season', 'saison', 'serie', 'seasons', 'saisons', 'series']
|
||||
episode_words = ['episode', 'episodes', 'ep']
|
||||
of_words = ['of', 'sur']
|
||||
@@ -96,25 +87,29 @@ def episodes():
|
||||
abbreviations=[alt_dash],
|
||||
children=True,
|
||||
private_parent=True,
|
||||
validate_all=True,
|
||||
validator={'__parent__': ordering_validator},
|
||||
conflict_solver=season_episode_conflict_solver) \
|
||||
.defaults(validate_all=True,
|
||||
validator={'__parent__': ordering_validator,
|
||||
'season': season_episode_validator,
|
||||
'episode': season_episode_validator}) \
|
||||
.regex(build_or_pattern(season_markers) + r'(?P<season>\d+)@?' +
|
||||
build_or_pattern(episode_markers) + r'@?(?P<episode>\d+)') \
|
||||
build_or_pattern(episode_markers) + r'@?(?P<episode>\d+)',
|
||||
validate_all=True,
|
||||
validator={'__parent__': seps_before}) \
|
||||
.regex(r'(?:(?P<episodeSeparator>' +
|
||||
build_or_pattern(episode_markers + discrete_separators + range_separators) + ')' +
|
||||
r'(?P<episode>\d+))').repeater('*') \
|
||||
.chain() \
|
||||
.regex(r'(?P<season>\d+)@?' +
|
||||
build_or_pattern(season_ep_markers) +
|
||||
r'@?(?P<episode>\d+)') \
|
||||
r'@?(?P<episode>\d+)',
|
||||
validate_all=True,
|
||||
validator={'__parent__': seps_before}) \
|
||||
.regex(r'(?:(?P<episodeSeparator>' +
|
||||
build_or_pattern(season_ep_markers + discrete_separators + range_separators) + ')' +
|
||||
r'(?P<episode>\d+))').repeater('*') \
|
||||
.chain() \
|
||||
.regex(build_or_pattern(season_markers) + r'(?P<season>\d+)') \
|
||||
.regex(build_or_pattern(season_markers) + r'(?P<season>\d+)',
|
||||
validate_all=True,
|
||||
validator={'__parent__': seps_before}) \
|
||||
.regex(r'(?:(?P<seasonSeparator>' +
|
||||
build_or_pattern(season_markers + discrete_separators + range_separators) + ')' +
|
||||
r'(?P<season>\d+))').repeater('*')
|
||||
|
||||
@@ -42,6 +42,8 @@ def title():
|
||||
search = search.replace(' ', '-')
|
||||
matches = RePattern(search, abbreviations=[dash], flags=re.IGNORECASE).matches(input_string, context)
|
||||
for match in matches:
|
||||
# Instance of 'list' has no 'span' member (no-member). Seems to be a pylint bug.
|
||||
# pylint: disable=no-member
|
||||
ret.append(match.span)
|
||||
else:
|
||||
for start in find_all(input_string, search, ignore_case=True):
|
||||
|
||||
@@ -16,7 +16,7 @@ with io.open(os.path.join(here, 'README.rst'), encoding='utf-8') as f:
|
||||
with io.open(os.path.join(here, 'HISTORY.rst'), encoding='utf-8') as f:
|
||||
history = f.read()
|
||||
|
||||
install_requires = ['rebulk>=0.7.5', 'babelfish>=0.5.5', 'python-dateutil']
|
||||
install_requires = ['rebulk>=0.7.6', 'babelfish>=0.5.5', 'python-dateutil']
|
||||
if sys.version_info < (2, 7):
|
||||
install_requires.extend(['argparse', 'ordereddict'])
|
||||
setup_requires = ['pytest-runner']
|
||||
|
||||
Reference in New Issue
Block a user