Skip to content

Commit

Permalink
Add better support for -T option
Browse files Browse the repository at this point in the history
  • Loading branch information
Toilal committed Nov 23, 2015
1 parent 2f74c35 commit 27898a9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
19 changes: 15 additions & 4 deletions guessit/rules/properties/title.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@
"""
from __future__ import unicode_literals

import re

from guessit.rules.properties.film import FilmTitleRule
from guessit.rules.properties.language import SubtitlePrefixLanguageRule, SubtitleSuffixLanguageRule, \
SubtitleExtensionRule
from rebulk import Rebulk, Rule, AppendMatch, RemoveMatch, AppendTags
from rebulk.formatters import formatters

from rebulk.pattern import RePattern
from ..common.formatters import cleanup, reorder_title
from ..common.comparators import marker_sorted
from ..common import seps, title_seps
from ..common import seps, title_seps, dash
from rebulk.utils import find_all


Expand All @@ -35,9 +37,18 @@ def expected_title(input_string, context):
:return:
:rtype:
"""
ret = []
for search in context.get('expected_title'):
for start in find_all(input_string, search, ignore_case=True):
return start, start+len(search)
if search.startswith('re:'):
search = search[3:]
search = search.replace(' ', '-')
matches = RePattern(search, abbreviations=[dash], flags=re.IGNORECASE).matches(input_string, context)
for match in matches:
ret.append(match.span)
else:
for start in find_all(input_string, search, ignore_case=True):
ret.append((start, start+len(search)))
return ret

rebulk.functional(expected_title, name='title', tags=['expected'],
conflict_solver=lambda match, other: other,
Expand Down
2 changes: 1 addition & 1 deletion guessit/test/episodes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1675,6 +1675,6 @@
screen_size: 720p

? -my 720p show S01E02
: options: -T "my 720p show"
: options: -T "re:my \d+p show"
screen_size: 720p

0 comments on commit 27898a9

Please sign in to comment.