# Buggy code
def movie(self, **kwargs):
    """
    Discover movies by different types of data like average rating,
    number of votes, genres and certifications.

    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', 'release_date.desc', 'release_date.asc'
                 'popularity.desc', 'popularity.asc'.
        include_adult: (optional) Toggle the inclusion of adult titles.
                       Expected value is a boolean, True or False.
        year: (optional) Filter the results release dates to matches that
              include this value. Expected value is a year.
        primary_release_year: (optional) Filter the results so that
                              only the primary release date year has
                              this value.  Expected value is a year.
        vote_count.gte: (optional) Only include movies that are equal to,
                        or have a vote count higher than this value.
                        Expected value is an integer.
        vote_average.gte: (optional) Only include movies that are equal
                          to, or have a higher average rating than this
                          value.  Expected value is a float.
        with_genres: (optional) Only include movies with the specified
                     genres.  Expected value is an integer (the id of
                     a genre).  Multiple values can be specified.
                     Comma separated indicates an 'AND' query, while
                     a pipe (|) separated value indicates an 'OR'.
        release_date.gte: (optional) The minimum release to include.
                          Expected format is 'YYYY-MM-DD'.
        release_date.lte: (optional) The maximum release to include.
                          Expected format is 'YYYY-MM-DD'.
        certification_country: (optional) Only include movies with
                               certifications for a specific country. When
                               this value is specified, 'certification.lte'
                               is required. An ISO 3166-1 is expected.
        certification.lte: (optional) Only include movies with this
                           certification and lower. Expected value is a
                           valid certification for the specified
                           'certification_country'.
        with_companies: (optional) Filter movies to include a specific
                        company.  Expected value is an integer (the id
                        of a company).  They can be comma separated
                        to indicate an 'AND' query.

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

    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 movie(self, **kwargs):
    """
    Discover movies by different types of data like average rating,
    number of votes, genres and certifications.

    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', 'release_date.desc', 'release_date.asc'
                 'popularity.desc', 'popularity.asc'.
        include_adult: (optional) Toggle the inclusion of adult titles.
                       Expected value is a boolean, True or False.
        year: (optional) Filter the results release dates to matches that
              include this value. Expected value is a year.
        primary_release_year: (optional) Filter the results so that
                              only the primary release date year has
                              this value.  Expected value is a year.
        vote_count.gte or vote_count_gte: (optional) Only include movies
                        that are equal to, or have a vote count higher
                        than this value.  Expected value is an integer.
        vote_average.gte or vote_average_gte: (optional) Only include
                          movies that are equal to, or have a higher
                          average rating than this value.  Expected value
                          is a float.
        with_genres: (optional) Only include movies with the specified
                     genres.  Expected value is an integer (the id of
                     a genre).  Multiple values can be specified.
                     Comma separated indicates an 'AND' query, while
                     a pipe (|) separated value indicates an 'OR'.
        release_date.gte or release_date_gte: (optional) The minimum
                          release to include.  Expected format is
                          'YYYY-MM-DD'.
        releaste_date.lte or release_date_lte: (optional) The maximum
                          release to include.  Expected format is
                          'YYYY-MM-DD'.
        certification_country: (optional) Only include movies with
                               certifications for a specific country. When
                               this value is specified, 'certification.lte'
                               is required. An ISO 3166-1 is expected.
        certification.lte or certification_lte: (optional) Only include
                           movies with this certification and lower.
                           Expected value is a valid certification for
                           the specified 'certification_country'.
        with_companies: (optional) Filter movies to include a specific
                        company.  Expected value is an integer (the id
                        of a company).  They can be comma separated
                        to indicate an 'AND' query.

    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("movie")

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