# Buggy code
def want_episode(
    self, season, episode, quality, forced_search=False, download_current_quality=False
):
    """Whether or not the episode with the specified quality is wanted.

    :param season:
    :type season: int
    :param episode:
    :type episode: int
    :param quality:
    :type quality: int
    :param forced_search:
    :type forced_search: bool
    :param download_current_quality:
    :type download_current_quality: bool
    :return:
    :rtype: bool
    """
    # if the quality isn't one we want under any circumstances then just say no
    allowed_qualities, preferred_qualities = self.current_qualities
    logger.debug(
        "{id}: Allowed, Preferred = [ {allowed} ] [ {preferred} ] Found = [ {found} ]",
        id=self.indexerid,
        allowed=self.__qualities_to_string(allowed_qualities),
        preferred=self.__qualities_to_string(preferred_qualities),
        found=self.__qualities_to_string([quality]),
    )

    if not Quality.wanted_quality(quality, allowed_qualities, preferred_qualities):
        logger.debug(
            "{id}: Ignoring found result for '{show}' {ep} with unwanted quality '{quality}'",
            id=self.indexerid,
            show=self.name,
            ep=episode_num(season, episode),
            quality=Quality.qualityStrings[quality],
        )
        return False

    main_db_con = db.DBConnection()
    sql_results = main_db_con.select(
        b"SELECT "
        b"  status, "
        b"  manually_searched "
        b"FROM "
        b"  tv_episodes "
        b"WHERE "
        b"  showid = ? "
        b"  AND season = ? "
        b"  AND episode = ?",
        [self.indexerid, season, episode],
    )

    if not sql_results or not len(sql_results):
        logger.debug(
            "{id}: Unable to find a matching episode in database. "
            "Ignoring found result for '{show}' {ep} with quality '{quality}'",
            id=self.indexerid,
            show=self.name,
            ep=episode_num(season, episode),
            quality=Quality.qualityStrings[quality],
        )
        return False

    ep_status = int(sql_results[0][b"status"])
    ep_status_text = statusStrings[ep_status].upper()
    manually_searched = sql_results[0][b"manually_searched"]
    _, cur_quality = Quality.split_composite_status(ep_status)

    # if it's one of these then we want it as long as it's in our allowed initial qualities
    if ep_status == WANTED:
        logger.debug(
            "{id}: '{show}' {ep} status is 'WANTED'. Accepting result with quality '{new_quality}'",
            id=self.indexerid,
            status=ep_status_text,
            show=self.name,
            ep=episode_num(season, episode),
            new_quality=Quality.qualityStrings[quality],
        )
        return True

    should_replace, msg = Quality.should_replace(
        ep_status,
        cur_quality,
        quality,
        allowed_qualities,
        preferred_qualities,
        download_current_quality,
        forced_search,
        manually_searched,
    )
    logger.debug(
        "{id}: '{show}' {ep} status is: '{status}'. {action} result with quality '{new_quality}'. "
        "Reason: {msg}",
        id=self.indexerid,
        show=self.name,
        ep=episode_num(season, episode),
        status=ep_status_text,
        action="Accepting" if should_replace else "Ignoring",
        new_quality=Quality.qualityStrings[quality],
        msg=msg,
    )
    return should_replace


