Refactor FFmpeg updater to version checker
Replaces the FFmpeg updater logic with a version checker across all supported languages and removes the updater module. The Windows installation logic in ytsage_ffmpeg.py is rewritten to use essentials build extraction and path configuration directly, removing dependency on the updater module. Dialogs and UI strings are updated to reflect the new version checking workflow and provide installation guide links.
This commit is contained in:
+170
-7
@@ -12,6 +12,7 @@ from src.utils.ytsage_constants import (
|
||||
FFMPEG_7Z_DOWNLOAD_URL,
|
||||
FFMPEG_7Z_SHA256_URL,
|
||||
FFMPEG_ZIP_DOWNLOAD_URL,
|
||||
FFMPEG_ZIP_SHA256_URL,
|
||||
OS_NAME,
|
||||
SUBPROCESS_CREATIONFLAGS,
|
||||
)
|
||||
@@ -194,7 +195,7 @@ def check_ffmpeg_installed() -> bool:
|
||||
|
||||
|
||||
def install_ffmpeg_windows(progress_callback=None) -> bool:
|
||||
"""Install FFmpeg on Windows using 7z method primarily, with zip as fallback."""
|
||||
"""Install FFmpeg on Windows using essentials build with 7z method primarily, with zip as fallback."""
|
||||
# Check if already installed
|
||||
if check_ffmpeg_installed():
|
||||
logger.info("FFmpeg is already installed!")
|
||||
@@ -203,14 +204,176 @@ def install_ffmpeg_windows(progress_callback=None) -> bool:
|
||||
return True
|
||||
|
||||
try:
|
||||
# Import the updater for installation
|
||||
from src.core.ytsage_ffmpeg_updater import update_ffmpeg_windows
|
||||
# Define variables for essentials build
|
||||
extract_dir = Path(os.getenv("LOCALAPPDATA")) / "ffmpeg" # type: ignore
|
||||
|
||||
# Use the updater to install the latest version
|
||||
logger.info("Installing FFmpeg using the updater module...")
|
||||
# Create extraction directory if it doesn't exist
|
||||
extract_dir.mkdir(exist_ok=True)
|
||||
|
||||
# Try 7z method first (smaller size)
|
||||
use_7zip = check_7zip_installed()
|
||||
success = False
|
||||
|
||||
if use_7zip:
|
||||
logger.info("Using 7-Zip method (smaller download size)...")
|
||||
if progress_callback:
|
||||
progress_callback("⚡ Using 7-Zip method...")
|
||||
temp_file = tempfile.NamedTemporaryFile(delete=False, suffix=".7z").name
|
||||
|
||||
# Download 7z file
|
||||
if progress_callback:
|
||||
progress_callback("⬇ Downloading FFmpeg (7z)...")
|
||||
if download_file(
|
||||
FFMPEG_7Z_DOWNLOAD_URL,
|
||||
temp_file,
|
||||
progress_callback=progress_callback,
|
||||
):
|
||||
# Verify SHA-256 hash for 7z file
|
||||
if progress_callback:
|
||||
progress_callback("🔐 Verifying download integrity...")
|
||||
if verify_sha256(temp_file, FFMPEG_7Z_SHA256_URL):
|
||||
logger.info("Extracting FFmpeg components from 7z archive...")
|
||||
if progress_callback:
|
||||
progress_callback("⚙ Extracting FFmpeg...")
|
||||
try:
|
||||
subprocess.run(
|
||||
["7z", "x", temp_file, f"-o{extract_dir}", "-y"],
|
||||
creationflags=SUBPROCESS_CREATIONFLAGS,
|
||||
timeout=300,
|
||||
check=True,
|
||||
)
|
||||
success = True
|
||||
except Exception as e:
|
||||
logger.exception(f"7z extraction failed: {e}, trying zip fallback...")
|
||||
if progress_callback:
|
||||
progress_callback("❌ 7z extraction failed, trying zip fallback...")
|
||||
else:
|
||||
logger.error("SHA-256 verification failed for 7z file, trying zip fallback...")
|
||||
if progress_callback:
|
||||
progress_callback("❌ SHA-256 verification failed, trying zip fallback...")
|
||||
|
||||
# Clean up temp file
|
||||
try:
|
||||
Path(temp_file).unlink(missing_ok=True)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# Fallback to zip method if 7z failed or not available
|
||||
if not success:
|
||||
logger.info("Using ZIP method as fallback...")
|
||||
if progress_callback:
|
||||
progress_callback("📦 Using ZIP method...")
|
||||
temp_file = tempfile.NamedTemporaryFile(delete=False, suffix=".zip").name
|
||||
|
||||
# Download zip file
|
||||
if progress_callback:
|
||||
progress_callback("⬇ Downloading FFmpeg (zip)...")
|
||||
if not download_file(
|
||||
FFMPEG_ZIP_DOWNLOAD_URL,
|
||||
temp_file,
|
||||
progress_callback=progress_callback,
|
||||
):
|
||||
logger.error("Failed to download FFmpeg (both 7z and zip methods failed)")
|
||||
if progress_callback:
|
||||
progress_callback("❌ Failed to download FFmpeg")
|
||||
return False
|
||||
|
||||
# Verify SHA-256 hash for zip
|
||||
if progress_callback:
|
||||
progress_callback("🔐 Verifying download integrity...")
|
||||
if not verify_sha256(temp_file, FFMPEG_ZIP_SHA256_URL):
|
||||
logger.warning("SHA-256 verification failed for zip file, proceeding anyway...")
|
||||
if progress_callback:
|
||||
progress_callback("⚠️ SHA-256 verification failed, proceeding anyway...")
|
||||
|
||||
logger.info("Extracting FFmpeg components from zip archive...")
|
||||
if progress_callback:
|
||||
progress_callback("⚙ Extracting FFmpeg...")
|
||||
try:
|
||||
import zipfile
|
||||
with zipfile.ZipFile(temp_file, "r") as zip_ref:
|
||||
zip_ref.extractall(extract_dir)
|
||||
success = True
|
||||
except Exception as e:
|
||||
logger.exception(f"Extraction failed: {e}")
|
||||
if progress_callback:
|
||||
progress_callback(f"❌ Extraction failed: {e}")
|
||||
return False
|
||||
finally:
|
||||
# Clean up temp file
|
||||
try:
|
||||
Path(temp_file).unlink(missing_ok=True)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
if not success:
|
||||
logger.error("Both 7z and zip methods failed")
|
||||
if progress_callback:
|
||||
progress_callback("❌ Installation failed")
|
||||
return False
|
||||
|
||||
# Find the bin directory in the extracted essentials build
|
||||
logger.info("Locating FFmpeg binaries...")
|
||||
if progress_callback:
|
||||
progress_callback("📦 Installing FFmpeg...")
|
||||
return update_ffmpeg_windows(progress_callback=progress_callback)
|
||||
progress_callback("🔍 Locating FFmpeg binaries...")
|
||||
|
||||
bin_dir = None
|
||||
# Look for any directory matching ffmpeg-*-essentials_build pattern
|
||||
for item in extract_dir.iterdir():
|
||||
if item.is_dir() and "essentials_build" in item.name.lower():
|
||||
potential_bin = item / "bin"
|
||||
if potential_bin.exists():
|
||||
bin_dir = potential_bin
|
||||
logger.info(f"Found FFmpeg bin directory: {bin_dir}")
|
||||
break
|
||||
|
||||
if not bin_dir:
|
||||
logger.error("Could not locate FFmpeg bin directory")
|
||||
if progress_callback:
|
||||
progress_callback("❌ Could not locate FFmpeg bin directory")
|
||||
return False
|
||||
|
||||
logger.info("Configuring system paths...")
|
||||
if progress_callback:
|
||||
progress_callback("🔧 Configuring system paths...")
|
||||
|
||||
# Add to System Path
|
||||
user_path = os.environ.get("PATH", "")
|
||||
path_parts = user_path.split(os.pathsep)
|
||||
|
||||
# Remove old FFmpeg paths and add new one
|
||||
cleaned_paths = [p for p in path_parts if "ffmpeg" not in p.lower() or str(bin_dir) in p]
|
||||
if str(bin_dir) not in cleaned_paths:
|
||||
cleaned_paths.insert(0, str(bin_dir))
|
||||
|
||||
new_path = os.pathsep.join(cleaned_paths)
|
||||
|
||||
try:
|
||||
subprocess.run(
|
||||
["setx", "PATH", new_path],
|
||||
creationflags=SUBPROCESS_CREATIONFLAGS,
|
||||
timeout=30,
|
||||
check=True,
|
||||
)
|
||||
os.environ["PATH"] = new_path
|
||||
except Exception as e:
|
||||
logger.warning(f"Failed to update PATH permanently: {e}")
|
||||
# Still update for current session
|
||||
os.environ["PATH"] = new_path
|
||||
|
||||
# Verify installation
|
||||
if progress_callback:
|
||||
progress_callback("✅ Verifying installation...")
|
||||
if not check_ffmpeg_installed():
|
||||
logger.error("FFmpeg installation verification failed")
|
||||
if progress_callback:
|
||||
progress_callback("⚠️ Installation completed but verification failed")
|
||||
return True # Still return True as files were extracted
|
||||
|
||||
logger.info("FFmpeg installation completed successfully!")
|
||||
if progress_callback:
|
||||
progress_callback("✅ FFmpeg installation completed successfully!")
|
||||
return True
|
||||
|
||||
except Exception as e:
|
||||
logger.exception(f"Error installing FFmpeg: {e}")
|
||||
|
||||
Reference in New Issue
Block a user