# Buggy code
def check_language(self, languages):
    # Cut additional Subtitles
    try:
        languages = languages[: languages.index("+")]
    except IndexError:
        pass

    language_list = re.split(r"[,&]", languages)

    try:
        if self.config["language"] == "german":
            if regex_is_german.search(language_list[0]):
                return True
        elif self.config["language"] == "foreign":
            if (
                regex_is_foreign.search(language_list[0]) and len(language_list) == 1
            ) or (
                len(language_list) > 1
                and not regex_is_subtitle.search(language_list[1])
            ):
                return True
        elif self.config["language"] == "subtitle":
            if len(language_list) > 1 and regex_is_subtitle.search(language_list[1]):
                return True
        elif self.config["language"] == "dual":
            if len(language_list) > 1 and not regex_is_subtitle.search(
                language_list[1]
            ):
                return True
    except (KeyError, re.error):
        pass

    return False


# Traceback (ValueError)
2016-09-16 21:34 DEBUG    urlrewriter   serienjk_de_local Checking 2 entries
2016-09-16 21:34 DEBUG    urlrewriter   serienjk_de_local Url rewriting http://serienjunkies.org/gotham/gotham-staffel-2-blu-ray-sd720p1080p/
2016-09-16 21:34 DEBUG    utils.requests serienjk_de_local Fetching http://serienjunkies.org/gotham/gotham-staffel-2-blu-ray-sd720p1080p/
2016-09-16 21:34 DEBUG    serienjunkies serienjk_de_local Title seems to describe multiple episodes
2016-09-16 21:34 DEBUG    plugin        serienjk_de_local decorator caught ValueError. handled traceback:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/flexget/plugin.py", line 118, in wrapped_func
return func(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/flexget/plugins/sites/serienjunkies.py", line 116, in parse_downloads
if not self.check_language(episode_lang):
File "/usr/local/lib/python2.7/dist-packages/flexget/plugins/sites/serienjunkies.py", line 169, in check_language
languages = languages[:languages.index("+")]
ValueError: substring not found
2016-09-16 21:34 WARNING  urlrewriter   serienjk_de_local URL rewriting serienjunkies failed: substring not found

# Fixed code
def check_language(self, languages):
    # Cut additional Subtitles
    languages = languages.split("|", 1)[0]

    language_list = re.split(r"[,&]", languages)

    try:
        if self.config["language"] == "german":
            if regex_is_german.search(language_list[0]):
                return True
        elif self.config["language"] == "foreign":
            if (
                regex_is_foreign.search(language_list[0]) and len(language_list) == 1
            ) or (
                len(language_list) > 1
                and not regex_is_subtitle.search(language_list[1])
            ):
                return True
        elif self.config["language"] == "subtitle":
            if len(language_list) > 1 and regex_is_subtitle.search(language_list[1]):
                return True
        elif self.config["language"] == "dual":
            if len(language_list) > 1 and not regex_is_subtitle.search(
                language_list[1]
            ):
                return True
    except (KeyError, re.error):
        pass

    return False