From a8982cf8c74598d453c3508973ed804716d844df Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Thu, 3 Oct 2019 10:14:58 +0300 Subject: [PATCH] Remove extension from lottie2ffmpeg and fix crash when lottieconverter not present --- .../util/{lottie2ffmpeg.sh => lottie2ffmpeg} | 0 mautrix_telegram/util/tgs_converter.py | 9 +++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) rename mautrix_telegram/util/{lottie2ffmpeg.sh => lottie2ffmpeg} (100%) diff --git a/mautrix_telegram/util/lottie2ffmpeg.sh b/mautrix_telegram/util/lottie2ffmpeg similarity index 100% rename from mautrix_telegram/util/lottie2ffmpeg.sh rename to mautrix_telegram/util/lottie2ffmpeg diff --git a/mautrix_telegram/util/tgs_converter.py b/mautrix_telegram/util/tgs_converter.py index 3e3106d1..84f5696f 100644 --- a/mautrix_telegram/util/tgs_converter.py +++ b/mautrix_telegram/util/tgs_converter.py @@ -24,8 +24,13 @@ log: logging.Logger = logging.getLogger("mau.util.tgs") converters: Dict[str, Callable[[bytes, int, int, Any], Awaitable[Tuple[str, bytes]]]] = {} -lottieconverter = os.path.abspath(shutil.which("lottieconverter")) -lottie2ffmpeg = os.path.abspath(shutil.which("lottie2ffmpeg.sh")) +def abswhich(program: Optional[str]) -> Optional[str]: + path = shutil.which(program) + return os.path.abspath(path) if path else None + + +lottieconverter = abswhich("lottieconverter") +lottie2ffmpeg = abswhich("lottie2ffmpeg") if lottieconverter: async def tgs_to_png(file: bytes, width: int, height: int, **_: Any) -> Tuple[str, bytes]: