# Buggy code
def tv(self, **kwargs):
    """
    Discover TV shows by different types of data like average rating,
    number of votes, genres, the network they aired on and air dates.

    Args:
        page: (optional) Minimum 1, maximum 1000.
        language: (optional) ISO 639-1 code.
        sort_by: (optional) Available options are 'vote_average.desc',
                 'vote_average.asc', 'first_air_date.desc',
                 'first_air_date.asc', 'popularity.desc', 'popularity.asc'
        first_air_year: (optional) Filter the results release dates to
                        matches that include this value. Expected value
                        is a year.
        vote_count.gte: (optional) Only include TV shows that are equal to,
                        or have vote count higher than this value. Expected
                        value is an integer.
        vote_average.gte: (optional) Only include TV shows that are equal
                          to, or have a higher average rating than this
                          value.  Expected value is a float.
        with_genres: (optional) Only include TV shows with the specified
                     genres. Expected value is an integer (the id of a
                     genre).  Multiple valued can be specified. Comma
                     separated indicates an 'AND' query, while a
                     pipe (|) separated value indicates an 'OR'.
        with_networks: (optional) Filter TV shows to include a specific
                       network. Expected value is an integer (the id of a
                       network).  They can be comma separated to indicate an
                       'AND' query.
        first_air_date.gte: (optional) The minimum release to include.
                            Expected format is 'YYYY-MM-DD'.
        first_air_date.lte: (optional) The maximum release to include.
                            Expected format is 'YYYY-MM-DD'.

    Returns:
        A dict respresentation of the JSON returned from the API.
    """
    path = self._get_path("tv")

    response = self._GET(path, kwargs)
    self._set_attrs_to_values(response)
    return response


# 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 tv(self, **kwargs):
    """
    Discover TV shows by different types of data like average rating,
    number of votes, genres, the network they aired on and air dates.

    Args:
        page: (optional) Minimum 1, maximum 1000.
        language: (optional) ISO 639-1 code.
        sort_by: (optional) Available options are 'vote_average.desc',
                 'vote_average.asc', 'first_air_date.desc',
                 'first_air_date.asc', 'popularity.desc', 'popularity.asc'
        first_air_year: (optional) Filter the results release dates to
                        matches that include this value. Expected value
                        is a year.
        vote_count.gte or vote_count_gte: (optional) Only include TV shows
                        that are equal to,
                        or have vote count higher than this value. Expected
                        value is an integer.
        vote_average.gte or vote_average_gte: (optional) Only include TV
                          shows that are equal
                          to, or have a higher average rating than this
                          value.  Expected value is a float.
        with_genres: (optional) Only include TV shows with the specified
                     genres. Expected value is an integer (the id of a
                     genre).  Multiple valued can be specified. Comma
                     separated indicates an 'AND' query, while a
                     pipe (|) separated value indicates an 'OR'.
        with_networks: (optional) Filter TV shows to include a specific
                       network. Expected value is an integer (the id of a
                       network).  They can be comma separated to indicate an
                       'AND' query.
        first_air_date.gte or first_air_date_gte: (optional) The minimum
                            release to include.
                            Expected format is 'YYYY-MM-DD'.
        first_air_date.lte or first_air_date_lte: (optional) The maximum
                            release to include.
                            Expected format is 'YYYY-MM-DD'.

    Returns:
        A dict respresentation of the JSON returned from the API.
    """
    # Periods are not allowed in keyword arguments but several API
    # arguments contain periods. See both usages in tests/test_discover.py.
    for param in kwargs:
        if "_lte" in param:
            kwargs[param.replace("_lte", ".lte")] = kwargs.pop(param)
        if "_gte" in param:
            kwargs[param.replace("_gte", ".gte")] = kwargs.pop(param)

    path = self._get_path("tv")

    response = self._GET(path, kwargs)
    self._set_attrs_to_values(response)
    return response