# Buggy code
def run_subs_scripts(video_path, scripts, script_args):
    """Execute subtitle scripts

    :param video_path: the video path
    :type video_path: str
    :param scripts: the script commands to be executed
    :type scripts: list of str
    :param script_args: the arguments to be passed to the script
    :type script_args: list of str
    """
    for script_name in scripts:
        script_cmd = [
            piece
            for piece in re.split("( |\\\".*?\\\"|'.*?')", script_name)
            if piece.strip()
        ]

        logger.info(
            "Running subtitle %s-script: %s",
            "extra" if len(script_args) > 1 else "pre",
            script_name,
        )
        inner_cmd = script_cmd + script_args

        # use subprocess to run the command and capture output
        logger.info("Executing command: %s", inner_cmd)
        try:
            process = subprocess.Popen(
                inner_cmd,
                stdin=subprocess.PIPE,
                stdout=subprocess.PIPE,
                stderr=subprocess.STDOUT,
                cwd=sickbeard.PROG_DIR,
            )
            out, _ = process.communicate()  # @UnusedVariable
            logger.debug("Script result: %s", out)

        except Exception as error:
            logger.info("Unable to run subtitles script: %s", ex(error))

    invalidate_video_cache(video_path)


# Traceback (UnicodeEncodeError)
FINDSUBTITLES :: [d47493d] Traceback (most recent call last):
File "/home/home/SickRage/sickbeard/subtitles.py", line 338, in download_best_subs
save_subtitles(video, found_subtitles, directory=subtitles_dir, single=not sickbeard.SUBTITLES_MULTI)
File "/home/home/SickRage/lib/subliminal/core.py", line 695, in save_subtitles
with io.open(subtitle_path, 'wb') as f:
UnicodeEncodeError: 'ascii' codec can't encode character u'\xea' in position 93: ordinal not in range(128)
Traceback (most recent call last):
File "/home/home/SickRage/sickbeard/subtitles.py", line 338, in download_best_subs
save_subtitles(video, found_subtitles, directory=subtitles_dir, single=not sickbeard.SUBTITLES_MULTI)
File "/home/home/SickRage/lib/subliminal/core.py", line 695, in save_subtitles
with io.open(subtitle_path, 'wb') as f:
UnicodeEncodeError: 'ascii' codec can't encode character u'\xea' in position 93: ordinal not in range(128)

# Fixed code
def run_subs_scripts(video_path, scripts, *args):
    """Execute subtitle scripts.

    :param video_path: the video path
    :type video_path: str
    :param scripts: the script commands to be executed
    :type scripts: list of str
    :param args: the arguments to be passed to the script
    :type args: list of str
    """
    for script_name in scripts:
        script_cmd = [
            piece
            for piece in re.split("( |\\\".*?\\\"|'.*?')", script_name)
            if piece.strip()
        ]
        script_cmd.extend(str(arg) for arg in args)

        logger.info(
            "Running subtitle %s-script: %s",
            "extra" if len(args) > 1 else "pre",
            script_name,
        )

        # use subprocess to run the command and capture output
        logger.info("Executing command: %s", script_cmd)
        try:
            process = subprocess.Popen(
                script_cmd,
                stdin=subprocess.PIPE,
                stdout=subprocess.PIPE,
                stderr=subprocess.STDOUT,
                cwd=sickbeard.PROG_DIR,
            )
            out, _ = process.communicate()  # @UnusedVariable
            logger.debug("Script result: %s", out)

        except Exception as error:
            logger.info("Unable to run subtitles script: %s", ex(error))

    invalidate_video_cache(video_path)