# Buggy code
def _parse_episodes(self, tvdb_id, episode_data):
    """Parse retreived episodes."""
    if "episode" not in episode_data:
        return False

    episodes = episode_data["episode"]
    if not isinstance(episodes, list):
        episodes = [episodes]

    for cur_ep in episodes:
        if self.config["dvdorder"]:
            logger.debug("Using DVD ordering.")
            use_dvd = (
                cur_ep["dvd_season"] is not None
                and cur_ep["dvd_episodenumber"] is not None
            )
        else:
            use_dvd = False

        if use_dvd:
            seasnum, epno = cur_ep.get("dvd_season"), cur_ep.get("dvd_episodenumber")
        else:
            seasnum, epno = cur_ep.get("seasonnumber"), cur_ep.get("episodenumber")

        if seasnum is None or epno is None:
            logger.warning(
                "This episode has incomplete information. The season or episode number "
                "(season: %s, episode: %s) is missing. "
                "to get rid of this warning, you will have to contact tvdb through their forums "
                "and have them fix the specific episode.",
                seasnum,
                epno,
            )
            continue  # Skip to next episode

        # float() is because https://github.com/dbr/tvnamer/issues/95 - should probably be fixed in TVDB data
        seas_no = int(float(seasnum))
        ep_no = int(float(epno))

        for k, v in cur_ep.items():
            k = k.lower()

            if v is not None:
                if k == "filename":
                    v = urljoin(self.config["artwork_prefix"], v)
                else:
                    v = self._clean_data(v)

            self._set_item(tvdb_id, seas_no, ep_no, k, v)


# Traceback (KeyError)
2017-03-24 13:09:12 DEBUG    SHOWQUEUE-UPDATE :: [b4a8a54] Using DVD ordering.
Exception in thread SHOWQUEUE-UPDATE:
Traceback (most recent call last):
File "C:\Python27\lib\threading.py", line 801, in __bootstrap_inner
self.run()
File "C:/Users/fernando/Documents/Medusa\medusa\show_queue.py", line 722, in run
self.show.load_from_indexer()
File "C:/Users/fernando/Documents/Medusa\medusa\tv\series.py", line 1211, in load_from_indexer
indexed_show = self.indexer_api[self.indexerid]
File "C:/Users/fernando/Documents/Medusa\medusa\indexers\indexer_base.py", line 254, in __getitem__
self._get_show_data(key, self.config['language'])
File "C:/Users/fernando/Documents/Medusa\medusa\indexers\tvmaze\tvmaze_api.py", line 432, in _get_show_data
self._get_episodes(tvmaze_id, specials=False, aired_season=None)
File "C:/Users/fernando/Documents/Medusa\medusa\indexers\tvmaze\tvmaze_api.py", line 255, in _get_episodes
use_dvd = cur_ep['dvd_season'] is not None and cur_ep['dvd_episodenumber'] is not None
KeyError: u'dvd_season'

# Fixed code
def _parse_episodes(self, tvdb_id, episode_data):
    """Parse retreived episodes."""
    if "episode" not in episode_data:
        return False

    episodes = episode_data["episode"]
    if not isinstance(episodes, list):
        episodes = [episodes]

    for cur_ep in episodes:
        if self.config["dvdorder"]:
            logger.debug("Using DVD ordering.")
            use_dvd = (
                cur_ep.get("dvd_season") is not None
                and cur_ep.get("dvd_episodenumber") is not None
            )
        else:
            use_dvd = False

        if use_dvd:
            seasnum, epno = cur_ep.get("dvd_season"), cur_ep.get("dvd_episodenumber")
            if self.config["dvdorder"]:
                logger.warning(
                    "Episode doest not have DVD ordering available (season: %s, episode: %s). "
                    "Falling back to non-DVD order. "
                    "Please consider disable DVD ordering for the show with TMDB ID: %s",
                    seasnum,
                    epno,
                    tvdb_id,
                )
        else:
            seasnum, epno = cur_ep.get("seasonnumber"), cur_ep.get("episodenumber")

        if seasnum is None or epno is None:
            logger.warning(
                "This episode has incomplete information. The season or episode number "
                "(season: %s, episode: %s) is missing. "
                "to get rid of this warning, you will have to contact tvdb through their forums "
                "and have them fix the specific episode.",
                seasnum,
                epno,
            )
            continue  # Skip to next episode

        # float() is because https://github.com/dbr/tvnamer/issues/95 - should probably be fixed in TVDB data
        seas_no = int(float(seasnum))
        ep_no = int(float(epno))

        for k, v in cur_ep.items():
            k = k.lower()

            if v is not None:
                if k == "filename":
                    v = urljoin(self.config["artwork_prefix"], v)
                else:
                    v = self._clean_data(v)

            self._set_item(tvdb_id, seas_no, ep_no, k, v)