From 043b5762a551d3ed4aab92dff3ec799886fe45b0 Mon Sep 17 00:00:00 2001 From: Paul WOISARD Date: Sat, 25 May 2024 14:44:22 +0200 Subject: [PATCH] Chemin de librairie de VLC --- main.py | 172 ++++++++++++++++++++++-------------------- specs/main-linux.spec | 8 +- src/MainWindow.py | 10 ++- 3 files changed, 101 insertions(+), 89 deletions(-) diff --git a/main.py b/main.py index 874e211..f66ded4 100644 --- a/main.py +++ b/main.py @@ -2,84 +2,92 @@ import os import sys import time -from PyQt6.QtGui import QPixmap -from PyQt6.QtWidgets import QApplication import platform import logging from logging.handlers import RotatingFileHandler +from PyQt6.QtGui import QPixmap +from PyQt6.QtWidgets import QApplication import qdarkstyle from src.MainWindow import MainWindow from src.CustomSplashScreen import CustomSplashScreen -# Définir les chemins en fonction du contexte d'exécution -if getattr(sys, 'frozen', False): - application_path = sys._MEIPASS -else: - application_path = os.path.dirname(os.path.abspath(__file__)) - -# Configuration des chemins de VLC et des logs -vlc_plugin_path = { - "Windows": 'C:\\Program Files\\VideoLAN\\VLC\\plugins', - "Linux": '/usr/lib/x86_64-linux-gnu/vlc/plugins', - "Darwin": '/Applications/VLC.app/Contents/MacOS/plugins' -} - -vlc_lib_path = { - "Darwin": '/Applications/VLC.app/Contents/MacOS/lib' -} - -log_path = { - "Windows": os.path.expanduser("~/AppData/Local/IPTVAPP/logs"), - "Linux": os.path.expanduser("~/.local/share/IPTVAPP/logs"), - "Darwin": os.path.expanduser("~/Library/Logs/IPTVAPP") -} - -os_name = platform.system() -if os_name in vlc_plugin_path: - os.environ['VLC_PLUGIN_PATH'] = vlc_plugin_path[os_name] - if os_name == "Darwin": - os.environ['DYLD_LIBRARY_PATH'] = vlc_lib_path[os_name] - -try: - os.makedirs(log_path.get(os_name, "/tmp"), exist_ok=True) -except Exception as e: - logging.error(f"Failed to create log directory: {str(e)}") - sys.exit(1) - -# Configuration du chemin de log -log_directory = os.path.join(log_path.get(platform.system(), "/tmp"), 'Logs') -os.makedirs(log_directory, exist_ok=True) -log_filename = os.path.join(log_directory, 'application.log') - -try: - # Configuration du handler de fichier - file_handler = RotatingFileHandler(log_filename, maxBytes=10**6, backupCount=5) - file_handler.setLevel(logging.DEBUG) - formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') - file_handler.setFormatter(formatter) - - # Configuration du logger - logger = logging.getLogger(__name__) - logger.setLevel(logging.DEBUG) # Pour le développement; utiliser `logging.ERROR` pour la production - logger.addHandler(file_handler) - - # Handler de console pour le développement - console_handler = logging.StreamHandler() - console_handler.setLevel(logging.DEBUG) - console_handler.setFormatter(formatter) - logger.addHandler(console_handler) - - logger.info("Logger configuration complete.") -except Exception as e: - print(f"Failed to configure logger: {str(e)}") - sys.exit(1) - -config_path = "" +def configure_paths(): + application_path = sys._MEIPASS if getattr(sys, 'frozen', False) else os.path.dirname(os.path.abspath(__file__)) + + if getattr(sys, 'frozen', False): + vlc_plugin_path = os.path.join(application_path, 'plugins') + os.environ['VLC_PLUGIN_PATH'] = vlc_plugin_path + + if platform.system() == "Darwin": + os.environ["LD_LIBRARY_PATH"] = os.path.join(application_path, 'lib') + os.environ['DYLD_LIBRARY_PATH'] = os.path.join(application_path, 'lib') + else: + os.environ["LD_LIBRARY_PATH"] = application_path + + else: + vlc_plugin_path = { + "Windows": 'C:\\Program Files\\VideoLAN\\VLC\\plugins', + "Linux": '/usr/lib/x86_64-linux-gnu/vlc/plugins', + "Darwin": '/Applications/VLC.app/Contents/MacOS/plugins' + } + + vlc_lib_path = { + "Darwin": '/Applications/VLC.app/Contents/MacOS/lib' + } + + os_name = platform.system() + if os_name in vlc_plugin_path: + os.environ['VLC_PLUGIN_PATH'] = vlc_plugin_path[os_name] + if os_name == "Darwin": + os.environ['DYLD_LIBRARY_PATH'] = vlc_lib_path[os_name] + + return application_path + +def configure_log_path(): + log_path = { + "Windows": os.path.expanduser("~/AppData/Local/IPTVAPP/logs"), + "Linux": os.path.expanduser("~/.local/share/IPTVAPP/logs"), + "Darwin": os.path.expanduser("~/Library/Logs/IPTVAPP") + } + + os_name = platform.system() + log_directory = os.path.join(log_path.get(os_name, "/tmp"), 'Logs') + + try: + os.makedirs(log_directory, exist_ok=True) + except Exception as e: + logging.error(f"Failed to create log directory: {str(e)}") + sys.exit(1) + + return os.path.join(log_directory, 'application.log') + +def setup_logging(log_filename): + try: + file_handler = RotatingFileHandler(log_filename, maxBytes=10**6, backupCount=5) + file_handler.setLevel(logging.DEBUG) + formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') + file_handler.setFormatter(formatter) + + logger = logging.getLogger(__name__) + logger.setLevel(logging.DEBUG) + logger.addHandler(file_handler) + + console_handler = logging.StreamHandler() + console_handler.setLevel(logging.DEBUG) + console_handler.setFormatter(formatter) + logger.addHandler(console_handler) + + logger.info("Logger configuration complete.") + except Exception as e: + print(f"Failed to configure logger: {str(e)}") + sys.exit(1) + + return logger def get_config_path(app_name): - if os.name == 'nt': # Windows + if os.name == 'nt': config_path = os.path.join(os.getenv('LOCALAPPDATA'), app_name) - elif os.name == 'posix': # Linux et macOS + elif os.name == 'posix': home = os.path.expanduser('~') if sys.platform == 'darwin': config_path = os.path.join(home, 'Library', 'Application Support', app_name) @@ -88,14 +96,10 @@ def get_config_path(app_name): else: raise Exception("Système d'exploitation non supporté") - os.makedirs(config_path, exist_ok=True) # Crée le dossier s'il n'existe pas + os.makedirs(config_path, exist_ok=True) return config_path -app_name = 'IPTVAPP' -config_directory = get_config_path(app_name) -config_file_path = os.path.join(config_directory, 'config.json') - -def load_config(): +def load_config(config_file_path): default_config = { "hdhomerun_url": "http://hdhomerun.local/lineup.m3u", "auto_detect": True @@ -106,22 +110,18 @@ def load_config(): return {**default_config, **config} # Utilise les valeurs par défaut pour les clés manquantes except (FileNotFoundError, json.JSONDecodeError): return default_config - -config = load_config() # Gardez cette variable globale ou dans une instance pour accès à travers l'application - + def main(): app = QApplication(sys.argv) - # Application du thème sombre app.setStyleSheet(qdarkstyle.load_stylesheet(qt_api='pyqt6')) splash_pix = QPixmap(os.path.join(application_path, './assets/image/splash_screen.png')) splash = CustomSplashScreen(splash_pix) splash.show() - # Simuler le chargement de l'application for i in range(1, 101): splash.setProgress(i) - time.sleep(0.03) # Simuler le temps de chargement + time.sleep(0.03) mainWindow = MainWindow(config, config_file_path, config_path, logger, application_path) mainWindow.show() @@ -130,6 +130,16 @@ def main(): sys.exit(app.exec()) if __name__ == '__main__': + application_path = configure_paths() + log_filename = configure_log_path() + logger = setup_logging(log_filename) + + app_name = 'IPTVAPP' + config_path = get_config_path(app_name) + config_file_path = os.path.join(config_path, 'config.json') + config = load_config(config_file_path) + if platform.system() == "Linux": os.environ["QT_QPA_PLATFORM"] = "xcb" - main() \ No newline at end of file + + main() diff --git a/specs/main-linux.spec b/specs/main-linux.spec index 4b01e91..2d3ea42 100644 --- a/specs/main-linux.spec +++ b/specs/main-linux.spec @@ -38,15 +38,13 @@ exe = EXE( bootloader_ignore_signals=False, strip=False, upx=True, - upx_exclude=[], - runtime_tmpdir=None, console=False, # Change to False if you do not want a console window disable_windowed_traceback=False, + runtime_tmpdir=None, argv_emulation=False, + icon='../assets/image/missing_icon.png', # Chemin vers l'icône target_arch=None, codesign_identity=None, entitlements_file=None, - icon='../assets/image/missing_icon.png', # Chemin vers l'icône + onefile=True # Ajoutez cette ligne pour créer un seul exécutable ) - - diff --git a/src/MainWindow.py b/src/MainWindow.py index c2e2f59..301623d 100644 --- a/src/MainWindow.py +++ b/src/MainWindow.py @@ -44,9 +44,13 @@ def __init__(self, config, config_file_path, config_path, logger, application_pa app_icon = QIcon(window_icon_path) QApplication.instance().setWindowIcon(app_icon) - # Initialize VLC player - instance = vlc.Instance() - self.player = instance.media_player_new() + # Initialisation de VLC + try: + instance = vlc.Instance() + self.player = instance.media_player_new() + print("VLC media player initialized successfully") + except AttributeError as e: + print(f"Failed to initialize VLC instance or create media player: {e}") # Création de l'objet de surveillance d'état VLC self.state_monitor = VLCStateMonitor(self.player)