From 28683b70285cd8644b675249d46fd6d73c4b38f4 Mon Sep 17 00:00:00 2001 From: WyattBlue Date: Thu, 3 Oct 2024 21:18:26 -0400 Subject: [PATCH] Inline `open_with_system_default()` --- auto_editor/edit.py | 26 +++++++++++++++++++------- auto_editor/utils/func.py | 25 ------------------------- 2 files changed, 19 insertions(+), 32 deletions(-) diff --git a/auto_editor/edit.py b/auto_editor/edit.py index d596e822b..c3b97d19f 100644 --- a/auto_editor/edit.py +++ b/auto_editor/edit.py @@ -1,6 +1,8 @@ from __future__ import annotations import os +import sys +from subprocess import run from typing import Any from auto_editor.ffwrapper import FFmpeg, FileInfo, initFileInfo @@ -15,7 +17,6 @@ from auto_editor.utils.chunks import Chunk, Chunks from auto_editor.utils.cmdkw import ParserError, parse_with_palet, pAttr, pAttrs from auto_editor.utils.container import Container, container_constructor -from auto_editor.utils.func import open_with_system_default from auto_editor.utils.log import Log from auto_editor.utils.types import Args @@ -356,10 +357,21 @@ def pad_chunk(chunk: Chunk, total: int) -> Chunks: if not args.no_open and export in ("default", "audio"): if args.player is None: - if (ret := open_with_system_default(output)) is not None: - log.warning(ret) + if sys.platform == "win32": + try: + os.startfile(output) + except OSError: + log.warning(f"Could not find application to open file: {output}") + else: + try: # MacOS case + run(["open", output]) + except Exception: + try: # WSL2 case + run(["cmd.exe", "/C", "start", output]) + except Exception: + try: # Linux case + run(["xdg-open", output]) + except Exception: + log.warning(f"Could not open output file: {output}") else: - import subprocess - from shlex import split - - subprocess.run(split(args.player) + [output]) + run(__import__("shlex").split(args.player) + [output]) diff --git a/auto_editor/utils/func.py b/auto_editor/utils/func.py index 5fc3e5445..1e7a6d928 100644 --- a/auto_editor/utils/func.py +++ b/auto_editor/utils/func.py @@ -133,31 +133,6 @@ def human_readable_time(time_in_secs: float) -> str: return f"{time_in_secs} {units}" -def open_with_system_default(path: str) -> str | None: - import sys - from subprocess import run - - if sys.platform == "win32": - from os import startfile - - try: - startfile(path) - except OSError: - return f"Could not find application to open file: {path}" - else: - try: # MacOS case - run(["open", path]) - except Exception: - try: # WSL2 case - run(["cmd.exe", "/C", "start", path]) - except Exception: - try: # Linux case - run(["xdg-open", path]) - except Exception: - return f"Could not open output file: {path}" - return None - - def append_filename(path: str, val: str) -> str: from os.path import splitext