# Traceback (TypeError)
2017-02-21 12:37:29 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [TorrentProject] :: [54bddc5] Transaction with 76 queries executed
2017-02-21 12:37:27 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [ExtraTorrent] :: [54bddc5] Traceback (most recent call last):
File "C:\Gits\Medusa\medusa\search\core.py", line 423, in search_for_needed_episodes
cur_found_results = cur_provider.search_rss(episodes)
File "C:\Gits\Medusa\medusa\providers\generic_provider.py", line 472, in search_rss
return self.cache.find_needed_episodes(episodes)
File "C:\Gits\Medusa\medusa\tv\cache.py", line 566, in find_needed_episodes
forced_search, down_cur_quality):
File "C:\Gits\Medusa\medusa\tv\series.py", line 1832, in want_episode
new_quality=Quality.qualityStrings[quality], msg=msg)
TypeError: debug() got multiple values for keyword argument 'msg'
2017-02-21 12:37:27 ERROR    SEARCHQUEUE-DAILY-SEARCH :: [ExtraTorrent] :: [54bddc5] Error while searching ExtraTorrent, skipping: debug() got multiple values for keyword argument 'msg'
Traceback (most recent call last):
File "C:\Gits\Medusa\medusa\search\core.py", line 423, in search_for_needed_episodes
cur_found_results = cur_provider.search_rss(episodes)
File "C:\Gits\Medusa\medusa\providers\generic_provider.py", line 472, in search_rss
return self.cache.find_needed_episodes(episodes)
File "C:\Gits\Medusa\medusa\tv\cache.py", line 566, in find_needed_episodes
forced_search, down_cur_quality):
File "C:\Gits\Medusa\medusa\tv\series.py", line 1832, in want_episode
new_quality=Quality.qualityStrings[quality], msg=msg)
TypeError: debug() got multiple values for keyword argument 'msg'
2017-02-21 12:37:27 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [ExtraTorrent] :: [54bddc5] 295683: Allowed, Preferred = [ 720p HDTV, 720p WEB-DL, 720p BluRay ] [ None ] Found = [ 720p HDTV ]
2017-02-21 12:37:27 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [ExtraTorrent] :: [54bddc5] Parsed 'Rosewood.S02E08.720p.HDTV.x264-FLEET[PRiME]' into title: Rosewood, season: 2, episode: [8], screen_size: 720p, format: HDTV, video_codec: h264, video_encoder: x264, release_group: FLEET, type: episode, parsing_time: 0.0269999504089, total_time: 0.0279998779297, absolute_episode: [], quality: 720p HDTV
2017-02-21 12:37:27 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [ExtraTorrent] :: [54bddc5] Matched release 'Rosewood.S02E08.720p.HDTV.x264-FLEET[PRiME]' to a show in your database: 'Rosewood'
2017-02-21 12:37:27 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [ExtraTorrent] :: [54bddc5] Transaction with 76 queries executed
2017-02-21 12:37:27 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Torrentz2] :: [54bddc5] Traceback (most recent call last):
File "C:\Gits\Medusa\medusa\search\core.py", line 423, in search_for_needed_episodes
cur_found_results = cur_provider.search_rss(episodes)
File "C:\Gits\Medusa\medusa\providers\generic_provider.py", line 472, in search_rss
return self.cache.find_needed_episodes(episodes)
File "C:\Gits\Medusa\medusa\tv\cache.py", line 566, in find_needed_episodes
forced_search, down_cur_quality):
File "C:\Gits\Medusa\medusa\tv\series.py", line 1832, in want_episode
new_quality=Quality.qualityStrings[quality], msg=msg)
TypeError: debug() got multiple values for keyword argument 'msg'
2017-02-21 12:37:27 ERROR    SEARCHQUEUE-DAILY-SEARCH :: [Torrentz2] :: [54bddc5] Error while searching Torrentz2, skipping: debug() got multiple values for keyword argument 'msg'
Traceback (most recent call last):
File "C:\Gits\Medusa\medusa\search\core.py", line 423, in search_for_needed_episodes
cur_found_results = cur_provider.search_rss(episodes)
File "C:\Gits\Medusa\medusa\providers\generic_provider.py", line 472, in search_rss
return self.cache.find_needed_episodes(episodes)
File "C:\Gits\Medusa\medusa\tv\cache.py", line 566, in find_needed_episodes
forced_search, down_cur_quality):
File "C:\Gits\Medusa\medusa\tv\series.py", line 1832, in want_episode
new_quality=Quality.qualityStrings[quality], msg=msg)
TypeError: debug() got multiple values for keyword argument 'msg'
2017-02-21 12:37:27 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Torrentz2] :: [54bddc5] 295683: Allowed, Preferred = [ 720p HDTV, 720p WEB-DL, 720p BluRay ] [ None ] Found = [ 720p HDTV ]
2017-02-21 12:37:27 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Torrentz2] :: [54bddc5] Parsed 'Rosewood.S02E08.720p.HDTV.x264-FLEET[eztv].mkv' into title: Rosewood, season: 2, episode: [8], screen_size: 720p, format: HDTV, video_codec: h264, video_encoder: x264, release_group: FLEET, container: mkv, mimetype: video/x-matroska, type: episode, parsing_time: 0.0280001163483, total_time: 0.0280001163483, absolute_episode: [], quality: 720p HDTV
2017-02-21 12:37:27 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Torrentz2] :: [54bddc5] Matched release 'Rosewood.S02E08.720p.HDTV.x264-FLEET[eztv].mkv' to a show in your database: 'Rosewood'
2017-02-21 12:37:27 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Torrentz2] :: [54bddc5] Transaction with 76 queries executed

