# Buggy code
def _get_show_data(self, sid, language="en"):
    """Take a series ID, gets the epInfo URL and parses the TMDB json response.

    into the shows dict in layout:
    shows[series_id][season_number][episode_number]
    """
    if self.config["language"] is None:
        log.debug("Config language is none, using show language")
        if language is None:
            raise IndexerError("config['language'] was None, this should not happen")
        get_show_in_language = language
    else:
        log.debug(
            "Configured language {0} override show language of {1}",
            self.config["language"],
            language,
        )
        get_show_in_language = self.config["language"]

    # Parse show information
    log.debug("Getting all series data for {0}", sid)

    # Parse show information
    series_info = self._get_show_by_id(sid, request_language=get_show_in_language)

    if not series_info:
        log.debug("Series result returned zero")
        raise IndexerError("Series result returned zero")

    # get series data / add the base_url to the image urls
    # Create a key/value dict, to map the image type to a default image width.
    # possitlbe widths can also be retrieved from self.configuration.images['poster_sizes'] and
    # self.configuration.images['still_sizes']
    image_width = {"fanart": "w1280", "poster": "w500"}

    for k, v in viewitems(series_info["series"]):
        if v is not None:
            if k in ["fanart", "banner", "poster"]:
                v = self.config["artwork_prefix"].format(
                    base_url=self.tmdb_configuration.images["base_url"],
                    image_size=image_width[k],
                    file_path=v,
                )

        self._set_show_data(sid, k, v)

    # Get external ids.
    # As the external id's are not part of the shows default response, we need to make an additional call for it.
    self._set_show_data(sid, "externals", self.tmdb.TV(sid).external_ids())

    # get episode data
    if self.config["episodes_enabled"]:
        self._get_episodes(sid, specials=False, aired_season=None)

    # Parse banners
    if self.config["banners_enabled"]:
        self._parse_images(sid)

    # Parse actors
    if self.config["actors_enabled"]:
        self._parse_actors(sid)

    return True


