Optional parameter to check if the encoder exists

If `must_exists` is `False` when intializing `EncoderFFmpeg()`, skip
skip checking whether the FFmpeg binary exists.

Fixes #722.
This commit is contained in:
Ritiek Malhotra
2020-05-19 12:49:00 +05:30
parent 9c97f33aa2
commit debe7ee902
3 changed files with 8 additions and 8 deletions

View File

@@ -37,12 +37,12 @@ class EncoderBase(ABC):
"""
@abstractmethod
def __init__(self, encoder_path, loglevel, additional_arguments=[]):
def __init__(self, encoder_path, must_exist, loglevel, additional_arguments=[]):
"""
This method must make sure whether specified encoder
is available under PATH.
"""
if shutil.which(encoder_path) is None:
if must_exist and shutil.which(encoder_path) is None:
raise EncoderNotFoundError(
"{} executable does not exist or was not found in PATH.".format(
encoder_path

View File

@@ -27,11 +27,11 @@ RULES = {
class EncoderFFmpeg(EncoderBase):
def __init__(self, encoder_path="ffmpeg"):
def __init__(self, encoder_path="ffmpeg", must_exist=True):
_loglevel = "-hide_banner -nostats -v panic"
_additional_arguments = ["-b:a", "192k", "-vn"]
try:
super().__init__(encoder_path, _loglevel, _additional_arguments)
super().__init__(encoder_path, must_exist, _loglevel, _additional_arguments)
except EncoderNotFoundError as e:
raise FFmpegNotFoundError(e.args[0])
self._rules = RULES