Add control for command where ffmpeg and not

This commit is contained in:
Dark1291 2025-02-04 15:47:29 +01:00
parent 45d5f5b971
commit e5ee9f83af

View File

@ -2,6 +2,7 @@
import io import io
import os import os
import glob
import sys import sys
import time import time
import shutil import shutil
@ -294,6 +295,18 @@ class OsSummary:
self.ffprobe_path = None self.ffprobe_path = None
self.ffplay_path = None self.ffplay_path = None
def get_binary_directory(self):
"""Get the binary directory based on OS."""
system = platform.system().lower()
home = os.path.expanduser('~')
if system == 'windows':
return os.path.join(os.path.splitdrive(home)[0] + os.path.sep, 'binary')
elif system == 'darwin':
return os.path.join(home, 'Applications', 'binary')
else: # linux
return os.path.join(home, '.local', 'bin', 'binary')
def get_executable_version(self, command: list): def get_executable_version(self, command: list):
""" """
Get the version of a given command-line executable. Get the version of a given command-line executable.
@ -396,24 +409,11 @@ class OsSummary:
sys.exit(0) sys.exit(0)
def get_system_summary(self): def get_system_summary(self):
"""
Generate a summary of the system environment.
Includes:
- Python version and implementation details.
- Operating system and architecture.
- Versions of `ffmpeg` and `ffprobe` executables.
- Installed Python libraries as listed in `requirements.txt`.
"""
# Check if Python is the official CPython
self.check_python_version() self.check_python_version()
# Check internet connectivity
InternManager().check_internet() InternManager().check_internet()
console.print("[bold blue]System Summary[/bold blue][white]:") console.print("[bold blue]System Summary[/bold blue][white]:")
# Python version and platform # Python info
python_version = sys.version.split()[0] python_version = sys.version.split()[0]
python_implementation = platform.python_implementation() python_implementation = platform.python_implementation()
arch = platform.machine() arch = platform.machine()
@ -422,34 +422,56 @@ class OsSummary:
console.print(f"[cyan]Python[white]: [bold red]{python_version} ({python_implementation} {arch}) - {os_info} ({glibc_version})[/bold red]") console.print(f"[cyan]Python[white]: [bold red]{python_version} ({python_implementation} {arch}) - {os_info} ({glibc_version})[/bold red]")
logging.info(f"Python: {python_version} ({python_implementation} {arch}) - {os_info} ({glibc_version})") logging.info(f"Python: {python_version} ({python_implementation} {arch}) - {os_info} ({glibc_version})")
# FFmpeg detection
binary_dir = self.get_binary_directory()
system = platform.system().lower()
arch = platform.machine().lower()
# Use the 'where' command on Windows and 'which' command on Unix-like systems # Map architecture names
system_platform = platform.system().lower() arch_map = {
command = 'where' if system_platform == 'windows' else 'which' 'amd64': 'x64',
'x86_64': 'x64',
'x64': 'x64',
'arm64': 'arm64',
'aarch64': 'arm64',
'armv7l': 'arm',
'i386': 'ia32',
'i686': 'ia32'
}
arch = arch_map.get(arch, arch)
# Locate ffmpeg and ffprobe from the PATH environment # Check binary directory
if self.ffmpeg_path is not None and "binary" not in self.ffmpeg_path: if os.path.exists(binary_dir):
self.ffmpeg_path = self.check_ffmpeg_location([command, 'ffmpeg'])
# Search for any file containing 'ffmpeg' and the architecture
if self.ffprobe_path is not None and "binary" not in self.ffprobe_path: ffmpeg_files = glob.glob(os.path.join(binary_dir, f'*ffmpeg*{arch}*'))
self.ffprobe_path = self.check_ffmpeg_location([command, 'ffprobe']) ffprobe_files = glob.glob(os.path.join(binary_dir, f'*ffprobe*{arch}*'))
# If ffmpeg or ffprobe is not located, fall back to using the check_ffmpeg function if ffmpeg_files and ffprobe_files:
if self.ffmpeg_path is None or self.ffprobe_path is None: self.ffmpeg_path = ffmpeg_files[0]
self.ffprobe_path = ffprobe_files[0]
# Set executable permissions if needed
if system != 'windows':
os.chmod(self.ffmpeg_path, 0o755)
os.chmod(self.ffprobe_path, 0o755)
else:
self.ffmpeg_path, self.ffprobe_path, self.ffplay_path = check_ffmpeg()
else:
self.ffmpeg_path, self.ffprobe_path, self.ffplay_path = check_ffmpeg() self.ffmpeg_path, self.ffprobe_path, self.ffplay_path = check_ffmpeg()
# If still not found, print error and exit if not self.ffmpeg_path or not self.ffprobe_path:
if self.ffmpeg_path is None or self.ffprobe_path is None:
console.log("[red]Can't locate ffmpeg or ffprobe") console.log("[red]Can't locate ffmpeg or ffprobe")
sys.exit(0) sys.exit(0)
ffmpeg_version = self.get_executable_version([self.ffprobe_path, '-version']) ffmpeg_version = self.get_executable_version([self.ffmpeg_path, '-version'])
ffprobe_version = self.get_executable_version([self.ffprobe_path, '-version']) ffprobe_version = self.get_executable_version([self.ffprobe_path, '-version'])
console.print(f"[cyan]Path[white]: [red]ffmpeg [bold yellow]'{self.ffmpeg_path}'[/bold yellow][white], [red]ffprobe '[bold yellow]{self.ffprobe_path}'[/bold yellow]") console.print(f"[cyan]Path[white]: [red]ffmpeg [bold yellow]'{self.ffmpeg_path}'[/bold yellow][white], [red]ffprobe '[bold yellow]{self.ffprobe_path}'[/bold yellow]")
console.print(f"[cyan]Exe versions[white]: [bold red]ffmpeg {ffmpeg_version}, ffprobe {ffprobe_version}[/bold red]") console.print(f"[cyan]Exe versions[white]: [bold red]ffmpeg {ffmpeg_version}, ffprobe {ffprobe_version}[/bold red]")
# Check if requirements.txt exists, if not on pyinstaller # Handle requirements.txt
if not getattr(sys, 'frozen', False): if not getattr(sys, 'frozen', False):
requirements_file = 'requirements.txt' requirements_file = 'requirements.txt'
@ -459,19 +481,14 @@ class OsSummary:
requirements_file requirements_file
) )
# Read the optional libraries from the requirements file, get only name without version if "library==1.0.0"
optional_libraries = [line.strip().split("=")[0] for line in open(requirements_file, 'r', encoding='utf-8-sig')] optional_libraries = [line.strip().split("=")[0] for line in open(requirements_file, 'r', encoding='utf-8-sig')]
# Check if libraries are installed and prompt to install missing ones
for lib in optional_libraries: for lib in optional_libraries:
installed_version = self.get_library_version(lib) installed_version = self.get_library_version(lib)
if 'not installed' in installed_version: if 'not installed' in installed_version:
user_response = msg.ask(f"{lib} is not installed. Do you want to install it? (yes/no)", default="y") user_response = msg.ask(f"{lib} is not installed. Do you want to install it? (yes/no)", default="y")
if user_response.lower().strip() in ["yes", "y"]: if user_response.lower().strip() in ["yes", "y"]:
self.install_library(lib) self.install_library(lib)
else: else:
logging.info(f"Library: {installed_version}") logging.info(f"Library: {installed_version}")
@ -479,7 +496,6 @@ class OsSummary:
logging.info(f"Libraries: {', '.join([self.get_library_version(lib) for lib in optional_libraries])}") logging.info(f"Libraries: {', '.join([self.get_library_version(lib) for lib in optional_libraries])}")
# OTHER
os_manager = OsManager() os_manager = OsManager()
internet_manager = InternManager() internet_manager = InternManager()
os_summary = OsSummary() os_summary = OsSummary()