# Fixed code
def want_episode(
    self, season, episode, quality, forced_search=False, download_current_quality=False
):
    """Whether or not the episode with the specified quality is wanted.

    :param season:
    :type season: int
    :param episode:
    :type episode: int
    :param quality:
    :type quality: int
    :param forced_search:
    :type forced_search: bool
    :param download_current_quality:
    :type download_current_quality: bool
    :return:
    :rtype: bool
    """
    # if the quality isn't one we want under any circumstances then just say no
    allowed_qualities, preferred_qualities = self.current_qualities
    logger.debug(
        "{id}: Allowed, Preferred = [ {allowed} ] [ {preferred} ] Found = [ {found} ]",
        id=self.indexerid,
        allowed=self.__qualities_to_string(allowed_qualities),
        preferred=self.__qualities_to_string(preferred_qualities),
        found=self.__qualities_to_string([quality]),
    )

    if not Quality.wanted_quality(quality, allowed_qualities, preferred_qualities):
        logger.debug(
            "{id}: Ignoring found result for '{show}' {ep} with unwanted quality '{quality}'",
            id=self.indexerid,
            show=self.name,
            ep=episode_num(season, episode),
            quality=Quality.qualityStrings[quality],
        )
        return False

    main_db_con = db.DBConnection()
    sql_results = main_db_con.select(
        b"SELECT "
        b"  status, "
        b"  manually_searched "
        b"FROM "
        b"  tv_episodes "
        b"WHERE "
        b"  showid = ? "
        b"  AND season = ? "
        b"  AND episode = ?",
        [self.indexerid, season, episode],
    )

    if not sql_results or not len(sql_results):
        logger.debug(
            "{id}: Unable to find a matching episode in database. "
            "Ignoring found result for '{show}' {ep} with quality '{quality}'",
            id=self.indexerid,
            show=self.name,
            ep=episode_num(season, episode),
            quality=Quality.qualityStrings[quality],
        )
        return False

    ep_status = int(sql_results[0][b"status"])
    ep_status_text = statusStrings[ep_status].upper()
    manually_searched = sql_results[0][b"manually_searched"]
    _, cur_quality = Quality.split_composite_status(ep_status)

    # if it's one of these then we want it as long as it's in our allowed initial qualities
    if ep_status == WANTED:
        logger.debug(
            "{id}: '{show}' {ep} status is 'WANTED'. Accepting result with quality '{new_quality}'",
            id=self.indexerid,
            status=ep_status_text,
            show=self.name,
            ep=episode_num(season, episode),
            new_quality=Quality.qualityStrings[quality],
        )
        return True

    should_replace, reason = Quality.should_replace(
        ep_status,
        cur_quality,
        quality,
        allowed_qualities,
        preferred_qualities,
        download_current_quality,
        forced_search,
        manually_searched,
    )
    logger.debug(
        "{id}: '{show}' {ep} status is: '{status}'. {action} result with quality '{new_quality}'. "
        "Reason: {reason}",
        id=self.indexerid,
        show=self.name,
        ep=episode_num(season, episode),
        status=ep_status_text,
        action="Accepting" if should_replace else "Ignoring",
        new_quality=Quality.qualityStrings[quality],
        reason=reason,
    )
    return should_replace