From fd64e6acf465b55d19f123b211b1bbae792cebab Mon Sep 17 00:00:00 2001 From: rlaphoenix Date: Wed, 24 Apr 2024 05:10:20 +0100 Subject: [PATCH] refactor(utilities): Remove get_binary_path, use binaries.find instead The function now located at core/binaries should only be used by services to find a specific binary not listed in there already, or if the name of the binary needed by your service differs. --- devine/core/binaries.py | 37 ++++++++++++++++++++++++------------- devine/core/utilities.py | 10 ---------- 2 files changed, 24 insertions(+), 23 deletions(-) diff --git a/devine/core/binaries.py b/devine/core/binaries.py index 096dde9..095b245 100644 --- a/devine/core/binaries.py +++ b/devine/core/binaries.py @@ -1,34 +1,45 @@ +import shutil import sys - -from devine.core.utilities import get_binary_path +from pathlib import Path +from typing import Optional __shaka_platform = { "win32": "win", "darwin": "osx" }.get(sys.platform, sys.platform) -FFMPEG = get_binary_path("ffmpeg") -FFProbe = get_binary_path("ffprobe") -FFPlay = get_binary_path("ffplay") -SubtitleEdit = get_binary_path("SubtitleEdit") -ShakaPackager = get_binary_path( + +def find(*names: str) -> Optional[Path]: + """Find the path of the first found binary name.""" + for name in names: + path = shutil.which(name) + if path: + return Path(path) + return None + + +FFMPEG = find("ffmpeg") +FFProbe = find("ffprobe") +FFPlay = find("ffplay") +SubtitleEdit = find("SubtitleEdit") +ShakaPackager = find( "shaka-packager", "packager", f"packager-{__shaka_platform}", f"packager-{__shaka_platform}-x64" ) -Aria2 = get_binary_path("aria2c", "aria2") -CCExtractor = get_binary_path( +Aria2 = find("aria2c", "aria2") +CCExtractor = find( "ccextractor", "ccextractorwin", "ccextractorwinfull" ) -HolaProxy = get_binary_path("hola-proxy") -MPV = get_binary_path("mpv") -Caddy = get_binary_path("caddy") +HolaProxy = find("hola-proxy") +MPV = find("mpv") +Caddy = find("caddy") __all__ = ( "FFMPEG", "FFProbe", "FFPlay", "SubtitleEdit", "ShakaPackager", - "Aria2", "CCExtractor", "HolaProxy", "MPV", "Caddy" + "Aria2", "CCExtractor", "HolaProxy", "MPV", "Caddy", "find" ) diff --git a/devine/core/utilities.py b/devine/core/utilities.py index 8faefc0..81c0a4d 100644 --- a/devine/core/utilities.py +++ b/devine/core/utilities.py @@ -3,7 +3,6 @@ import contextlib import importlib.util import os import re -import shutil import socket import sys import time @@ -87,15 +86,6 @@ def import_module_by_path(path: Path) -> ModuleType: return module -def get_binary_path(*names: str) -> Optional[Path]: - """Find the path of the first found binary name.""" - for name in names: - path = shutil.which(name) - if path: - return Path(path) - return None - - def sanitize_filename(filename: str, spacer: str = ".") -> str: """ Sanitize a string to be filename safe.