From 2ba42ac071d8ee6f19d5e5bcffd8d00d49cd6d97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian-Robert=20St=C3=B6ter?= Date: Mon, 8 Jul 2019 11:51:08 +0200 Subject: [PATCH] check if ffmpeg and ffprobe exists, addressing #18 --- stempeg/__init__.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/stempeg/__init__.py b/stempeg/__init__.py index fa95ccf..0322aeb 100644 --- a/stempeg/__init__.py +++ b/stempeg/__init__.py @@ -11,8 +11,29 @@ import soundfile as sf import argparse import pkg_resources +import shutil -__version__ = "0.1.6" +__version__ = "0.1.7" + + +def cmd_exist(cmd): + try: + from shutil import which + return shutil.which(cmd) is not None + except ImportError: + return any( + os.access(os.path.join(path, cmd), os.X_OK) + for path in os.environ["PATH"].split(os.pathsep) + ) + +def ffmpeg_and_ffprobe_exists(): + return cmd_exist("ffmpeg") and cmd_exist("ffprobe") + + +if not ffmpeg_and_ffprobe_exists(): + raise RuntimeError('ffmpeg or ffprobe could not be found! ' + 'Please install them before using stempeg. ' + 'See: https://github.com/faroit/stempeg') def example_stem_path():