# Buggy code
def write_ep_file(self, ep_obj):
    """
    Generates and writes ep_obj's metadata under the given path with the
    given filename root. Uses the episode's name with the extension in
    _ep_nfo_extension.

    ep_obj: TVEpisode object for which to create the metadata

    file_name_path: The file name to use for this metadata. Note that the extension
            will be automatically added based on _ep_nfo_extension. This should
            include an absolute path.

    Note that this method expects that _ep_data will return an ElementTree
    object. If your _ep_data returns data in another format you'll need to
    override this method.
    """

    data = self._ep_data(ep_obj)

    if not data:
        return False

    nfo_file_path = self.get_episode_file_path(ep_obj)
    assert isinstance(nfo_file_path, text_type)
    nfo_file_dir = ek(os.path.dirname, nfo_file_path)

    try:
        if not ek(os.path.isdir, nfo_file_dir):
            logger.log(
                "Metadata dir didn't exist, creating it at " + nfo_file_dir,
                logger.DEBUG,
            )
            ek(os.makedirs, nfo_file_dir)
            helpers.chmodAsParent(nfo_file_dir)

        logger.log("Writing episode nfo file to " + nfo_file_path, logger.DEBUG)
        nfo_file = io.open(nfo_file_path, "wb")
        data.write(nfo_file, encoding="UTF-8")
        nfo_file.close()
        helpers.chmodAsParent(nfo_file_path)
    except IOError as e:
        logger.log(
            "Unable to write file to "
            + nfo_file_path
            + " - are you sure the folder is writable? "
            + ex(e),
            logger.ERROR,
        )
        return False

    return True


