Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider to use sys.stderr instead of sys.stdout when frozen #14

Open
Dadangdut33 opened this issue Dec 11, 2023 · 0 comments
Open

Consider to use sys.stderr instead of sys.stdout when frozen #14

Dadangdut33 opened this issue Dec 11, 2023 · 0 comments

Comments

@Dadangdut33
Copy link

Can you use stderr when frozen instead of stdout, sometimes frozen application don't have access to stdout because they don't have any console which is gonna make the download fail because this library print directly into stdout and stdout is None

You can change it or simply add this:

if getattr(sys, "frozen", False):
    sys.stdout = sys.stderr

Because of this, to get around this problem in my project i did a little patching:

# modify static_ffmpeg add_paths
def add_ffmpeg_to_path(weak=False) -> bool:
    """Add the ffmpeg executable to the path"""
    if getattr(sys, "frozen", False):
        # pylint: disable=import-outside-toplevel, protected-access
        from static_ffmpeg import _add_paths, run
        run.sys.stdout = sys.stderr
        if weak:
            has_ffmpeg = _add_paths._has("ffmpeg") is not None
            has_ffprobe = _add_paths._has("ffprobe") is not None
            if has_ffmpeg and has_ffprobe:
                return False
        ffmpeg, _ = run.get_or_fetch_platform_executables_else_raise()
        os.environ["PATH"] = os.pathsep.join([os.path.dirname(ffmpeg), os.environ["PATH"]])
        return True
    else:
        # pylint: disable=import-outside-toplevel
        from static_ffmpeg import _add_paths
        return _add_paths.add_paths()

Thank you 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant