# Buggy code
def subtitleMissedPP(self):
    t = PageTemplate(rh=self, filename="manage_subtitleMissedPP.mako")
    app.RELEASES_IN_PP = []
    for root, _, files in os.walk(app.TV_DOWNLOAD_DIR, topdown=False):
        for filename in sorted(files):
            if not isMediaFile(filename):
                continue

            video_path = os.path.join(root, filename)
            video_date = datetime.datetime.fromtimestamp(os.stat(video_path).st_ctime)
            video_age = datetime.datetime.today() - video_date

            tv_episode = TVEpisode.from_filepath(video_path)

            if not tv_episode:
                logger.debug("%s cannot be parsed to an episode", filename)
                continue

            if not tv_episode.show.subtitles:
                continue

            related_files = postProcessor.PostProcessor(
                video_path
            ).list_associated_files(video_path, base_name_only=True, subfolders=False)
            if related_files:
                continue

            age_hours = divmod(video_age.seconds, 3600)[0]
            age_minutes = divmod(video_age.seconds, 60)[0]
            if video_age.days > 0:
                age_unit = "d"
                age_value = video_age.days
            elif age_hours > 0:
                age_unit = "h"
                age_value = age_hours
            else:
                age_unit = "m"
                age_value = age_minutes

            app.RELEASES_IN_PP.append(
                {
                    "release": video_path,
                    "show": tv_episode.show.indexerid,
                    "show_name": tv_episode.show.name,
                    "season": tv_episode.season,
                    "episode": tv_episode.episode,
                    "age": age_value,
                    "age_unit": age_unit,
                    "age_raw": video_age,
                }
            )
    app.RELEASES_IN_PP = sorted(
        app.RELEASES_IN_PP, key=lambda k: k["age_raw"], reverse=True
    )

    return t.render(
        releases_in_pp=app.RELEASES_IN_PP,
        title="Missing Subtitles in Post-Process folder",
        header="Missing Subtitles in Post Process folder",
        topmenu="manage",
        controller="manage",
        action="subtitleMissedPP",
    )


