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.
This commit is contained in:
rlaphoenix 2024-04-24 05:10:20 +01:00
parent 677fd9c56a
commit fd64e6acf4
2 changed files with 24 additions and 23 deletions

View File

@ -1,34 +1,45 @@
import shutil
import sys import sys
from pathlib import Path
from devine.core.utilities import get_binary_path from typing import Optional
__shaka_platform = { __shaka_platform = {
"win32": "win", "win32": "win",
"darwin": "osx" "darwin": "osx"
}.get(sys.platform, sys.platform) }.get(sys.platform, sys.platform)
FFMPEG = get_binary_path("ffmpeg")
FFProbe = get_binary_path("ffprobe") def find(*names: str) -> Optional[Path]:
FFPlay = get_binary_path("ffplay") """Find the path of the first found binary name."""
SubtitleEdit = get_binary_path("SubtitleEdit") for name in names:
ShakaPackager = get_binary_path( 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", "shaka-packager",
"packager", "packager",
f"packager-{__shaka_platform}", f"packager-{__shaka_platform}",
f"packager-{__shaka_platform}-x64" f"packager-{__shaka_platform}-x64"
) )
Aria2 = get_binary_path("aria2c", "aria2") Aria2 = find("aria2c", "aria2")
CCExtractor = get_binary_path( CCExtractor = find(
"ccextractor", "ccextractor",
"ccextractorwin", "ccextractorwin",
"ccextractorwinfull" "ccextractorwinfull"
) )
HolaProxy = get_binary_path("hola-proxy") HolaProxy = find("hola-proxy")
MPV = get_binary_path("mpv") MPV = find("mpv")
Caddy = get_binary_path("caddy") Caddy = find("caddy")
__all__ = ( __all__ = (
"FFMPEG", "FFProbe", "FFPlay", "SubtitleEdit", "ShakaPackager", "FFMPEG", "FFProbe", "FFPlay", "SubtitleEdit", "ShakaPackager",
"Aria2", "CCExtractor", "HolaProxy", "MPV", "Caddy" "Aria2", "CCExtractor", "HolaProxy", "MPV", "Caddy", "find"
) )

View File

@ -3,7 +3,6 @@ import contextlib
import importlib.util import importlib.util
import os import os
import re import re
import shutil
import socket import socket
import sys import sys
import time import time
@ -87,15 +86,6 @@ def import_module_by_path(path: Path) -> ModuleType:
return module 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: def sanitize_filename(filename: str, spacer: str = ".") -> str:
""" """
Sanitize a string to be filename safe. Sanitize a string to be filename safe.