# Traceback (ParseError)
2016-09-10 04:37:01 DEBUG    SHOWQUEUE-REFRESH :: [c6c6e84] 269750: Writing NFOs for all episodes
2016-09-10 04:37:01 DEBUG    SHOWQUEUE-REFRESH :: [c6c6e84] 269750: Retrieving/creating episode S01E01
2016-09-10 04:37:01 DEBUG    SHOWQUEUE-REFRESH :: [c6c6e84] Checking if /media/extssd/Shows/Wayward Pines/Season 01/Wayward.Pines.S01E01.Where.Paradise.Is.Home.PROPER.720p.HDTV.x264-KILLERS.nfo exists: True
2016-09-10 04:37:01 DEBUG    SHOWQUEUE-REFRESH :: [c6c6e84] Checking if /media/extssd/Shows/Wayward Pines/Season 01/Wayward.Pines.S01E01.Where.Paradise.Is.Home.PROPER.720p.HDTV.x264-KILLERS-thumb.jpg exists: True
2016-09-10 04:37:01 DEBUG    SHOWQUEUE-REFRESH :: [c6c6e84] Checking if /media/extssd/Shows/Wayward Pines/Season 01/Wayward.Pines.S01E01.Where.Paradise.Is.Home.PROPER.720p.HDTV.x264-KILLERS.nfo exists: True
2016-09-10 04:37:01 DEBUG    SHOWQUEUE-REFRESH :: [c6c6e84] Checking if /media/extssd/Shows/Wayward Pines/Season 01/Wayward.Pines.S01E01.Where.Paradise.Is.Home.PROPER.720p.HDTV.x264-KILLERS-thumb.jpg exists: True
2016-09-10 04:37:01 DEBUG    SHOWQUEUE-REFRESH :: [c6c6e84] 269750: Retrieving/creating episode S01E02
2016-09-10 04:37:01 DEBUG    SHOWQUEUE-REFRESH :: [c6c6e84] Checking if /media/extssd/Shows/Wayward Pines/Season 01/Wayward.Pines.S01E02.Dont.Discuss.Your.Life.Before.1080p.WEB-DL.h264-KiNGS.nfo exists: True
2016-09-10 04:37:01 DEBUG    SHOWQUEUE-REFRESH :: [c6c6e84] Checking if /media/extssd/Shows/Wayward Pines/Season 01/Wayward.Pines.S01E02.Dont.Discuss.Your.Life.Before.1080p.WEB-DL.h264-KiNGS-thumb.jpg exists: True
2016-09-10 04:37:01 DEBUG    SHOWQUEUE-REFRESH :: [c6c6e84] Checking if /media/extssd/Shows/Wayward Pines/Season 01/Wayward.Pines.S01E02.Dont.Discuss.Your.Life.Before.1080p.WEB-DL.h264-KiNGS.nfo exists: True
2016-09-10 04:37:01 DEBUG    SHOWQUEUE-REFRESH :: [c6c6e84] Checking if /media/extssd/Shows/Wayward Pines/Season 01/Wayward.Pines.S01E02.Dont.Discuss.Your.Life.Before.1080p.WEB-DL.h264-KiNGS-thumb.jpg exists: True
2016-09-10 04:37:01 DEBUG    SHOWQUEUE-REFRESH :: [c6c6e84] 269750: Retrieving/creating episode S01E03
2016-09-10 04:37:01 DEBUG    SHOWQUEUE-REFRESH :: [c6c6e84] Checking if /media/extssd/Shows/Wayward Pines/Season 01/Wayward.Pines.S01E03.Our.Town.Our.Law.720p.HDTV.x264-DIMENSION.nfo exists: True
2016-09-10 04:37:01 DEBUG    SHOWQUEUE-REFRESH :: [c6c6e84] Checking if /media/extssd/Shows/Wayward Pines/Season 01/Wayward.Pines.S01E03.Our.Town.Our.Law.720p.HDTV.x264-DIMENSION-thumb.jpg exists: True
2016-09-10 04:37:01 DEBUG    SHOWQUEUE-REFRESH :: [c6c6e84] Checking if /media/extssd/Shows/Wayward Pines/Season 01/Wayward.Pines.S01E03.Our.Town.Our.Law.720p.HDTV.x264-DIMENSION.nfo exists: True
2016-09-10 04:37:01 DEBUG    SHOWQUEUE-REFRESH :: [c6c6e84] Checking if /media/extssd/Shows/Wayward Pines/Season 01/Wayward.Pines.S01E03.Our.Town.Our.Law.720p.HDTV.x264-DIMENSION-thumb.jpg exists: True
2016-09-10 04:37:01 DEBUG    SHOWQUEUE-REFRESH :: [c6c6e84] 269750: Retrieving/creating episode S01E04
2016-09-10 04:37:01 DEBUG    SHOWQUEUE-REFRESH :: [c6c6e84] Checking if /media/extssd/Shows/Wayward Pines/Season 01/Wayward.Pines.S01E04.One.of.Our.Senior.Realtors.Has.Chosen.to.Retire.1080p.WEB-DL.h264-KiNGS.nfo exists: True
2016-09-10 04:37:01 DEBUG    SHOWQUEUE-REFRESH :: [c6c6e84] Checking if /media/extssd/Shows/Wayward Pines/Season 01/Wayward.Pines.S01E04.One.of.Our.Senior.Realtors.Has.Chosen.to.Retire.1080p.WEB-DL.h264-KiNGS-thumb.jpg exists: True
2016-09-10 04:37:01 DEBUG    SHOWQUEUE-REFRESH :: [c6c6e84] Checking if /media/extssd/Shows/Wayward Pines/Season 01/Wayward.Pines.S01E04.One.of.Our.Senior.Realtors.Has.Chosen.to.Retire.1080p.WEB-DL.h264-KiNGS.nfo exists: True
2016-09-10 04:37:01 DEBUG    SHOWQUEUE-REFRESH :: [c6c6e84] Checking if /media/extssd/Shows/Wayward Pines/Season 01/Wayward.Pines.S01E04.One.of.Our.Senior.Realtors.Has.Chosen.to.Retire.1080p.WEB-DL.h264-KiNGS-thumb.jpg exists: True
2016-09-10 04:37:01 DEBUG    SHOWQUEUE-REFRESH :: [c6c6e84] 269750: Retrieving/creating episode S01E05
2016-09-10 04:37:01 DEBUG    SHOWQUEUE-REFRESH :: [c6c6e84] Checking if /media/extssd/Shows/Wayward Pines/Season 01/Wayward.Pines.S01E05.The.Truth.1080p.WEB-DL.h264-KiNGS.nfo exists: True
2016-09-10 04:37:01 DEBUG    SHOWQUEUE-REFRESH :: [c6c6e84] Checking if /media/extssd/Shows/Wayward Pines/Season 01/Wayward.Pines.S01E05.The.Truth.1080p.WEB-DL.h264-KiNGS-thumb.jpg exists: True
2016-09-10 04:37:01 DEBUG    SHOWQUEUE-REFRESH :: [c6c6e84] Checking if /media/extssd/Shows/Wayward Pines/Season 01/Wayward.Pines.S01E05.The.Truth.1080p.WEB-DL.h264-KiNGS.nfo exists: True
2016-09-10 04:37:01 DEBUG    SHOWQUEUE-REFRESH :: [c6c6e84] Checking if /media/extssd/Shows/Wayward Pines/Season 01/Wayward.Pines.S01E05.The.Truth.1080p.WEB-DL.h264-KiNGS-thumb.jpg exists: True
2016-09-10 04:37:01 DEBUG    SHOWQUEUE-REFRESH :: [c6c6e84] 269750: Retrieving/creating episode S01E06
2016-09-10 04:37:01 DEBUG    SHOWQUEUE-REFRESH :: [c6c6e84] Checking if /media/extssd/Shows/Wayward Pines/Season 01/Wayward.Pines.S01E06.Choices.1080p.WEB-DL.h264-KiNGS.nfo exists: True
2016-09-10 04:37:01 DEBUG    SHOWQUEUE-REFRESH :: [c6c6e84] Checking if /media/extssd/Shows/Wayward Pines/Season 01/Wayward.Pines.S01E06.Choices.1080p.WEB-DL.h264-KiNGS-thumb.jpg exists: True
2016-09-10 04:37:01 DEBUG    SHOWQUEUE-REFRESH :: [c6c6e84] Checking if /media/extssd/Shows/Wayward Pines/Season 01/Wayward.Pines.S01E06.Choices.1080p.WEB-DL.h264-KiNGS.nfo exists: True
2016-09-10 04:37:01 DEBUG    SHOWQUEUE-REFRESH :: [c6c6e84] Checking if /media/extssd/Shows/Wayward Pines/Season 01/Wayward.Pines.S01E06.Choices.1080p.WEB-DL.h264-KiNGS-thumb.jpg exists: True
2016-09-10 04:37:01 DEBUG    SHOWQUEUE-REFRESH :: [c6c6e84] 269750: Retrieving/creating episode S01E07
2016-09-10 04:37:01 DEBUG    SHOWQUEUE-REFRESH :: [c6c6e84] Checking if /media/extssd/Shows/Wayward Pines/Season 01/Wayward.Pines.S01E07.Betrayal.1080p.HDTV.x264-DIMENSION.nfo exists: True
2016-09-10 04:37:01 DEBUG    SHOWQUEUE-REFRESH :: [c6c6e84] Checking if /media/extssd/Shows/Wayward Pines/Season 01/Wayward.Pines.S01E07.Betrayal.1080p.HDTV.x264-DIMENSION-thumb.jpg exists: True
2016-09-10 04:37:01 DEBUG    SHOWQUEUE-REFRESH :: [c6c6e84] Checking if /media/extssd/Shows/Wayward Pines/Season 01/Wayward.Pines.S01E07.Betrayal.1080p.HDTV.x264-DIMENSION.nfo exists: True
2016-09-10 04:37:01 DEBUG    SHOWQUEUE-REFRESH :: [c6c6e84] Checking if /media/extssd/Shows/Wayward Pines/Season 01/Wayward.Pines.S01E07.Betrayal.1080p.HDTV.x264-DIMENSION-thumb.jpg exists: True
2016-09-10 04:37:01 DEBUG    SHOWQUEUE-REFRESH :: [c6c6e84] 269750: Retrieving/creating episode S01E08
2016-09-10 04:37:01 DEBUG    SHOWQUEUE-REFRESH :: [c6c6e84] Checking if /media/extssd/Shows/Wayward Pines/Season 01/Wayward.Pines.S01E08.The.Friendliest.Place.on.Earth.1080p.WEB-DL.h264-KiNGS.nfo exists: True
2016-09-10 04:37:01 DEBUG    SHOWQUEUE-REFRESH :: [c6c6e84] Checking if /media/extssd/Shows/Wayward Pines/Season 01/Wayward.Pines.S01E08.The.Friendliest.Place.on.Earth.1080p.WEB-DL.h264-KiNGS-thumb.jpg exists: True
2016-09-10 04:37:01 DEBUG    SHOWQUEUE-REFRESH :: [c6c6e84] Checking if /media/extssd/Shows/Wayward Pines/Season 01/Wayward.Pines.S01E08.The.Friendliest.Place.on.Earth.1080p.WEB-DL.h264-KiNGS.nfo exists: True
2016-09-10 04:37:01 DEBUG    SHOWQUEUE-REFRESH :: [c6c6e84] Checking if /media/extssd/Shows/Wayward Pines/Season 01/Wayward.Pines.S01E08.The.Friendliest.Place.on.Earth.1080p.WEB-DL.h264-KiNGS-thumb.jpg exists: True
2016-09-10 04:37:01 DEBUG    SHOWQUEUE-REFRESH :: [c6c6e84] 269750: Retrieving/creating episode S01E09
2016-09-10 04:37:01 DEBUG    SHOWQUEUE-REFRESH :: [c6c6e84] Checking if /media/extssd/Shows/Wayward Pines/Season 01/Wayward.Pines.S01E09.A.Reckoning.720p.HDTV.x264-DIMENSION.nfo exists: True
2016-09-10 04:37:01 DEBUG    SHOWQUEUE-REFRESH :: [c6c6e84] Checking if /media/extssd/Shows/Wayward Pines/Season 01/Wayward.Pines.S01E09.A.Reckoning.720p.HDTV.x264-DIMENSION-thumb.jpg exists: True
2016-09-10 04:37:01 DEBUG    SHOWQUEUE-REFRESH :: [c6c6e84] Checking if /media/extssd/Shows/Wayward Pines/Season 01/Wayward.Pines.S01E09.A.Reckoning.720p.HDTV.x264-DIMENSION.nfo exists: True
2016-09-10 04:37:02 DEBUG    SHOWQUEUE-REFRESH :: [c6c6e84] Checking if /media/extssd/Shows/Wayward Pines/Season 01/Wayward.Pines.S01E09.A.Reckoning.720p.HDTV.x264-DIMENSION-thumb.jpg exists: True
2016-09-10 04:37:02 DEBUG    SHOWQUEUE-REFRESH :: [c6c6e84] 269750: Retrieving/creating episode S01E10
2016-09-10 04:37:02 DEBUG    SHOWQUEUE-REFRESH :: [c6c6e84] Checking if /media/extssd/Shows/Wayward Pines/Season 01/Wayward.Pines.S01E10.Cycle.720p.HDTV.x264-DIMENSION.nfo exists: True
2016-09-10 04:37:02 DEBUG    SHOWQUEUE-REFRESH :: [c6c6e84] Checking if /media/extssd/Shows/Wayward Pines/Season 01/Wayward.Pines.S01E10.Cycle.720p.HDTV.x264-DIMENSION-thumb.jpg exists: True
2016-09-10 04:37:02 DEBUG    SHOWQUEUE-REFRESH :: [c6c6e84] Checking if /media/extssd/Shows/Wayward Pines/Season 01/Wayward.Pines.S01E10.Cycle.720p.HDTV.x264-DIMENSION.nfo exists: True
2016-09-10 04:37:02 DEBUG    SHOWQUEUE-REFRESH :: [c6c6e84] Checking if /media/extssd/Shows/Wayward Pines/Season 01/Wayward.Pines.S01E10.Cycle.720p.HDTV.x264-DIMENSION-thumb.jpg exists: True
2016-09-10 04:37:02 DEBUG    SHOWQUEUE-REFRESH :: [c6c6e84] 269750: Retrieving/creating episode S02E02
2016-09-10 04:37:02 DEBUG    SHOWQUEUE-REFRESH :: [c6c6e84] Checking if /media/extssd/Shows/Wayward Pines/Season 02/Wayward.Pines.S02E02.Blood.Harvest.720p.HDTV.x264-AVS.nfo exists: True
2016-09-10 04:37:02 DEBUG    SHOWQUEUE-REFRESH :: [c6c6e84] Checking if /media/extssd/Shows/Wayward Pines/Season 02/Wayward.Pines.S02E02.Blood.Harvest.720p.HDTV.x264-AVS-thumb.jpg exists: True
2016-09-10 04:37:02 DEBUG    SHOWQUEUE-REFRESH :: [c6c6e84] Checking if /media/extssd/Shows/Wayward Pines/Season 02/Wayward.Pines.S02E02.Blood.Harvest.720p.HDTV.x264-AVS.nfo exists: True
2016-09-10 04:37:02 DEBUG    SHOWQUEUE-REFRESH :: [c6c6e84] Checking if /media/extssd/Shows/Wayward Pines/Season 02/Wayward.Pines.S02E02.Blood.Harvest.720p.HDTV.x264-AVS-thumb.jpg exists: True
2016-09-10 04:37:02 DEBUG    SHOWQUEUE-REFRESH :: [c6c6e84] 269750: Retrieving/creating episode S02E03
2016-09-10 04:37:02 DEBUG    SHOWQUEUE-REFRESH :: [c6c6e84] Checking if /media/extssd/Shows/Wayward Pines/Season 02/Wayward.Pines.S02E03.Once.Upon.a.Time.in.Wayward.Pines.720p.HDTV.x264-AVS.nfo exists: True
2016-09-10 04:37:02 DEBUG    SHOWQUEUE-REFRESH :: [c6c6e84] Checking if /media/extssd/Shows/Wayward Pines/Season 02/Wayward.Pines.S02E03.Once.Upon.a.Time.in.Wayward.Pines.720p.HDTV.x264-AVS-thumb.jpg exists: True
2016-09-10 04:37:02 DEBUG    SHOWQUEUE-REFRESH :: [c6c6e84] Checking if /media/extssd/Shows/Wayward Pines/Season 02/Wayward.Pines.S02E03.Once.Upon.a.Time.in.Wayward.Pines.720p.HDTV.x264-AVS.nfo exists: True
2016-09-10 04:37:02 DEBUG    SHOWQUEUE-REFRESH :: [c6c6e84] Checking if /media/extssd/Shows/Wayward Pines/Season 02/Wayward.Pines.S02E03.Once.Upon.a.Time.in.Wayward.Pines.720p.HDTV.x264-AVS-thumb.jpg exists: True
2016-09-10 04:37:02 DEBUG    SHOWQUEUE-REFRESH :: [c6c6e84] 269750: Retrieving/creating episode S02E04
2016-09-10 04:37:02 DEBUG    SHOWQUEUE-REFRESH :: [c6c6e84] Checking if /media/extssd/Shows/Wayward Pines/Season 02/Wayward.Pines.S02E04.Exit.Strategy.720p.HDTV.x264-AVS.nfo exists: True
2016-09-10 04:37:02 DEBUG    SHOWQUEUE-REFRESH :: [c6c6e84] Checking if /media/extssd/Shows/Wayward Pines/Season 02/Wayward.Pines.S02E04.Exit.Strategy.720p.HDTV.x264-AVS-thumb.jpg exists: True
2016-09-10 04:37:02 DEBUG    SHOWQUEUE-REFRESH :: [c6c6e84] Checking if /media/extssd/Shows/Wayward Pines/Season 02/Wayward.Pines.S02E04.Exit.Strategy.720p.HDTV.x264-AVS.nfo exists: True
2016-09-10 04:37:02 DEBUG    SHOWQUEUE-REFRESH :: [c6c6e84] Checking if /media/extssd/Shows/Wayward Pines/Season 02/Wayward.Pines.S02E04.Exit.Strategy.720p.HDTV.x264-AVS-thumb.jpg exists: True
2016-09-10 04:37:02 DEBUG    SHOWQUEUE-REFRESH :: [c6c6e84] 269750: Retrieving/creating episode S02E05
2016-09-10 04:37:02 DEBUG    SHOWQUEUE-REFRESH :: [c6c6e84] Checking if /media/extssd/Shows/Wayward Pines/Season 02/Wayward.Pines.S02E05.Sound.the.Alarm.1080p.HDTV.x264-BRISK.nfo exists: True
2016-09-10 04:37:02 DEBUG    SHOWQUEUE-REFRESH :: [c6c6e84] Checking if /media/extssd/Shows/Wayward Pines/Season 02/Wayward.Pines.S02E05.Sound.the.Alarm.1080p.HDTV.x264-BRISK-thumb.jpg exists: True
2016-09-10 04:37:02 DEBUG    SHOWQUEUE-REFRESH :: [c6c6e84] Checking if /media/extssd/Shows/Wayward Pines/Season 02/Wayward.Pines.S02E05.Sound.the.Alarm.1080p.HDTV.x264-BRISK.nfo exists: True
2016-09-10 04:37:02 DEBUG    SHOWQUEUE-REFRESH :: [c6c6e84] Checking if /media/extssd/Shows/Wayward Pines/Season 02/Wayward.Pines.S02E05.Sound.the.Alarm.1080p.HDTV.x264-BRISK-thumb.jpg exists: True
2016-09-10 04:37:02 DEBUG    SHOWQUEUE-REFRESH :: [c6c6e84] 269750: Retrieving/creating episode S02E06
2016-09-10 04:37:02 DEBUG    SHOWQUEUE-REFRESH :: [c6c6e84] Checking if /media/extssd/Shows/Wayward Pines/Season 02/Wayward.Pines.S02E06.City.Upon.a.Hill.720p.HDTV.x264-AVS.nfo exists: True
2016-09-10 04:37:02 DEBUG    SHOWQUEUE-REFRESH :: [c6c6e84] Checking if /media/extssd/Shows/Wayward Pines/Season 02/Wayward.Pines.S02E06.City.Upon.a.Hill.720p.HDTV.x264-AVS-thumb.jpg exists: True
2016-09-10 04:37:02 DEBUG    SHOWQUEUE-REFRESH :: [c6c6e84] Checking if /media/extssd/Shows/Wayward Pines/Season 02/Wayward.Pines.S02E06.City.Upon.a.Hill.720p.HDTV.x264-AVS.nfo exists: True
2016-09-10 04:37:02 DEBUG    SHOWQUEUE-REFRESH :: [c6c6e84] Checking if /media/extssd/Shows/Wayward Pines/Season 02/Wayward.Pines.S02E06.City.Upon.a.Hill.720p.HDTV.x264-AVS-thumb.jpg exists: True
2016-09-10 04:37:02 DEBUG    SHOWQUEUE-REFRESH :: [c6c6e84] 269750: Retrieving/creating episode S02E07
2016-09-10 04:37:02 DEBUG    SHOWQUEUE-REFRESH :: [c6c6e84] Checking if /media/extssd/Shows/Wayward Pines/Season 02/Wayward.Pines.S02E07.Time.Will.Tell.1080p.WEB-DL.h264-ViSUM.nfo exists: True
2016-09-10 04:37:02 DEBUG    SHOWQUEUE-REFRESH :: [c6c6e84] Checking if /media/extssd/Shows/Wayward Pines/Season 02/Wayward.Pines.S02E07.Time.Will.Tell.1080p.WEB-DL.h264-ViSUM-thumb.jpg exists: True
2016-09-10 04:37:02 DEBUG    SHOWQUEUE-REFRESH :: [c6c6e84] Checking if /media/extssd/Shows/Wayward Pines/Season 02/Wayward.Pines.S02E07.Time.Will.Tell.1080p.WEB-DL.h264-ViSUM.nfo exists: True
2016-09-10 04:37:02 DEBUG    SHOWQUEUE-REFRESH :: [c6c6e84] Checking if /media/extssd/Shows/Wayward Pines/Season 02/Wayward.Pines.S02E07.Time.Will.Tell.1080p.WEB-DL.h264-ViSUM-thumb.jpg exists: True
2016-09-10 04:37:02 DEBUG    SHOWQUEUE-REFRESH :: [c6c6e84] 269750: Retrieving/creating episode S02E08
2016-09-10 04:37:02 DEBUG    SHOWQUEUE-REFRESH :: [c6c6e84] Checking if /media/extssd/Shows/Wayward Pines/Season 02/Wayward.Pines.S02E08.Pass.Judgment.1080p.WEB-DL.h264-ViSUM.nfo exists: True
2016-09-10 04:37:02 DEBUG    SHOWQUEUE-REFRESH :: [c6c6e84] Checking if /media/extssd/Shows/Wayward Pines/Season 02/Wayward.Pines.S02E08.Pass.Judgment.1080p.WEB-DL.h264-ViSUM-thumb.jpg exists: True
2016-09-10 04:37:02 DEBUG    SHOWQUEUE-REFRESH :: [c6c6e84] Checking if /media/extssd/Shows/Wayward Pines/Season 02/Wayward.Pines.S02E08.Pass.Judgment.1080p.WEB-DL.h264-ViSUM.nfo exists: True
2016-09-10 04:37:02 DEBUG    SHOWQUEUE-REFRESH :: [c6c6e84] Checking if /media/extssd/Shows/Wayward Pines/Season 02/Wayward.Pines.S02E08.Pass.Judgment.1080p.WEB-DL.h264-ViSUM-thumb.jpg exists: True
2016-09-10 04:37:02 DEBUG    SHOWQUEUE-REFRESH :: [c6c6e84] 269750: Retrieving/creating episode S02E09
2016-09-10 04:37:02 DEBUG    SHOWQUEUE-REFRESH :: [c6c6e84] Checking if /media/extssd/Shows/Wayward Pines/Season 02/Wayward.Pines.S02E09.Walcott.Prep.1080p.WEB-DL.h264-ViSUM.nfo exists: True
2016-09-10 04:37:02 DEBUG    SHOWQUEUE-REFRESH :: [c6c6e84] Checking if /media/extssd/Shows/Wayward Pines/Season 02/Wayward.Pines.S02E09.Walcott.Prep.1080p.WEB-DL.h264-ViSUM-thumb.jpg exists: True
2016-09-10 04:37:02 DEBUG    SHOWQUEUE-REFRESH :: [c6c6e84] Checking if /media/extssd/Shows/Wayward Pines/Season 02/Wayward.Pines.S02E09.Walcott.Prep.1080p.WEB-DL.h264-ViSUM.nfo exists: True
2016-09-10 04:37:02 DEBUG    SHOWQUEUE-REFRESH :: [c6c6e84] Checking if /media/extssd/Shows/Wayward Pines/Season 02/Wayward.Pines.S02E09.Walcott.Prep.1080p.WEB-DL.h264-ViSUM-thumb.jpg exists: True
2016-09-10 04:37:02 DEBUG    SHOWQUEUE-REFRESH :: [c6c6e84] 269750: Retrieving/creating episode S02E10
2016-09-10 04:37:02 DEBUG    SHOWQUEUE-REFRESH :: [c6c6e84] Checking if /media/extssd/Shows/Wayward Pines/Season 02/Wayward.Pines.S02E10.Bedtime.Story.720p.HDTV.x264-AVS.nfo exists: True
2016-09-10 04:37:02 DEBUG    SHOWQUEUE-REFRESH :: [c6c6e84] Checking if /media/extssd/Shows/Wayward Pines/Season 02/Wayward.Pines.S02E10.Bedtime.Story.720p.HDTV.x264-AVS-thumb.jpg exists: True
2016-09-10 04:37:02 DEBUG    SHOWQUEUE-REFRESH :: [c6c6e84] Checking if /media/extssd/Shows/Wayward Pines/Season 02/Wayward.Pines.S02E10.Bedtime.Story.720p.HDTV.x264-AVS.nfo exists: True
2016-09-10 04:37:02 DEBUG    SHOWQUEUE-REFRESH :: [c6c6e84] Checking if /media/extssd/Shows/Wayward Pines/Season 02/Wayward.Pines.S02E10.Bedtime.Story.720p.HDTV.x264-AVS-thumb.jpg exists: True
2016-09-10 04:37:02 INFO     SHOWQUEUE-REFRESH :: [c6c6e84] 269750: Updating NFOs for show with new indexer info
2016-09-10 04:37:02 DEBUG    SHOWQUEUE-REFRESH :: [c6c6e84] Checking if /media/extssd/Shows/Wayward Pines/tvshow.nfo exists: True
2016-09-10 04:37:02 DEBUG    SHOWQUEUE-REFRESH :: [c6c6e84] Metadata provider KODI 12+ updating show indexer info metadata file for Wayward Pines
2016-09-10 04:37:02 ERROR    SHOWQUEUE-REFRESH :: [c6c6e84] 269750: Error while refreshing show Wayward Pines. Error: unclosed token: line 104, column 12
Traceback (most recent call last):
  File "/home/home/SickRage/sickbeard/show_queue.py", line 581, in run
    self.show.update_metadata()
  File "/home/home/SickRage/sickbeard/tv.py", line 547, in update_metadata
    self.__update_show_nfo()
  File "/home/home/SickRage/sickbeard/tv.py", line 555, in __update_show_nfo
    result = cur_provider.update_show_indexer_metadata(self) or result
  File "/home/home/SickRage/sickbeard/metadata/generic.py", line 273, in update_show_indexer_metadata
    showXML = etree.ElementTree(file=xmlFileObj)
  File "/usr/lib/python2.7/xml/etree/ElementTree.py", line 611, in __init__
    self.parse(file)
  File "<string>", line 38, in parse
