Skip to content

Commit

Permalink
refactor(utilities): Remove get_binary_path(), use binaries.find() in…
Browse files Browse the repository at this point in the history
…stead

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.
  • Loading branch information
rlaphoenix committed Apr 24, 2024
1 parent 677fd9c commit b98442f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 23 deletions.
37 changes: 24 additions & 13 deletions devine/core/binaries.py
Original file line number Diff line number Diff line change
@@ -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"
)
10 changes: 0 additions & 10 deletions devine/core/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import importlib.util
import os
import re
import shutil
import socket
import sys
import time
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit b98442f

Please sign in to comment.