# Buggy code
def subtitles_download_in_pp():  # pylint: disable=too-many-locals, too-many-branches, too-many-statements
    """Check for needed subtitles in the post process folder."""
    from sickbeard.tv import TVEpisode

    logger.info("Checking for needed subtitles in Post-Process folder")

    # Check if PP folder is set
    if not sickbeard.TV_DOWNLOAD_DIR or not os.path.isdir(sickbeard.TV_DOWNLOAD_DIR):
        logger.warning(
            'You must set a valid post-process folder in "Post Processing" settings'
        )
        return

    # Search for all wanted languages
    if not wanted_languages():
        return

    unpack_rar_files(sickbeard.TV_DOWNLOAD_DIR)

    run_post_process = False
    for root, _, files in os.walk(sickbeard.TV_DOWNLOAD_DIR, topdown=False):
        for filename in sorted(files):
            # Delete unwanted subtitles before downloading new ones
            delete_unwanted_subtitles(root, filename)

            if not isMediaFile(filename):
                continue

            video_path = os.path.join(root, filename)
            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:
                logger.debug(
                    "Subtitle disabled for show: %s. Running post-process to PP it",
                    filename,
                )
                run_post_process = True
                continue

            # 'postpone' should not consider existing subtitles from db.
            tv_episode.subtitles = []
            downloaded_languages = download_subtitles(
                tv_episode,
                video_path=video_path,
                subtitles=False,
                embedded_subtitles=False,
            )

            # Don't run post processor unless at least one file has all of the needed subtitles OR
            # if user don't want to ignore embedded subtitles and wants to consider 'unknown' as wanted sub,
            # and .mkv has one.
            if not run_post_process and (
                not needs_subtitles(downloaded_languages)
                or processTV.has_matching_unknown_subtitles(video_path)
            ):
                run_post_process = True

    if run_post_process:
        logger.info(
            "Starting post-process with default settings now that we found subtitles"
        )
        processTV.processDir(sickbeard.TV_DOWNLOAD_DIR)


# Traceback (ValueError)
FINDSUBTITLES :: [13ce2b7] Exception generated in thread FINDSUBTITLES: Path does not exist
Traceback (most recent call last):
File "/volume1/@appstore/sickbeard-custom/var/SickBeard/sickbeard/scheduler.py", line 106, in run
self.action.run(self.force)
File "/volume1/@appstore/sickbeard-custom/var/SickBeard/sickbeard/subtitles.py", line 745, in run
self.subtitles_download_in_pp()
File "/volume1/@appstore/sickbeard-custom/var/SickBeard/sickbeard/subtitles.py", line 701, in subtitles_download_in_pp
processTV.has_matching_unknown_subtitles(video_path)):
File "/volume1/@appstore/sickbeard-custom/var/SickBeard/sickbeard/processTV.py", line 699, in has_matching_unknown_subtitles
Language('und') in get_embedded_subtitles(video_path)
File "/volume1/@appstore/sickbeard-custom/var/SickBeard/sickbeard/processTV.py", line 710, in get_embedded_subtitles
subliminal_video = scan_video(video_path)
File "/usr/local/sickbeard-custom/var/SickBeard/lib/subliminal/core.py", line 370, in scan_video
raise ValueError('Path does not exist')
ValueError: Path does not exist

# Fixed code
def subtitles_download_in_pp():  # pylint: disable=too-many-locals, too-many-branches, too-many-statements
    """Check for needed subtitles in the post process folder."""
    from sickbeard.tv import TVEpisode

    logger.info("Checking for needed subtitles in Post-Process folder")

    # Check if PP folder is set
    if not sickbeard.TV_DOWNLOAD_DIR or not os.path.isdir(sickbeard.TV_DOWNLOAD_DIR):
        logger.warning(
            'You must set a valid post-process folder in "Post Processing" settings'
        )
        return

    # Search for all wanted languages
    if not wanted_languages():
        return

    unpack_rar_files(sickbeard.TV_DOWNLOAD_DIR)

    run_post_process = False
    for root, _, files in os.walk(sickbeard.TV_DOWNLOAD_DIR, topdown=False):
        for filename in sorted(files):
            # Delete unwanted subtitles before downloading new ones
            delete_unwanted_subtitles(root, filename)

            if not isMediaFile(filename):
                continue

            video_path = os.path.join(root, filename)
            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:
                logger.debug(
                    "Subtitle disabled for show: %s. Running post-process to PP it",
                    filename,
                )
                run_post_process = True
                continue

            # 'postpone' should not consider existing subtitles from db.
            tv_episode.subtitles = []
            downloaded_languages = download_subtitles(
                tv_episode,
                video_path=video_path,
                subtitles=False,
                embedded_subtitles=False,
            )

            # Don't run post processor unless at least one file has all of the needed subtitles OR
            # if user don't want to ignore embedded subtitles and wants to consider 'unknown' as wanted sub,
            # and .mkv has one.
            if (
                not sickbeard.PROCESS_AUTOMATICALLY
                and not run_post_process
                and (
                    not needs_subtitles(downloaded_languages)
                    or processTV.has_matching_unknown_subtitles(video_path)
                )
            ):
                run_post_process = True

    if run_post_process:
        logger.info(
            "Starting post-process with default settings now that we found subtitles"
        )
        processTV.processDir(sickbeard.TV_DOWNLOAD_DIR)