Add ffmpeg installer and add ./bin to PATH

This commit is contained in:
csd4ni3l
2025-05-24 14:55:00 +02:00
parent 4e61c81493
commit 3b6acef788
3 changed files with 74 additions and 7 deletions

61
menus/ffmpeg_missing.py Normal file
View File

@@ -0,0 +1,61 @@
import arcade, arcade.gui
import os, sys, subprocess, platform, urllib.request, zipfile, logging
class FFmpegMissing(arcade.gui.UIView):
def __init__(self):
super().__init__()
def on_show_view(self):
super().on_show_view()
msgbox = self.add_widget(
arcade.gui.UIMessageBox(
width=self.window.width / 2,
height=self.window.height / 2,
title="FFmpeg Missing",
message_text="FFmpeg has not been found but is required for this application.",
buttons=("Exit", "Auto Install")
)
)
msgbox.on_action = lambda event: self.install_ffmpeg() if event.action == "Auto Install" else sys.exit()
def install_ffmpeg(self):
bin_dir = os.path.join(os.getcwd(), "bin")
os.makedirs(bin_dir, exist_ok=True)
system = platform.system()
if system == "Linux" or system == "Darwin":
url = "https://evermeet.cx/ffmpeg/ffmpeg-7.1.1.zip"
filename = "ffmpeg.zip"
logging.debug(f"Downloading FFmpeg from {url}...")
file_path = os.path.join(bin_dir, filename)
urllib.request.urlretrieve(url, file_path)
logging.debug("Extracting FFmpeg...")
with zipfile.ZipFile(file_path, 'r') as zip_ref:
zip_ref.extractall(bin_dir)
ffmpeg_path = os.path.join(bin_dir, "ffmpeg")
os.chmod(ffmpeg_path, 0o755)
os.remove(file_path)
logging.debug("FFmpeg installed in ./bin")
elif system == "Windows":
try:
subprocess.run([
"winget", "install", "--id=Gyan.FFmpeg", "--scope=user",
"--accept-source-agreements", "--accept-package-agreements"
], check=True)
logging.debug("FFmpeg installed via winget.")
except subprocess.CalledProcessError as e:
logging.debug("Failed to install FFmpeg via winget:", e)
else:
logging.error(f"Unsupported OS: {system}")
from menus.main import Main
self.window.show_view(Main())

18
run.py
View File

@@ -1,8 +1,13 @@
import os
bin_path = os.path.join(os.getcwd(), "bin")
current_path = os.environ.get("PATH", "")
os.environ["PATH"] = f"{bin_path}{os.pathsep}{current_path}"
import pyglet import pyglet
pyglet.options.debug_gl = False pyglet.options.debug_gl = False
import logging, datetime, os, json, sys, arcade import logging, datetime, json, sys, arcade
from utils.utils import get_closest_resolution, print_debug_info, on_exception, ErrorView from utils.utils import get_closest_resolution, print_debug_info, on_exception, ErrorView
from utils.constants import log_dir, menu_background_color from utils.constants import log_dir, menu_background_color
@@ -84,14 +89,15 @@ arcade.set_background_color(menu_background_color)
print_debug_info() print_debug_info()
if pyglet.media.codecs.have_ffmpeg(): # if pyglet.media.codecs.have_ffmpeg():
menu = Main() # menu = Main()
else: # else:
menu = ErrorView("FFmpeg has not been found but is required for this application.", "FFmpeg lib not found.") from menus.ffmpeg_missing import FFmpegMissing
menu = FFmpegMissing()
window.show_view(menu) window.show_view(menu)
logging.debug('Game started.') logging.debug('App started.')
arcade.run() arcade.run()

View File

@@ -1,4 +1,4 @@
import logging, arcade, arcade.gui, sys, traceback, os, re, platform, urllib.request, stat import logging, arcade, arcade.gui, sys, traceback, os, re, platform, urllib.request, zipfile, subprocess
from mutagen.easyid3 import EasyID3 from mutagen.easyid3 import EasyID3
from utils.constants import menu_background_color from utils.constants import menu_background_color