# Traceback (AttributeError)
2016-10-24 12:29:51 DEBUG    Thread-15 :: [e16480a] main.db: SELECT airdate, status FROM tv_episodes WHERE season > 0 AND episode > 0 AND airdate > 1
2016-10-24 12:29:54 INFO     Thread-17 :: [e16480a] Broken providers found: [u'btdigg', u'kickasstorrents', u'torrentproject']
2016-10-24 12:29:54 DEBUG    Thread-17 :: [e16480a] main.db: SELECT show_name, showid, season, episode, h.quality, action, provider, resource, date, h.proper_tags FROM history h, tv_shows s WHERE h.showid = s.indexer_id ORDER BY date DESC 
2016-10-24 12:29:55 DEBUG    Thread-17 :: [e16480a] main.db: SELECT airdate, status FROM tv_episodes WHERE season > 0 AND episode > 0 AND airdate > 1
2016-10-24 12:30:30 DEBUG    Thread-18 :: [e16480a] main.db: SELECT season, episode FROM scene_numbering WHERE indexer = ? and indexer_id = ? and scene_season = ? and scene_episode = ? with args [1, 248682, 6, 5]
2016-10-24 12:30:30 DEBUG    Thread-18 :: [e16480a] main.db: SELECT last_refreshed FROM xem_refresh WHERE indexer = ? and indexer_id = ? with args [1, 248682]
2016-10-24 12:30:30 DEBUG    Thread-18 :: [e16480a] main.db: SELECT season, episode FROM tv_episodes WHERE indexer = ? and showid = ? and scene_season = ? and scene_episode = ? with args [1, 248682, 6, 5]
2016-10-24 12:30:30 DEBUG    Thread-18 :: [e16480a] Scene numbering enabled show 'New Girl' using indexer numbering: S06E05
2016-10-24 12:30:30 DEBUG    Thread-18 :: [e16480a] Converted parsed result /media/SAMSUNG/media/downloaded/series/New.Girl.S06E05.Jaipur.Aviv.1080p.WEB-DL.DD5.1.H.264-CLZ[rartv]/New.Girl.S06E05.Jaipur.Aviv.1080p.WEB-DL.DD5.1.H.264-CLZ.mkv into title: New Girl, season: 6, episode: [5], episode_title: Jaipur Aviv, screen_size: 1080p, format: WEB-DL, audio_codec: DolbyDigital, audio_channels: 5.1, video_codec: h264, release_group: CLZ, container: mkv, mimetype: video/x-matroska, type: episode, absolute_episode: [], quality: 1080p WEB-DL
2016-10-24 12:30:30 DEBUG    Thread-18 :: [e16480a] Parsed '/media/SAMSUNG/media/downloaded/series/New.Girl.S06E05.Jaipur.Aviv.1080p.WEB-DL.DD5.1.H.264-CLZ[rartv]/New.Girl.S06E05.Jaipur.Aviv.1080p.WEB-DL.DD5.1.H.264-CLZ.mkv' into title: New Girl, season: 6, episode: [5], episode_title: Jaipur Aviv, screen_size: 1080p, format: WEB-DL, audio_codec: DolbyDigital, audio_channels: 5.1, video_codec: h264, release_group: CLZ, container: mkv, mimetype: video/x-matroska, type: episode, absolute_episode: [], quality: 1080p WEB-DL
2016-10-24 12:30:30 DEBUG    Thread-18 :: [e16480a] No associated files for /media/SAMSUNG/media/downloaded/series/New.Girl.S06E05.Jaipur.Aviv.1080p.WEB-DL.DD5.1.H.264-CLZ[rartv]/New.Girl.S06E05.Jaipur.Aviv.1080p.WEB-DL.DD5.1.H.264-CLZ.mkv were found during this pass
2016-10-24 12:30:31 DEBUG    Thread-18 :: [e16480a] main.db: SELECT season, episode FROM scene_numbering WHERE indexer = ? and indexer_id = ? and scene_season = ? and scene_episode = ? with args [1, 271910, 3, 10]
2016-10-24 12:30:31 DEBUG    Thread-18 :: [e16480a] main.db: SELECT last_refreshed FROM xem_refresh WHERE indexer = ? and indexer_id = ? with args [1, 271910]
2016-10-24 12:30:31 DEBUG    Thread-18 :: [e16480a] main.db: SELECT season, episode FROM tv_episodes WHERE indexer = ? and showid = ? and scene_season = ? and scene_episode = ? with args [1, 271910, 3, 10]
2016-10-24 12:30:31 DEBUG    Thread-18 :: [e16480a] Scene numbering enabled show 'Halt and Catch Fire' using indexer numbering: S03E10
2016-10-24 12:30:31 DEBUG    Thread-18 :: [e16480a] Converted parsed result /media/SAMSUNG/media/downloaded/series/Halt.and.Catch.Fire.S03E10.NeXT.1080p.WEB-DL.DD5.1.H264-NTb[rarbg]/Halt.and.Catch.Fire.S03E10.NeXT.1080p.WEB-DL.DD5.1.H264-NTb.mkv into title: Halt and Catch Fire, season: 3, episode: [10], episode_title: NeXT, screen_size: 1080p, format: WEB-DL, audio_codec: DolbyDigital, audio_channels: 5.1, video_codec: h264, release_group: NTb, container: mkv, mimetype: video/x-matroska, type: episode, absolute_episode: [], quality: 1080p WEB-DL
2016-10-24 12:30:31 DEBUG    Thread-18 :: [e16480a] Parsed '/media/SAMSUNG/media/downloaded/series/Halt.and.Catch.Fire.S03E10.NeXT.1080p.WEB-DL.DD5.1.H264-NTb[rarbg]/Halt.and.Catch.Fire.S03E10.NeXT.1080p.WEB-DL.DD5.1.H264-NTb.mkv' into title: Halt and Catch Fire, season: 3, episode: [10], episode_title: NeXT, screen_size: 1080p, format: WEB-DL, audio_codec: DolbyDigital, audio_channels: 5.1, video_codec: h264, release_group: NTb, container: mkv, mimetype: video/x-matroska, type: episode, absolute_episode: [], quality: 1080p WEB-DL
2016-10-24 12:30:31 DEBUG    Thread-18 :: [e16480a] No associated files for /media/SAMSUNG/media/downloaded/series/Halt.and.Catch.Fire.S03E10.NeXT.1080p.WEB-DL.DD5.1.H264-NTb[rarbg]/Halt.and.Catch.Fire.S03E10.NeXT.1080p.WEB-DL.DD5.1.H264-NTb.mkv were found during this pass
2016-10-24 12:30:32 DEBUG    Thread-18 :: [e16480a] main.db: SELECT season, episode FROM scene_numbering WHERE indexer = ? and indexer_id = ? and scene_season = ? and scene_episode = ? with args [1, 253463, 3, 3]
2016-10-24 12:30:32 DEBUG    Thread-18 :: [e16480a] main.db: SELECT last_refreshed FROM xem_refresh WHERE indexer = ? and indexer_id = ? with args [1, 253463]
2016-10-24 12:30:32 DEBUG    Thread-18 :: [e16480a] main.db: SELECT season, episode FROM tv_episodes WHERE indexer = ? and showid = ? and scene_season = ? and scene_episode = ? with args [1, 253463, 3, 3]
2016-10-24 12:30:32 DEBUG    Thread-18 :: [e16480a] Scene numbering enabled show 'Black Mirror' using indexer numbering: S03E03
2016-10-24 12:30:32 DEBUG    Thread-18 :: [e16480a] Converted parsed result /media/SAMSUNG/media/downloaded/series/Black.Mirror.S03E03.1080p.WEBRip.x264-SKGTV[rarbg]/black.mirror.s03e03.1080p.webrip.x264-skgtv.mkv into title: Black Mirror, season: 3, episode: [3], screen_size: 1080p, format: WEBRip, video_codec: h264, release_group: SKGTV, container: mkv, mimetype: video/x-matroska, type: episode, absolute_episode: [], quality: 1080p WEB-DL
2016-10-24 12:30:32 DEBUG    Thread-18 :: [e16480a] Parsed '/media/SAMSUNG/media/downloaded/series/Black.Mirror.S03E03.1080p.WEBRip.x264-SKGTV[rarbg]/black.mirror.s03e03.1080p.webrip.x264-skgtv.mkv' into title: Black Mirror, season: 3, episode: [3], screen_size: 1080p, format: WEBRip, video_codec: h264, release_group: SKGTV, container: mkv, mimetype: video/x-matroska, type: episode, absolute_episode: [], quality: 1080p WEB-DL
2016-10-24 12:30:32 DEBUG    Thread-18 :: [e16480a] No associated files for /media/SAMSUNG/media/downloaded/series/Black.Mirror.S03E03.1080p.WEBRip.x264-SKGTV[rarbg]/black.mirror.s03e03.1080p.webrip.x264-skgtv.mkv were found during this pass
2016-10-24 12:30:33 DEBUG    Thread-18 :: [e16480a] main.db: SELECT season, episode FROM scene_numbering WHERE indexer = ? and indexer_id = ? and scene_season = ? and scene_episode = ? with args [1, 295515, 2, 4]
2016-10-24 12:30:33 DEBUG    Thread-18 :: [e16480a] main.db: SELECT last_refreshed FROM xem_refresh WHERE indexer = ? and indexer_id = ? with args [1, 295515]
2016-10-24 12:30:33 DEBUG    Thread-18 :: [e16480a] main.db: SELECT season, episode FROM tv_episodes WHERE indexer = ? and showid = ? and scene_season = ? and scene_episode = ? with args [1, 295515, 2, 4]
2016-10-24 12:30:33 DEBUG    Thread-18 :: [e16480a] Scene numbering enabled show 'Quantico' using indexer numbering: S02E04
2016-10-24 12:30:33 DEBUG    Thread-18 :: [e16480a] Converted parsed result /media/SAMSUNG/media/downloaded/series/Quantico.S02E04.720p.HDTV.X264-DIMENSION[rarbg]/Quantico.S02E04.720p.HDTV.X264-DIMENSION.mkv into title: Quantico, season: 2, episode: [4], screen_size: 720p, format: HDTV, video_codec: h264, release_group: DIMENSION, container: mkv, mimetype: video/x-matroska, type: episode, absolute_episode: [], quality: 720p HDTV
2016-10-24 12:30:33 DEBUG    Thread-18 :: [e16480a] Parsed '/media/SAMSUNG/media/downloaded/series/Quantico.S02E04.720p.HDTV.X264-DIMENSION[rarbg]/Quantico.S02E04.720p.HDTV.X264-DIMENSION.mkv' into title: Quantico, season: 2, episode: [4], screen_size: 720p, format: HDTV, video_codec: h264, release_group: DIMENSION, container: mkv, mimetype: video/x-matroska, type: episode, absolute_episode: [], quality: 720p HDTV
2016-10-24 12:30:33 DEBUG    Thread-18 :: [e16480a] No associated files for /media/SAMSUNG/media/downloaded/series/Quantico.S02E04.720p.HDTV.X264-DIMENSION[rarbg]/Quantico.S02E04.720p.HDTV.X264-DIMENSION.mkv were found during this pass
2016-10-24 12:30:35 DEBUG    Thread-18 :: [e16480a] main.db: SELECT season, episode FROM scene_numbering WHERE indexer = ? and indexer_id = ? and scene_season = ? and scene_episode = ? with args [1, 253463, 3, 4]
2016-10-24 12:30:35 DEBUG    Thread-18 :: [e16480a] main.db: SELECT last_refreshed FROM xem_refresh WHERE indexer = ? and indexer_id = ? with args [1, 253463]
2016-10-24 12:30:35 DEBUG    Thread-18 :: [e16480a] main.db: SELECT season, episode FROM tv_episodes WHERE indexer = ? and showid = ? and scene_season = ? and scene_episode = ? with args [1, 253463, 3, 4]
2016-10-24 12:30:35 DEBUG    Thread-18 :: [e16480a] Scene numbering enabled show 'Black Mirror' using indexer numbering: S03E04
2016-10-24 12:30:35 DEBUG    Thread-18 :: [e16480a] Converted parsed result /media/SAMSUNG/media/downloaded/series/Black.Mirror.S03E04.1080p.WEBRip.x264-SKGTV[rarbg]/black.mirror.s03e04.1080p.webrip.x264-skgtv.mkv into title: Black Mirror, season: 3, episode: [4], screen_size: 1080p, format: WEBRip, video_codec: h264, release_group: SKGTV, container: mkv, mimetype: video/x-matroska, type: episode, absolute_episode: [], quality: 1080p WEB-DL
2016-10-24 12:30:35 DEBUG    Thread-18 :: [e16480a] Parsed '/media/SAMSUNG/media/downloaded/series/Black.Mirror.S03E04.1080p.WEBRip.x264-SKGTV[rarbg]/black.mirror.s03e04.1080p.webrip.x264-skgtv.mkv' into title: Black Mirror, season: 3, episode: [4], screen_size: 1080p, format: WEBRip, video_codec: h264, release_group: SKGTV, container: mkv, mimetype: video/x-matroska, type: episode, absolute_episode: [], quality: 1080p WEB-DL
2016-10-24 12:30:35 DEBUG    Thread-18 :: [e16480a] Associated file extension not found in allowed extensions: .NFO
2016-10-24 12:30:35 DEBUG    Thread-18 :: [e16480a] Found the following associated files for /media/SAMSUNG/media/downloaded/series/Black.Mirror.S03E04.1080p.WEBRip.x264-SKGTV[rarbg]/black.mirror.s03e04.1080p.webrip.x264-skgtv.mkv: [u'/media/SAMSUNG/media/downloaded/series/Black.Mirror.S03E04.1080p.WEBRip.x264-SKGTV[rarbg]/black.mirror.s03e04.1080p.webrip.x264-skgtv.nfo']
2016-10-24 12:30:35 DEBUG    Thread-18 :: [e16480a] Deleting file /media/SAMSUNG/media/downloaded/series/Black.Mirror.S03E04.1080p.WEBRip.x264-SKGTV[rarbg]/black.mirror.s03e04.1080p.webrip.x264-skgtv.nfo
2016-10-24 12:30:36 DEBUG    Thread-18 :: [e16480a] main.db: SELECT season, episode FROM scene_numbering WHERE indexer = ? and indexer_id = ? and scene_season = ? and scene_episode = ? with args [1, 266189, 4, 5]
2016-10-24 12:30:36 DEBUG    Thread-18 :: [e16480a] main.db: SELECT last_refreshed FROM xem_refresh WHERE indexer = ? and indexer_id = ? with args [1, 266189]
2016-10-24 12:30:36 DEBUG    Thread-18 :: [e16480a] main.db: SELECT season, episode FROM tv_episodes WHERE indexer = ? and showid = ? and scene_season = ? and scene_episode = ? with args [1, 266189, 4, 5]
2016-10-24 12:30:36 DEBUG    Thread-18 :: [e16480a] Scene numbering enabled show 'The Blacklist' using indexer numbering: S04E05
2016-10-24 12:30:36 DEBUG    Thread-18 :: [e16480a] Converted parsed result /media/SAMSUNG/media/downloaded/series/The.Blacklist.S04E05.The.Lindquist.Concern.105.1080p.WEB-DL.DD5.1.H264-AG[rarbg]/The.Blacklist.S04E05.The.Lindquist.Concern.105.1080p.WEB-DL.DD5.1.H264-AG.mkv into title: The Blacklist, season: 4, episode: [5], episode_title: The Lindquist Concern 105, screen_size: 1080p, format: WEB-DL, audio_codec: DolbyDigital, audio_channels: 5.1, video_codec: h264, release_group: AG, container: mkv, mimetype: video/x-matroska, type: episode, absolute_episode: [], quality: 1080p WEB-DL
2016-10-24 12:30:36 DEBUG    Thread-18 :: [e16480a] Parsed '/media/SAMSUNG/media/downloaded/series/The.Blacklist.S04E05.The.Lindquist.Concern.105.1080p.WEB-DL.DD5.1.H264-AG[rarbg]/The.Blacklist.S04E05.The.Lindquist.Concern.105.1080p.WEB-DL.DD5.1.H264-AG.mkv' into title: The Blacklist, season: 4, episode: [5], episode_title: The Lindquist Concern 105, screen_size: 1080p, format: WEB-DL, audio_codec: DolbyDigital, audio_channels: 5.1, video_codec: h264, release_group: AG, container: mkv, mimetype: video/x-matroska, type: episode, absolute_episode: [], quality: 1080p WEB-DL
2016-10-24 12:30:36 DEBUG    Thread-18 :: [e16480a] No associated files for /media/SAMSUNG/media/downloaded/series/The.Blacklist.S04E05.The.Lindquist.Concern.105.1080p.WEB-DL.DD5.1.H264-AG[rarbg]/The.Blacklist.S04E05.The.Lindquist.Concern.105.1080p.WEB-DL.DD5.1.H264-AG.mkv were found during this pass
2016-10-24 12:30:36 DEBUG    Thread-18 :: [e16480a] Converted parsed result /media/SAMSUNG/media/downloaded/series/Black.Mirror.S02.Special.White.Chirstmas.720p.HDTV.x264-TLA.mkv into title: Black Mirror, season: 2, episode_title: Special White Chirstmas, episode_details: Special, screen_size: 720p, format: HDTV, video_codec: h264, release_group: TLA, container: mkv, mimetype: video/x-matroska, type: episode, absolute_episode: [], quality: 720p HDTV, episode: []
2016-10-24 12:30:36 WARNING  Thread-18 :: [e16480a] Cannot create TVEpisode from path /media/SAMSUNG/media/downloaded/series/Black.Mirror.S02.Special.White.Chirstmas.720p.HDTV.x264-TLA.mkv
2016-10-24 12:30:36 ERROR    Thread-18 :: [e16480a] Failed doing web ui callback: Traceback (most recent call last):
  File "/home/osmc/Medusa/medusa/server/web/core/base.py", line 271, in async_call
    result = function(**kwargs)
  File "/home/osmc/Medusa/medusa/server/web/manage/handler.py", line 293, in subtitleMissedPP
    logger.debug(u'%s cannot be parsed to an episode', filename)
  File "/home/osmc/Medusa/medusa/logger.py", line 749, in __getattr__
    return getattr(self.instance, name)
