wackou/guessit — pull request #161 by Nikola-K (2014-09-28 13:55:36+00:00)
Title: guess_language exception fix

The `guess_language.py` will raise an exception if `lang_node.value` is not in `mtree.clean_string(lang_node.root.value).split()`. (see traceback at the end)

In `clean_default` function of `textutils.py` (which is called on `mtree.clean_string()`) because of `if c in ['-', ',']: continue` the language (the same one as in `lang_node.value`) is not always separated from the file title and returned value can look like `filename-eng` which when `split` will not have language in it.

This caused the following if statement in `guess_language.py` to raise an exception:

if (m.get('type') in ['moviesubtitle', 'episodesubtitle'] and (parts.index(lang_node.value) == len(parts) - 2)):
continue

This pull requests just splits that if statement into two if statements keeping `type` checking in first one and in second one checking whether `lang_node.value` exists in `parts`, which will not raise an exception if it doesn't. Maybe an `try`/`except` block would have been better solution, but wrapping the whole function into `try`/`except` makes multiple tests fail, and this seems like good enough compromise.

Example of filename that caused such exception is also added to the `episodes.yaml`.

This change does not affect other files, nor does it increase rate of false positives.

All test pass.

Exception traceback that's fixed:

$ guessit "Episode 4 - Kim Kelly Is My Friend-eng(1).srt"
For: Episode 4 - Kim Kelly Is My Friend-eng(1).srt
Traceback (most recent call last):
File "/usr/local/bin/guessit", line 9, in
load_entry_point('guessit==0.9.3', 'console_scripts', 'guessit')()
File "/usr/local/lib/python2.7/dist-packages/guessit/__main__.py", line 275, in main
options=vars(options))
File "/usr/local/lib/python2.7/dist-packages/guessit/__main__.py", line 39, in guess_file
guess = guess_file_info(filename, info, options, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/guessit/__init__.py", line 288, in guess_file_info
result.append(_guess_filename(filename, options, **kwargs))
File "/usr/local/lib/python2.7/dist-packages/guessit/__init__.py", line 111, in _guess_filename
mtree = _build_filename_mtree(filename, options=options, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/guessit/__init__.py", line 119, in _build_filename_mtree
second_pass_options = mtree.second_pass_options
File "/usr/local/lib/python2.7/dist-packages/guessit/matcher.py", line 147, in second_pass_options
transformer_second_pass_options = transformer.second_pass_options(self.match_tree, self.options)
File "/usr/local/lib/python2.7/dist-packages/guessit/transfo/guess_language.py", line 101, in second_pass_options
(parts.index(lang_node.value) == len(parts) - 2)):
ValueError: u'eng' is not in list