# Traceback (ZeroDivisionError)
2018-04-14 23:42:05 DEBUG    ThreadPoolExecutor-0_1 :: [b4c38d5] 78783: Saving to database: Hunting Nazi Treasure
2018-04-14 23:42:20 DEBUG    ThreadPoolExecutor-0_1 :: [b4c38d5] 78783: Queueing show refresh for Hunting Nazi Treasure
2018-04-14 23:42:20 DEBUG    ThreadPoolExecutor-0_1 :: [b4c38d5] Finished editing show: Hunting Nazi Treasure
2018-04-14 23:42:22 INFO     SHOWQUEUE-REFRESH :: [b4c38d5] 78783: Performing refresh on Hunting Nazi Treasure
2018-04-14 23:42:22 DEBUG    SHOWQUEUE-REFRESH :: [b4c38d5] 78783: Loading all episodes from the show directory: /media/ssd/Shows/Hunting Nazi Treasure
2018-04-14 23:42:22 DEBUG    SHOWQUEUE-REFRESH :: [b4c38d5] 78783: Found files: [u'/media/ssd/Shows/Hunting Nazi Treasure/Hunting.Nazi.Treasure.S01E01.Pilot.HDTV.x264-CAFFEiNE.mkv', u'/media/ssd/Shows/Hunting Nazi Treasure/Hunting.Nazi.Treasure.S01E02.The.Mystery.of.Rommels.Gold.HDTV.x264-CAFFEiNE.mkv', u'/media/ssd/Shows/Hunting Nazi Treasure/Hunting.Nazi.Treasure.S01E03.Hitlers.Obsession.HDTV.x264-CAFFEiNE.mkv', u'/media/ssd/Shows/Hunting Nazi Treasure/Hunting.Nazi.Treasure.S01E04.Nazi.Gold.HDTV.x264-CAFFEiNE.mkv', u'/media/ssd/Shows/Hunting Nazi Treasure/Hunting.Nazi.Treasure.S01E06.Blood.Treasure.HDTV.x264-CAFFEiNE.mkv', u'/media/ssd/Shows/Hunting Nazi Treasure/Hunting.Nazi.Treasure.S01E07.City.of.Loot.HDTV.x264-CAFFEiNE.mkv', u'/media/ssd/Shows/Hunting Nazi Treasure/Hunting.Nazi.Treasure.S01E08.Stealing.Italy.HDTV.x264-CAFFEiNE.mkv']
2018-04-14 23:42:22 DEBUG    SHOWQUEUE-REFRESH :: [b4c38d5] 78783: Creating episode from: /media/ssd/Shows/Hunting Nazi Treasure/Hunting.Nazi.Treasure.S01E01.Pilot.HDTV.x264-CAFFEiNE.mkv
2018-04-14 23:42:22 DEBUG    SHOWQUEUE-REFRESH :: [b4c38d5] 78783: Creating episode object from /media/ssd/Shows/Hunting Nazi Treasure/Hunting.Nazi.Treasure.S01E01.Pilot.HDTV.x264-CAFFEiNE.mkv
2018-04-14 23:42:22 DEBUG    SHOWQUEUE-REFRESH :: [b4c38d5] Scene numbering enabled series Hunting Nazi Treasure using indexer numbering: S01E01
2018-04-14 23:42:22 DEBUG    SHOWQUEUE-REFRESH :: [b4c38d5] Converted parsed result /media/ssd/Shows/Hunting Nazi Treasure/Hunting.Nazi.Treasure.S01E01.Pilot.HDTV.x264-CAFFEiNE.mkv into title: Hunting Nazi Treasure, season: 1, episode: [1], episode_title: Pilot, episode_details: Pilot, format: HDTV, video_codec: h264, video_encoder: x264, release_group: CAFFEiNE, container: mkv, mimetype: video/x-matroska, type: episode, parsing_time: 0.366448879242, total_time: None, absolute_episode: [], quality: SDTV
2018-04-14 23:42:22 DEBUG    SHOWQUEUE-REFRESH :: [b4c38d5] Matched release /media/ssd/Shows/Hunting Nazi Treasure/Hunting.Nazi.Treasure.S01E01.Pilot.HDTV.x264-CAFFEiNE.mkv to a series in your database: Hunting Nazi Treasure
2018-04-14 23:42:22 DEBUG    SHOWQUEUE-REFRESH :: [b4c38d5] Parsed /media/ssd/Shows/Hunting Nazi Treasure/Hunting.Nazi.Treasure.S01E01.Pilot.HDTV.x264-CAFFEiNE.mkv into title: Hunting Nazi Treasure, season: 1, episode: [1], episode_title: Pilot, episode_details: Pilot, format: HDTV, video_codec: h264, video_encoder: x264, release_group: CAFFEiNE, container: mkv, mimetype: video/x-matroska, type: episode, parsing_time: 0.366448879242, total_time: 0.390615940094, absolute_episode: [], quality: SDTV
2018-04-14 23:42:22 DEBUG    SHOWQUEUE-REFRESH :: [b4c38d5] 78783: /media/ssd/Shows/Hunting Nazi Treasure/Hunting.Nazi.Treasure.S01E01.Pilot.HDTV.x264-CAFFEiNE.mkv parsed to Hunting Nazi Treasure S01E01
2018-04-14 23:42:22 DEBUG    SHOWQUEUE-REFRESH :: [b4c38d5] 78783: Setter sets location to /media/ssd/Shows/Hunting Nazi Treasure/Hunting.Nazi.Treasure.S01E01.Pilot.HDTV.x264-CAFFEiNE.mkv
2018-04-14 23:42:22 DEBUG    SHOWQUEUE-REFRESH :: [b4c38d5] Checking if /media/ssd/Shows/Hunting Nazi Treasure/Hunting.Nazi.Treasure.S01E01.Pilot.HDTV.x264-CAFFEiNE.nfo exists: True
2018-04-14 23:42:22 DEBUG    SHOWQUEUE-REFRESH :: [b4c38d5] Checking if /media/ssd/Shows/Hunting Nazi Treasure/Hunting.Nazi.Treasure.S01E01.Pilot.HDTV.x264-CAFFEiNE-thumb.jpg exists: False
2018-04-14 23:42:22 DEBUG    SHOWQUEUE-REFRESH :: [b4c38d5] 78783: Setter sets location to /media/ssd/Shows/Hunting Nazi Treasure/Hunting.Nazi.Treasure.S01E01.Pilot.HDTV.x264-CAFFEiNE.mkv
2018-04-14 23:42:22 DEBUG    SHOWQUEUE-REFRESH :: [b4c38d5] Checking if /media/ssd/Shows/Hunting Nazi Treasure/Hunting.Nazi.Treasure.S01E01.Pilot.HDTV.x264-CAFFEiNE.nfo exists: True
2018-04-14 23:42:22 DEBUG    SHOWQUEUE-REFRESH :: [b4c38d5] Checking if /media/ssd/Shows/Hunting Nazi Treasure/Hunting.Nazi.Treasure.S01E01.Pilot.HDTV.x264-CAFFEiNE-thumb.jpg exists: False
2018-04-14 23:42:22 DEBUG    SHOWQUEUE-REFRESH :: [b4c38d5] 78783: Not changing current status 'Downloaded (SDTV)' based on file: /media/ssd/Shows/Hunting Nazi Treasure/Hunting.Nazi.Treasure.S01E01.Pilot.HDTV.x264-CAFFEiNE.mkv. Reason: New file is the same as current file
2018-04-14 23:42:23 DEBUG    SHOWQUEUE-REFRESH :: [b4c38d5] Transaction with 1 queries executed
2018-04-14 23:42:23 DEBUG    SHOWQUEUE-REFRESH :: [b4c38d5] Checking if /media/ssd/Shows/Hunting Nazi Treasure/Hunting.Nazi.Treasure.S01E01.Pilot.HDTV.x264-CAFFEiNE.nfo exists: True
2018-04-14 23:42:23 DEBUG    SHOWQUEUE-REFRESH :: [b4c38d5] Checking if /media/ssd/Shows/Hunting Nazi Treasure/Hunting.Nazi.Treasure.S01E01.Pilot.HDTV.x264-CAFFEiNE-thumb.jpg exists: False
2018-04-14 23:42:23 DEBUG    SHOWQUEUE-REFRESH :: [b4c38d5] Matched release /media/ssd/Shows/Hunting Nazi Treasure/Hunting.Nazi.Treasure.S01E01.Pilot.HDTV.x264-CAFFEiNE to a series in your database: Hunting Nazi Treasure
2018-04-14 23:42:23 DEBUG    SHOWQUEUE-REFRESH :: [b4c38d5] Parsed /media/ssd/Shows/Hunting Nazi Treasure/Hunting.Nazi.Treasure.S01E01.Pilot.HDTV.x264-CAFFEiNE into title: Hunting Nazi Treasure, season: 1, episode: [1], episode_title: Pilot, episode_details: Pilot, format: HDTV, video_codec: h264, video_encoder: x264, release_group: CAFFEiNE, type: episode, parsing_time: 0.411699056625, total_time: 0.412950992584, absolute_episode: [], quality: SDTV
2018-04-14 23:42:24 DEBUG    SHOWQUEUE-REFRESH :: [b4c38d5] Matched release Hunting.Nazi.Treasure.S01E01.Pilot.HDTV.x264-CAFFEiNE to a series in your database: Hunting Nazi Treasure
2018-04-14 23:42:24 DEBUG    SHOWQUEUE-REFRESH :: [b4c38d5] Parsed Hunting.Nazi.Treasure.S01E01.Pilot.HDTV.x264-CAFFEiNE into title: Hunting Nazi Treasure, season: 1, episode: [1], episode_title: Pilot, episode_details: Pilot, format: HDTV, video_codec: h264, video_encoder: x264, release_group: CAFFEiNE, type: episode, parsing_time: 0.245923995972, total_time: 0.247278928757, absolute_episode: [], quality: SDTV
2018-04-14 23:42:24 DEBUG    SHOWQUEUE-REFRESH :: [b4c38d5] Found codec for Hunting Nazi Treasure Pilot
2018-04-14 23:42:24 DEBUG    SHOWQUEUE-REFRESH :: [b4c38d5] 78783: Formatting pattern: %SN - S%0SE01 - %EN -> Hunting Nazi Treasure - S01E01 - Pilot
2018-04-14 23:42:24 DEBUG    SHOWQUEUE-REFRESH :: [b4c38d5] Metadata provider KODI 12+ creating episode thumbnail for Hunting Nazi Treasure - S01E01 - Pilot
2018-04-14 23:42:24 DEBUG    SHOWQUEUE-REFRESH :: [b4c38d5] 78783: Using language from show settings: en
2018-04-14 23:42:24 DEBUG    SHOWQUEUE-REFRESH :: [b4c38d5] GET URL: https://api.themoviedb.org/3/configuration?api_key=**********
2018-04-14 23:42:24 DEBUG    SHOWQUEUE-REFRESH :: [b4c38d5] User-Agent: Medusa/0.1.23 (Linux; 4.9.35-v7+; 5b3a1fbc-4032-11e8-8594-b827eb6b4d4c)
2018-04-14 23:42:24 DEBUG    SHOWQUEUE-REFRESH :: [b4c38d5] 78783: Using language from show settings: en
2018-04-14 23:42:24 DEBUG    SHOWQUEUE-REFRESH :: [b4c38d5] GET URL: https://api.themoviedb.org/3/configuration?api_key=**********
2018-04-14 23:42:24 DEBUG    SHOWQUEUE-REFRESH :: [b4c38d5] User-Agent: Medusa/0.1.23 (Linux; 4.9.35-v7+; 5b3a1fbc-4032-11e8-8594-b827eb6b4d4c)
2018-04-14 23:42:24 DEBUG    SHOWQUEUE-REFRESH :: [b4c38d5] Configured language en override show language of en
2018-04-14 23:42:24 DEBUG    SHOWQUEUE-REFRESH :: [b4c38d5] Getting all series data for 78783
2018-04-14 23:42:24 DEBUG    SHOWQUEUE-REFRESH :: [b4c38d5] Getting all show data for 78783
2018-04-14 23:42:25 DEBUG    SHOWQUEUE-REFRESH :: [b4c38d5] GET URL: https://api.themoviedb.org/3/tv/78783?api_key=**********&language=en%2Cnull [Status: 200]
2018-04-14 23:42:25 DEBUG    SHOWQUEUE-REFRESH :: [b4c38d5] User-Agent: Medusa/0.1.23 (Linux; 4.9.35-v7+; 5b3a1fbc-4032-11e8-8594-b827eb6b4d4c)
2018-04-14 23:42:26 DEBUG    SHOWQUEUE-REFRESH :: [b4c38d5] GET URL: https://api.themoviedb.org/3/tv/78783/external_ids?api_key=**********
2018-04-14 23:42:26 DEBUG    SHOWQUEUE-REFRESH :: [b4c38d5] User-Agent: Medusa/0.1.23 (Linux; 4.9.35-v7+; 5b3a1fbc-4032-11e8-8594-b827eb6b4d4c)
2018-04-14 23:42:26 DEBUG    SHOWQUEUE-REFRESH :: [b4c38d5] Getting all episodes of 78783
2018-04-14 23:42:26 DEBUG    SHOWQUEUE-REFRESH :: [b4c38d5] GET URL: https://api.themoviedb.org/3/tv/78783/season/1?api_key=**********&language=en [Status: 200]
2018-04-14 23:42:26 DEBUG    SHOWQUEUE-REFRESH :: [b4c38d5] User-Agent: Medusa/0.1.23 (Linux; 4.9.35-v7+; 5b3a1fbc-4032-11e8-8594-b827eb6b4d4c)
2018-04-14 23:42:26 DEBUG    SHOWQUEUE-REFRESH :: [b4c38d5] Getting show banners for 78783
2018-04-14 23:42:27 DEBUG    SHOWQUEUE-REFRESH :: [b4c38d5] GET URL: https://api.themoviedb.org/3/tv/78783/images?api_key=**********&params=include_image_language [Status: 200]
2018-04-14 23:42:27 DEBUG    SHOWQUEUE-REFRESH :: [b4c38d5] User-Agent: Medusa/0.1.23 (Linux; 4.9.35-v7+; 5b3a1fbc-4032-11e8-8594-b827eb6b4d4c)
2018-04-14 23:42:27 DEBUG    SHOWQUEUE-REFRESH :: [b4c38d5] Adding base url for image: /kOiXiSQNHiDNMRqvcNmSXnLao6F.jpg
2018-04-14 23:42:27 DEBUG    SHOWQUEUE-REFRESH :: [b4c38d5] Adding base url for image: /kOiXiSQNHiDNMRqvcNmSXnLao6F.jpg
2018-04-14 23:42:27 DEBUG    SHOWQUEUE-REFRESH :: [b4c38d5] Adding base url for image: /kOiXiSQNHiDNMRqvcNmSXnLao6F.jpg
2018-04-14 23:42:27 DEBUG    SHOWQUEUE-REFRESH :: [b4c38d5] Adding base url for image: /kOiXiSQNHiDNMRqvcNmSXnLao6F.jpg
2018-04-14 23:42:27 DEBUG    SHOWQUEUE-REFRESH :: [b4c38d5] Adding base url for image: /kOiXiSQNHiDNMRqvcNmSXnLao6F.jpg
2018-04-14 23:42:27 DEBUG    SHOWQUEUE-REFRESH :: [b4c38d5] Adding base url for image: /kOiXiSQNHiDNMRqvcNmSXnLao6F.jpg
2018-04-14 23:42:27 DEBUG    SHOWQUEUE-REFRESH :: [b4c38d5] Adding base url for image: /kOiXiSQNHiDNMRqvcNmSXnLao6F.jpg
2018-04-14 23:42:27 DEBUG    SHOWQUEUE-REFRESH :: [b4c38d5] No banners found for 78783
2018-04-14 23:42:27 DEBUG    SHOWQUEUE-REFRESH :: [b4c38d5] Found 0 total fanarts for series 78783
2018-04-14 23:42:27 ERROR    SHOWQUEUE-REFRESH :: [b4c38d5] 78783: Error while refreshing show Hunting Nazi Treasure. Error: division by zero
Traceback (most recent call last):
  File "/home/pi/Medusa/medusa/show_queue.py", line 637, in run
    self.show.refresh_dir()
  File "/home/pi/Medusa/medusa/tv/series.py", line 1754, in refresh_dir
    self.load_episodes_from_dir()
  File "/home/pi/Medusa/medusa/tv/series.py", line 932, in load_episodes_from_dir
    cur_episode = self.make_ep_from_file(os.path.join(self.location, media_file))
  File "/home/pi/Medusa/medusa/tv/series.py", line 1398, in make_ep_from_file
    **********_ep.create_meta_files()
  File "/home/pi/Medusa/medusa/tv/episode.py", line 1111, in create_meta_files
    self.__create_thumbnail(metadata_provider)
  File "/home/pi/Medusa/medusa/tv/episode.py", line 1134, in __create_thumbnail
    result = metadata_provider.create_episode_thumb(self) or result
  File "/home/pi/Medusa/medusa/metadata/generic.py", line 331, in create_episode_thumb
    return self.save_thumbnail(ep_obj)
  File "/home/pi/Medusa/medusa/metadata/generic.py", line 497, in save_thumbnail
    thumb_data = self._retrieve_show_image(u'thumbnail', ep_obj.series, ep_obj)
  File "/home/pi/Medusa/medusa/metadata/generic.py", line 734, in _retrieve_show_image
    indexer_show_obj = self._get_show_data(show_obj)
  File "/home/pi/Medusa/medusa/metadata/generic.py", line 857, in _get_show_data
    my_show = self.indexer_api[int(series_id)]
  File "/home/pi/Medusa/medusa/indexers/indexer_base.py", line 402, in __getitem__
    self._get_show_data(key, self.config['language'])
  File "/home/pi/Medusa/medusa/indexers/tmdb/tmdb.py", line 469, in _get_show_data
    self._parse_images(sid)
  File "/home/pi/Medusa/medusa/indexers/tmdb/tmdb.py", line 370, in _parse_images
    self._save_images(sid, _images)
  File "/home/pi/Medusa/medusa/indexers/indexer_base.py", line 395, in _save_images
    self._save_images_by_type(img_type, series_id, images_by_type)
  File "/home/pi/Medusa/medusa/indexers/indexer_base.py", line 296, in _save_images_by_type
    rating_mean, rating_dev, ratings = pop_stats(merged_images, 'rating')
  File "/home/pi/Medusa/medusa/indexers/indexer_base.py", line 229, in pop_stats
    mean = total / num_values
