Skip to content

Commit 847ab23

Browse files
committed
* ffxxx_path attributes to return None if not installed
* installed() - added optional `return_path` argument - returns the path or `None` if `return_path=True` * added typehints
1 parent 013fadf commit 847ab23

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

src/ffmpeg_downloader/__init__.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
__version__ = "0.3.0"
24

35
import os
@@ -26,25 +28,29 @@ def add_path():
2628
os.environ["PATH"] = os.pathsep.join([os.environ["PATH"], _.ffmpeg_path()])
2729

2830

29-
def installed(bin_name="ffmpeg"):
31+
def installed(
32+
bin_name: str = "ffmpeg", *, return_path: bool = False
33+
) -> bool | str | None:
3034
"""True if FFmpeg binary is installed
3135
3236
:param bin_name: FFmpeg command name, defaults to 'ffmpeg'
33-
:type bin_name: 'ffmpeg', 'ffprobe', or 'ffplay', optional
37+
:param return_path: True to return the valid path (or None if not installed),
38+
defaults to False
3439
:return: True if installed
35-
:rtype: bool
3640
"""
3741

38-
return os.path.isfile(_.ffmpeg_path(bin_name))
42+
p = _.ffmpeg_path(bin_name)
43+
tf = os.path.isfile(p)
44+
return tf if not return_path else p if tf else None
3945

4046

4147
def __getattr__(name): # per PEP 562
4248
try:
4349
return {
4450
"ffmpeg_dir": lambda: _.ffmpeg_path(),
45-
"ffmpeg_path": lambda: _.ffmpeg_path("ffmpeg"),
46-
"ffprobe_path": lambda: _.ffmpeg_path("ffprobe"),
47-
"ffplay_path": lambda: _.ffmpeg_path("ffplay"),
51+
"ffmpeg_path": lambda: installed("ffmpeg", return_path=True),
52+
"ffprobe_path": lambda: installed("ffprobe", return_path=True),
53+
"ffplay_path": lambda: installed("ffplay", return_path=True),
4854
"ffmpeg_version": _.ffmpeg_version,
4955
}[name]()
5056
except:

0 commit comments

Comments
 (0)