mirror of
https://github.com/Arrowar/StreamingCommunity.git
synced 2025-06-06 11:35:29 +00:00
Change ffmpeg check
This commit is contained in:
parent
673f53d97a
commit
1f8a534069
@ -288,24 +288,35 @@ def check_ffmpeg() -> Tuple[Optional[str], Optional[str], Optional[str]]:
|
|||||||
using the FFMPEGDownloader class.
|
using the FFMPEGDownloader class.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
if platform.system().lower() == 'windows':
|
system_platform = platform.system().lower()
|
||||||
|
|
||||||
|
# Check for Windows platform
|
||||||
|
if system_platform == 'windows':
|
||||||
|
|
||||||
|
# Using subprocess.call to check the executables and subprocess.check_output to get the path
|
||||||
ffmpeg_path = subprocess.check_output(['where', 'ffmpeg'], text=True).strip().split('\n')[0] if subprocess.call(['where', 'ffmpeg'], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) == 0 else None
|
ffmpeg_path = subprocess.check_output(['where', 'ffmpeg'], text=True).strip().split('\n')[0] if subprocess.call(['where', 'ffmpeg'], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) == 0 else None
|
||||||
ffprobe_path = subprocess.check_output(['where', 'ffprobe'], text=True).strip().split('\n')[0] if subprocess.call(['where', 'ffprobe'], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) == 0 else None
|
ffprobe_path = subprocess.check_output(['where', 'ffprobe'], text=True).strip().split('\n')[0] if subprocess.call(['where', 'ffprobe'], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) == 0 else None
|
||||||
ffplay_path = subprocess.check_output(['where', 'ffplay'], text=True).strip().split('\n')[0] if subprocess.call(['where', 'ffplay'], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) == 0 else None
|
ffplay_path = subprocess.check_output(['where', 'ffplay'], text=True).strip().split('\n')[0] if subprocess.call(['where', 'ffplay'], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) == 0 else None
|
||||||
|
|
||||||
|
# If all three executables are found, return their paths
|
||||||
if all([ffmpeg_path, ffprobe_path, ffplay_path]):
|
if all([ffmpeg_path, ffprobe_path, ffplay_path]):
|
||||||
return ffmpeg_path, ffprobe_path, ffplay_path
|
return ffmpeg_path, ffprobe_path, ffplay_path
|
||||||
|
|
||||||
|
# Check for Unix-like systems (Linux, macOS)
|
||||||
else:
|
else:
|
||||||
ffmpeg_path = shutil.which('ffmpeg')
|
ffmpeg_path = shutil.which('ffmpeg')
|
||||||
ffprobe_path = shutil.which('ffprobe')
|
ffprobe_path = shutil.which('ffprobe')
|
||||||
ffplay_path = shutil.which('ffplay')
|
ffplay_path = shutil.which('ffplay')
|
||||||
|
|
||||||
|
# If all three executables are found, return their paths
|
||||||
if all([ffmpeg_path, ffprobe_path, ffplay_path]):
|
if all([ffmpeg_path, ffprobe_path, ffplay_path]):
|
||||||
return ffmpeg_path, ffprobe_path, ffplay_path
|
return ffmpeg_path, ffprobe_path, ffplay_path
|
||||||
|
|
||||||
|
# If executables were not found, attempt to download FFmpeg
|
||||||
downloader = FFMPEGDownloader()
|
downloader = FFMPEGDownloader()
|
||||||
return downloader.download()
|
return downloader.download()
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error(f"Error checking FFmpeg: {e}")
|
# Log any unexpected errors that may occur during the check or download process
|
||||||
|
logging.error(f"Error checking or downloading FFmpeg executables: {e}")
|
||||||
return None, None, None
|
return None, None, None
|
@ -353,20 +353,17 @@ class OsSummary:
|
|||||||
console.print(f"{command[0]} not found", style="bold red")
|
console.print(f"{command[0]} not found", style="bold red")
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
def check_ffmpeg_location(self, command: list):
|
def check_ffmpeg_location(self, command: list) -> str:
|
||||||
"""
|
"""
|
||||||
Run 'where ffmpeg' command to check FFmpeg's location.
|
Check if a specific executable (ffmpeg or ffprobe) is located using the given command.
|
||||||
|
Returns the path of the executable or None if not found.
|
||||||
Returns:
|
|
||||||
str: Location of FFmpeg executable or None if not found
|
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
result = subprocess.check_output(command, stderr=subprocess.STDOUT, text=True).strip()
|
result = subprocess.check_output(command, text=True).strip()
|
||||||
return result
|
return result.split('\n')[0] if result else None
|
||||||
|
|
||||||
except subprocess.CalledProcessError:
|
except subprocess.CalledProcessError:
|
||||||
console.print("FFmpeg not found in system PATH", style="bold red")
|
return None
|
||||||
sys.exit(0)
|
|
||||||
|
|
||||||
def get_library_version(self, lib_name: str):
|
def get_library_version(self, lib_name: str):
|
||||||
"""
|
"""
|
||||||
@ -467,27 +464,24 @@ 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})")
|
||||||
|
|
||||||
# Usa il comando 'where' su Windows
|
# Use the 'where' command on Windows and 'which' command on Unix-like systems
|
||||||
if platform.system() == "Windows":
|
system_platform = platform.system().lower()
|
||||||
command = 'where'
|
command = 'where' if system_platform == 'windows' else 'which'
|
||||||
|
|
||||||
# Usa il comando 'which' su Unix/Linux
|
# Locate ffmpeg and ffprobe from the PATH environment
|
||||||
else:
|
if self.ffmpeg_path is not None and "binary" not in self.ffmpeg_path:
|
||||||
command = 'which'
|
|
||||||
|
|
||||||
# Locate ffmpeg and ffprobe from path enviroment
|
|
||||||
if self.ffmpeg_path != None and "binary" not in self.ffmpeg_path:
|
|
||||||
self.ffmpeg_path = self.check_ffmpeg_location([command, 'ffmpeg'])
|
self.ffmpeg_path = self.check_ffmpeg_location([command, 'ffmpeg'])
|
||||||
|
|
||||||
if self.ffprobe_path != None and "binary" not in self.ffprobe_path:
|
if self.ffprobe_path is not None and "binary" not in self.ffprobe_path:
|
||||||
self.ffprobe_path = self.check_ffmpeg_location([command, 'ffprobe'])
|
self.ffprobe_path = self.check_ffmpeg_location([command, 'ffprobe'])
|
||||||
|
|
||||||
# Locate ffmpeg from bin installation
|
# If ffmpeg or ffprobe is not located, fall back to using the check_ffmpeg function
|
||||||
if self.ffmpeg_path is None or self.ffprobe_path is None:
|
if self.ffmpeg_path is None or self.ffprobe_path is None:
|
||||||
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 self.ffmpeg_path is None or self.ffprobe_path is None:
|
if self.ffmpeg_path is None or self.ffprobe_path is None:
|
||||||
console.log("[red]Cant 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.ffprobe_path, '-version'])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user