ZeroDivisionError: division by zero

# Fixed code
def _get_show_data(self, sid, language="en"):
    """Take a series ID, gets the epInfo URL and parses the TMDB json response.

    into the shows dict in layout:
    shows[series_id][season_number][episode_number]
    """
    if self.config["language"] is None:
        log.debug("Config language is none, using show language")
        if language is None:
            raise IndexerError("config['language'] was None, this should not happen")
        get_show_in_language = language
    else:
        log.debug(
            "Configured language {0} override show language of {1}",
            self.config["language"],
            language,
        )
        get_show_in_language = self.config["language"]

    # Parse show information
    log.debug("Getting all series data for {0}", sid)

    # Parse show information
    series_info = self._get_show_by_id(sid, request_language=get_show_in_language)

    if not series_info:
        log.debug("Series result returned zero")
        raise IndexerError("Series result returned zero")

    # Get MPAA rating if available
    content_ratings = self.tmdb.TV(sid).content_ratings()
    if content_ratings and content_ratings.get("results"):
        mpaa_rating = next(
            (
                r["rating"]
                for r in content_ratings["results"]
                if r["iso_3166_1"].upper() == "US"
            ),
            None,
        )
        if mpaa_rating:
            self._set_show_data(sid, "contentrating", mpaa_rating)

    # get series data / add the base_url to the image urls
    # Create a key/value dict, to map the image type to a default image width.
    # possitlbe widths can also be retrieved from self.configuration.images['poster_sizes'] and
    # self.configuration.images['still_sizes']
    image_width = {"fanart": "w1280", "poster": "w500"}

    for k, v in viewitems(series_info["series"]):
        if v is not None:
            if k in ["fanart", "banner", "poster"]:
                v = self.config["artwork_prefix"].format(
                    base_url=self.tmdb_configuration.images["base_url"],
                    image_size=image_width[k],
                    file_path=v,
                )

        self._set_show_data(sid, k, v)

    # Get external ids.
    # As the external id's are not part of the shows default response, we need to make an additional call for it.
    self._set_show_data(sid, "externals", self.tmdb.TV(sid).external_ids())

    # get episode data
    if self.config["episodes_enabled"]:
        self._get_episodes(sid, specials=False, aired_season=None)

    # Parse banners
    if self.config["banners_enabled"]:
        self._parse_images(sid)

    # Parse actors
    if self.config["actors_enabled"]:
        self._parse_actors(sid)

    return True