AttributeError: 'Logger' object has no attribute 'debug'
Traceback (most recent call last):
  File "/home/osmc/Medusa/medusa/server/web/core/base.py", line 271, in async_call
    result = function(**kwargs)
  File "/home/osmc/Medusa/medusa/server/web/manage/handler.py", line 293, in subtitleMissedPP
    logger.debug(u'%s cannot be parsed to an episode', filename)
  File "/home/osmc/Medusa/medusa/logger.py", line 749, in __getattr__
    return getattr(self.instance, name)
AttributeError: 'Logger' object has no attribute 'debug'

# Fixed code
def subtitleMissedPP(self):
    t = PageTemplate(rh=self, filename="manage_subtitleMissedPP.mako")
    app.RELEASES_IN_PP = []
    for root, _, files in os.walk(app.TV_DOWNLOAD_DIR, topdown=False):
        for filename in sorted(files):
            if not isMediaFile(filename):
                continue

            video_path = os.path.join(root, filename)
            video_date = datetime.datetime.fromtimestamp(os.stat(video_path).st_ctime)
            video_age = datetime.datetime.today() - video_date

            tv_episode = TVEpisode.from_filepath(video_path)

            if not tv_episode:
                logger.log(
                    "Filename '{0}' cannot be parsed to an episode".format(filename),
                    logger.DEBUG,
                )
                continue

            if not tv_episode.show.subtitles:
                continue

            related_files = postProcessor.PostProcessor(
                video_path
            ).list_associated_files(video_path, base_name_only=True, subfolders=False)
            if related_files:
                continue

            age_hours = divmod(video_age.seconds, 3600)[0]
            age_minutes = divmod(video_age.seconds, 60)[0]
            if video_age.days > 0:
                age_unit = "d"
                age_value = video_age.days
            elif age_hours > 0:
                age_unit = "h"
                age_value = age_hours
            else:
                age_unit = "m"
                age_value = age_minutes

            app.RELEASES_IN_PP.append(
                {
                    "release": video_path,
                    "show": tv_episode.show.indexerid,
                    "show_name": tv_episode.show.name,
                    "season": tv_episode.season,
                    "episode": tv_episode.episode,
                    "age": age_value,
                    "age_unit": age_unit,
                    "age_raw": video_age,
                }
            )
    app.RELEASES_IN_PP = sorted(
        app.RELEASES_IN_PP, key=lambda k: k["age_raw"], reverse=True
    )

    return t.render(
        releases_in_pp=app.RELEASES_IN_PP,
        title="Missing Subtitles in Post-Process folder",
        header="Missing Subtitles in Post Process folder",
        topmenu="manage",
        controller="manage",
        action="subtitleMissedPP",
    )