Skip to content

Commit

Permalink
Fix infinit loop when filename contains multiple languages ISO codes
Browse files Browse the repository at this point in the history
This also adds ice as a common english word, avoiding detected ice as icelandic language.

Close #170
  • Loading branch information
Toilal committed Nov 10, 2014
1 parent 7166dd7 commit 4d1d40e
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 9 deletions.
2 changes: 1 addition & 1 deletion guessit/language.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def reverse(self, name):
'no', 'non', 'war', 'min', 'new', 'car', 'day', 'bad', 'bat', 'fan',
'fry', 'cop', 'zen', 'gay', 'fat', 'one', 'cherokee', 'got', 'an', 'as',
'cat', 'her', 'be', 'hat', 'sun', 'may', 'my', 'mr', 'rum', 'pi', 'bb', 'bt',
'tv', 'aw', 'by', 'md', 'mp', 'cd', 'lt', 'gt', 'in', 'ad',
'tv', 'aw', 'by', 'md', 'mp', 'cd', 'lt', 'gt', 'in', 'ad', 'ice',
# french words
'bas', 'de', 'le', 'son', 'ne', 'ca', 'ce', 'et', 'que',
'mal', 'est', 'vol', 'or', 'mon', 'se', 'je', 'tu', 'me',
Expand Down
26 changes: 19 additions & 7 deletions guessit/matcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,15 @@ def log_found_guess(guess, logger=None):
(k, v, guess.raw(k), guess.confidence(k)))


def _get_split_spans(node, span):
partition_spans = node.get_partition_spans(span)
for to_remove_span in partition_spans:
if to_remove_span[0] == span[0] and to_remove_span[1] in [span[1], span[1] + 1]:
partition_spans.remove(to_remove_span)
break
return partition_spans


class GuessFinder(object):
def __init__(self, guess_func, confidence=None, logger=None, options=None):
self.guess_func = guess_func
Expand Down Expand Up @@ -243,13 +252,16 @@ def process_node(self, node, iterative=True, partial_span=None):
for skip_node in skip_nodes:
if skip_node.parent.node_idx == node.node_idx[:len(skip_node.parent.node_idx)] and\
skip_node.span == span or\
skip_node.span == (span[0] + skip_node.offset, span[1] + skip_node.offset):
partition_spans = node.get_partition_spans(skip_node.span)
for to_remove_span in partition_spans:
if to_remove_span[0] == skip_node.span[0] and to_remove_span[1] in [skip_node.span[1], skip_node.span[1] + 1]:
partition_spans.remove(to_remove_span)
break
#break
skip_node.span == (span[0] + skip_node.offset, span[1] + skip_node.offset):
if partition_spans is None:
partition_spans = _get_split_spans(node, skip_node.span)
else:
new_partition_spans = []
for partition_span in partition_spans:
tmp_node = MatchTree(value, span=partition_span, parent=node)
tmp_partitions_spans = _get_split_spans(tmp_node, skip_node.span)
new_partition_spans.extend(tmp_partitions_spans)
partition_spans.extend(new_partition_spans)

if not partition_spans:
# restore sentinels compensation
Expand Down
14 changes: 13 additions & 1 deletion guessit/test/autodetect.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -458,4 +458,16 @@
series: The Flash
type: episode
videoCodec: XviD
year: 2014
year: 2014

? Ice.Lake.Rebels.S01E06.Ice.Lake.Games.720p.HDTV.x264-DHD
: options: -n
episodeNumber: 6
format: HDTV
releaseGroup: DHD
screenSize: 720p
season: 1
series: Ice Lake Rebels
title: Ice Lake Games
type: episode
videoCodec: h264

0 comments on commit 4d1d40e

Please sign in to comment.