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
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"
)

View File

@ -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.