Skip to content

Commit

Permalink
Chemin de librairie de VLC
Browse files Browse the repository at this point in the history
  • Loading branch information
Paullux committed May 25, 2024
1 parent d8d5eba commit 043b576
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 89 deletions.
172 changes: 91 additions & 81 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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()
Expand All @@ -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()

main()
8 changes: 3 additions & 5 deletions specs/main-linux.spec
Original file line number Diff line number Diff line change
Expand Up @@ -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
)


10 changes: 7 additions & 3 deletions src/MainWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 043b576

Please sign in to comment.