# Buggy code
def _write_image(self, image_data, image_path, obj=None):
    """
    Saves the data in image_data to the location image_path. Returns True/False
    to represent success or failure.

    image_data: binary image data to write to file
    image_path: file location to save the image to
    """

    assert isinstance(image_path, text_type)

    # don't bother overwriting it
    if ek(os.path.isfile, image_path):
        logger.log("Image already exists, not downloading", logger.DEBUG)
        return False

    image_dir = ek(os.path.dirname, image_path)

    if not image_data:
        logger.log(
            "Unable to retrieve image to save in %s, skipping" % image_path,
            logger.DEBUG,
        )
        return False

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

        outFile = io.open(image_path, "wb")
        outFile.write(image_data)
        outFile.close()
        helpers.chmodAsParent(image_path)
    except IOError as e:
        if hasattr(e, "errno") and e.errno in (
            13,
            28,
        ):  # Permission denied and No space left on device
            msg_level = logger.WARNING
        else:
            msg_level = logger.ERROR
        logger.log(
            "Unable to write image to {0}. Error: {1}".format(image_path, e), msg_level
        )
        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_image(self, image_data, image_path, obj=None):
    """
    Saves the data in image_data to the location image_path. Returns True/False
    to represent success or failure.

    image_data: binary image data to write to file
    image_path: file location to save the image to
    """

    assert isinstance(image_path, text_type)

    # don't bother overwriting it
    if ek(os.path.isfile, image_path):
        logger.log("Image already exists, not downloading", logger.DEBUG)
        return False

    image_dir = ek(os.path.dirname, image_path)

    if not image_data:
        logger.log(
            "Unable to retrieve image to save in %s, skipping" % image_path,
            logger.DEBUG,
        )
        return False

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

        outFile = io.open(image_path, "wb", encoding="utf8")
        outFile.write(image_data)
        outFile.close()
        helpers.chmodAsParent(image_path)
    except IOError as e:
        if hasattr(e, "errno") and e.errno in (
            13,
            28,
        ):  # Permission denied and No space left on device
            msg_level = logger.WARNING
        else:
            msg_level = logger.ERROR
        logger.log(
            "Unable to write image to {0}. Error: {1}".format(image_path, e), msg_level
        )
        return False

    return True