mirror of
https://github.com/csd4ni3l/music-player.git
synced 2026-01-01 12:13:42 +01:00
Add ffmpeg installer and add ./bin to PATH
This commit is contained in:
61
menus/ffmpeg_missing.py
Normal file
61
menus/ffmpeg_missing.py
Normal 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
18
run.py
@@ -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()
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user