updating and refactoring codebase for improved performance and maintainability

This commit is contained in:
2026-05-03 17:29:32 -07:00
parent b7d3dc5f2d
commit 77cab1bd27
17 changed files with 590 additions and 294 deletions
+19 -7
View File
@@ -4,13 +4,7 @@ from __future__ import annotations
import json
import hashlib
import subprocess
import shutil
try:
import ffmpeg # type: ignore
except Exception:
ffmpeg = None # type: ignore
import os
import base64
import logging
@@ -23,6 +17,22 @@ from urllib.parse import urlparse
from SYS.utils_constant import mime_maps
_ffmpeg_mod: Any = None
_ffmpeg_checked = False
def _get_ffmpeg():
"""Lazily return the ffmpeg module, or None if unavailable."""
global _ffmpeg_mod, _ffmpeg_checked
if not _ffmpeg_checked:
try:
import ffmpeg as _f # type: ignore
_ffmpeg_mod = _f
except Exception:
_ffmpeg_mod = None
_ffmpeg_checked = True
return _ffmpeg_mod
try:
import cbor2
except ImportError:
@@ -191,6 +201,7 @@ def ffprobe(file_path: str) -> dict:
probe = None
# Try python ffmpeg module first
ffmpeg = _get_ffmpeg()
if ffmpeg is not None:
try:
probe = ffmpeg.probe(file_path)
@@ -203,7 +214,8 @@ def ffprobe(file_path: str) -> dict:
ffprobe_cmd = shutil.which("ffprobe")
if ffprobe_cmd:
try:
proc = subprocess.run(
import subprocess as _subprocess
proc = _subprocess.run(
[
ffprobe_cmd,
"-v",