ParseError: unclosed token: line 104, column 12

# Fixed code
def write_ep_file(self, ep_obj):
    """
    Generates and writes ep_obj's metadata under the given path with the
    given filename root. Uses the episode's name with the extension in
    _ep_nfo_extension.

    ep_obj: TVEpisode object for which to create the metadata

    file_name_path: The file name to use for this metadata. Note that the extension
            will be automatically added based on _ep_nfo_extension. This should
            include an absolute path.

    Note that this method expects that _ep_data will return an ElementTree
    object. If your _ep_data returns data in another format you'll need to
    override this method.
    """

    data = self._ep_data(ep_obj)

    if not data:
        return False

    nfo_file_path = self.get_episode_file_path(ep_obj)
    assert isinstance(nfo_file_path, text_type)
    nfo_file_dir = ek(os.path.dirname, nfo_file_path)

    try:
        if not ek(os.path.isdir, nfo_file_dir):
            logger.log(
                "Metadata dir didn't exist, creating it at " + nfo_file_dir,
                logger.DEBUG,
            )
            ek(os.makedirs, nfo_file_dir)
            helpers.chmodAsParent(nfo_file_dir)

        logger.log("Writing episode nfo file to " + nfo_file_path, logger.DEBUG)
        nfo_file = io.open(nfo_file_path, "wb", encoding="utf8")
        data.write(nfo_file, encoding="UTF-8")
        nfo_file.close()
        helpers.chmodAsParent(nfo_file_path)
    except IOError as e:
        logger.log(
            "Unable to write file to "
            + nfo_file_path
            + " - are you sure the folder is writable? "
            + ex(e),
            logger.ERROR,
        )
        return False

    return True