From 606fe40fef127137c4d7638ca628a50e0fb144fd Mon Sep 17 00:00:00 2001 From: Toilal Date: Sun, 18 Sep 2016 22:38:47 +0200 Subject: [PATCH] Enhance season/episode guess validation --- guessit/rules/properties/episodes.py | 29 ++++++++++++---------------- guessit/rules/properties/title.py | 2 ++ setup.py | 2 +- 3 files changed, 15 insertions(+), 18 deletions(-) diff --git a/guessit/rules/properties/episodes.py b/guessit/rules/properties/episodes.py index 6432e28..c4a9098 100644 --- a/guessit/rules/properties/episodes.py +++ b/guessit/rules/properties/episodes.py @@ -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\d+)@?' + - build_or_pattern(episode_markers) + r'@?(?P\d+)') \ + build_or_pattern(episode_markers) + r'@?(?P\d+)', + validate_all=True, + validator={'__parent__': seps_before}) \ .regex(r'(?:(?P' + build_or_pattern(episode_markers + discrete_separators + range_separators) + ')' + r'(?P\d+))').repeater('*') \ .chain() \ .regex(r'(?P\d+)@?' + build_or_pattern(season_ep_markers) + - r'@?(?P\d+)') \ + r'@?(?P\d+)', + validate_all=True, + validator={'__parent__': seps_before}) \ .regex(r'(?:(?P' + build_or_pattern(season_ep_markers + discrete_separators + range_separators) + ')' + r'(?P\d+))').repeater('*') \ .chain() \ - .regex(build_or_pattern(season_markers) + r'(?P\d+)') \ + .regex(build_or_pattern(season_markers) + r'(?P\d+)', + validate_all=True, + validator={'__parent__': seps_before}) \ .regex(r'(?:(?P' + build_or_pattern(season_markers + discrete_separators + range_separators) + ')' + r'(?P\d+))').repeater('*') diff --git a/guessit/rules/properties/title.py b/guessit/rules/properties/title.py index 79f531b..067d432 100644 --- a/guessit/rules/properties/title.py +++ b/guessit/rules/properties/title.py @@ -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): diff --git a/setup.py b/setup.py index 53cc322..ef0ae96 100644 --- a/setup.py +++ b/setup.py @@ -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']