Skip to content

Commit 043b576

Browse files
committed
Chemin de librairie de VLC
1 parent d8d5eba commit 043b576

File tree

3 files changed

+101
-89
lines changed

3 files changed

+101
-89
lines changed

main.py

Lines changed: 91 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -2,84 +2,92 @@
22
import os
33
import sys
44
import time
5-
from PyQt6.QtGui import QPixmap
6-
from PyQt6.QtWidgets import QApplication
75
import platform
86
import logging
97
from logging.handlers import RotatingFileHandler
8+
from PyQt6.QtGui import QPixmap
9+
from PyQt6.QtWidgets import QApplication
1010
import qdarkstyle
1111
from src.MainWindow import MainWindow
1212
from src.CustomSplashScreen import CustomSplashScreen
1313

14-
# Définir les chemins en fonction du contexte d'exécution
15-
if getattr(sys, 'frozen', False):
16-
application_path = sys._MEIPASS
17-
else:
18-
application_path = os.path.dirname(os.path.abspath(__file__))
19-
20-
# Configuration des chemins de VLC et des logs
21-
vlc_plugin_path = {
22-
"Windows": 'C:\\Program Files\\VideoLAN\\VLC\\plugins',
23-
"Linux": '/usr/lib/x86_64-linux-gnu/vlc/plugins',
24-
"Darwin": '/Applications/VLC.app/Contents/MacOS/plugins'
25-
}
26-
27-
vlc_lib_path = {
28-
"Darwin": '/Applications/VLC.app/Contents/MacOS/lib'
29-
}
30-
31-
log_path = {
32-
"Windows": os.path.expanduser("~/AppData/Local/IPTVAPP/logs"),
33-
"Linux": os.path.expanduser("~/.local/share/IPTVAPP/logs"),
34-
"Darwin": os.path.expanduser("~/Library/Logs/IPTVAPP")
35-
}
36-
37-
os_name = platform.system()
38-
if os_name in vlc_plugin_path:
39-
os.environ['VLC_PLUGIN_PATH'] = vlc_plugin_path[os_name]
40-
if os_name == "Darwin":
41-
os.environ['DYLD_LIBRARY_PATH'] = vlc_lib_path[os_name]
42-
43-
try:
44-
os.makedirs(log_path.get(os_name, "/tmp"), exist_ok=True)
45-
except Exception as e:
46-
logging.error(f"Failed to create log directory: {str(e)}")
47-
sys.exit(1)
48-
49-
# Configuration du chemin de log
50-
log_directory = os.path.join(log_path.get(platform.system(), "/tmp"), 'Logs')
51-
os.makedirs(log_directory, exist_ok=True)
52-
log_filename = os.path.join(log_directory, 'application.log')
53-
54-
try:
55-
# Configuration du handler de fichier
56-
file_handler = RotatingFileHandler(log_filename, maxBytes=10**6, backupCount=5)
57-
file_handler.setLevel(logging.DEBUG)
58-
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
59-
file_handler.setFormatter(formatter)
60-
61-
# Configuration du logger
62-
logger = logging.getLogger(__name__)
63-
logger.setLevel(logging.DEBUG) # Pour le développement; utiliser `logging.ERROR` pour la production
64-
logger.addHandler(file_handler)
65-
66-
# Handler de console pour le développement
67-
console_handler = logging.StreamHandler()
68-
console_handler.setLevel(logging.DEBUG)
69-
console_handler.setFormatter(formatter)
70-
logger.addHandler(console_handler)
71-
72-
logger.info("Logger configuration complete.")
73-
except Exception as e:
74-
print(f"Failed to configure logger: {str(e)}")
75-
sys.exit(1)
76-
77-
config_path = ""
14+
def configure_paths():
15+
application_path = sys._MEIPASS if getattr(sys, 'frozen', False) else os.path.dirname(os.path.abspath(__file__))
16+
17+
if getattr(sys, 'frozen', False):
18+
vlc_plugin_path = os.path.join(application_path, 'plugins')
19+
os.environ['VLC_PLUGIN_PATH'] = vlc_plugin_path
20+
21+
if platform.system() == "Darwin":
22+
os.environ["LD_LIBRARY_PATH"] = os.path.join(application_path, 'lib')
23+
os.environ['DYLD_LIBRARY_PATH'] = os.path.join(application_path, 'lib')
24+
else:
25+
os.environ["LD_LIBRARY_PATH"] = application_path
26+
27+
else:
28+
vlc_plugin_path = {
29+
"Windows": 'C:\\Program Files\\VideoLAN\\VLC\\plugins',
30+
"Linux": '/usr/lib/x86_64-linux-gnu/vlc/plugins',
31+
"Darwin": '/Applications/VLC.app/Contents/MacOS/plugins'
32+
}
33+
34+
vlc_lib_path = {
35+
"Darwin": '/Applications/VLC.app/Contents/MacOS/lib'
36+
}
37+
38+
os_name = platform.system()
39+
if os_name in vlc_plugin_path:
40+
os.environ['VLC_PLUGIN_PATH'] = vlc_plugin_path[os_name]
41+
if os_name == "Darwin":
42+
os.environ['DYLD_LIBRARY_PATH'] = vlc_lib_path[os_name]
43+
44+
return application_path
45+
46+
def configure_log_path():
47+
log_path = {
48+
"Windows": os.path.expanduser("~/AppData/Local/IPTVAPP/logs"),
49+
"Linux": os.path.expanduser("~/.local/share/IPTVAPP/logs"),
50+
"Darwin": os.path.expanduser("~/Library/Logs/IPTVAPP")
51+
}
52+
53+
os_name = platform.system()
54+
log_directory = os.path.join(log_path.get(os_name, "/tmp"), 'Logs')
55+
56+
try:
57+
os.makedirs(log_directory, exist_ok=True)
58+
except Exception as e:
59+
logging.error(f"Failed to create log directory: {str(e)}")
60+
sys.exit(1)
61+
62+
return os.path.join(log_directory, 'application.log')
63+
64+
def setup_logging(log_filename):
65+
try:
66+
file_handler = RotatingFileHandler(log_filename, maxBytes=10**6, backupCount=5)
67+
file_handler.setLevel(logging.DEBUG)
68+
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
69+
file_handler.setFormatter(formatter)
70+
71+
logger = logging.getLogger(__name__)
72+
logger.setLevel(logging.DEBUG)
73+
logger.addHandler(file_handler)
74+
75+
console_handler = logging.StreamHandler()
76+
console_handler.setLevel(logging.DEBUG)
77+
console_handler.setFormatter(formatter)
78+
logger.addHandler(console_handler)
79+
80+
logger.info("Logger configuration complete.")
81+
except Exception as e:
82+
print(f"Failed to configure logger: {str(e)}")
83+
sys.exit(1)
84+
85+
return logger
7886

7987
def get_config_path(app_name):
80-
if os.name == 'nt': # Windows
88+
if os.name == 'nt':
8189
config_path = os.path.join(os.getenv('LOCALAPPDATA'), app_name)
82-
elif os.name == 'posix': # Linux et macOS
90+
elif os.name == 'posix':
8391
home = os.path.expanduser('~')
8492
if sys.platform == 'darwin':
8593
config_path = os.path.join(home, 'Library', 'Application Support', app_name)
@@ -88,14 +96,10 @@ def get_config_path(app_name):
8896
else:
8997
raise Exception("Système d'exploitation non supporté")
9098

91-
os.makedirs(config_path, exist_ok=True) # Crée le dossier s'il n'existe pas
99+
os.makedirs(config_path, exist_ok=True)
92100
return config_path
93101

94-
app_name = 'IPTVAPP'
95-
config_directory = get_config_path(app_name)
96-
config_file_path = os.path.join(config_directory, 'config.json')
97-
98-
def load_config():
102+
def load_config(config_file_path):
99103
default_config = {
100104
"hdhomerun_url": "http://hdhomerun.local/lineup.m3u",
101105
"auto_detect": True
@@ -106,22 +110,18 @@ def load_config():
106110
return {**default_config, **config} # Utilise les valeurs par défaut pour les clés manquantes
107111
except (FileNotFoundError, json.JSONDecodeError):
108112
return default_config
109-
110-
config = load_config() # Gardez cette variable globale ou dans une instance pour accès à travers l'application
111-
113+
112114
def main():
113115
app = QApplication(sys.argv)
114-
# Application du thème sombre
115116
app.setStyleSheet(qdarkstyle.load_stylesheet(qt_api='pyqt6'))
116117

117118
splash_pix = QPixmap(os.path.join(application_path, './assets/image/splash_screen.png'))
118119
splash = CustomSplashScreen(splash_pix)
119120
splash.show()
120121

121-
# Simuler le chargement de l'application
122122
for i in range(1, 101):
123123
splash.setProgress(i)
124-
time.sleep(0.03) # Simuler le temps de chargement
124+
time.sleep(0.03)
125125

126126
mainWindow = MainWindow(config, config_file_path, config_path, logger, application_path)
127127
mainWindow.show()
@@ -130,6 +130,16 @@ def main():
130130
sys.exit(app.exec())
131131

132132
if __name__ == '__main__':
133+
application_path = configure_paths()
134+
log_filename = configure_log_path()
135+
logger = setup_logging(log_filename)
136+
137+
app_name = 'IPTVAPP'
138+
config_path = get_config_path(app_name)
139+
config_file_path = os.path.join(config_path, 'config.json')
140+
config = load_config(config_file_path)
141+
133142
if platform.system() == "Linux":
134143
os.environ["QT_QPA_PLATFORM"] = "xcb"
135-
main()
144+
145+
main()

specs/main-linux.spec

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,13 @@ exe = EXE(
3838
bootloader_ignore_signals=False,
3939
strip=False,
4040
upx=True,
41-
upx_exclude=[],
42-
runtime_tmpdir=None,
4341
console=False, # Change to False if you do not want a console window
4442
disable_windowed_traceback=False,
43+
runtime_tmpdir=None,
4544
argv_emulation=False,
45+
icon='../assets/image/missing_icon.png', # Chemin vers l'icône
4646
target_arch=None,
4747
codesign_identity=None,
4848
entitlements_file=None,
49-
icon='../assets/image/missing_icon.png', # Chemin vers l'icône
49+
onefile=True # Ajoutez cette ligne pour créer un seul exécutable
5050
)
51-
52-

src/MainWindow.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,13 @@ def __init__(self, config, config_file_path, config_path, logger, application_pa
4444
app_icon = QIcon(window_icon_path)
4545
QApplication.instance().setWindowIcon(app_icon)
4646

47-
# Initialize VLC player
48-
instance = vlc.Instance()
49-
self.player = instance.media_player_new()
47+
# Initialisation de VLC
48+
try:
49+
instance = vlc.Instance()
50+
self.player = instance.media_player_new()
51+
print("VLC media player initialized successfully")
52+
except AttributeError as e:
53+
print(f"Failed to initialize VLC instance or create media player: {e}")
5054

5155
# Création de l'objet de surveillance d'état VLC
5256
self.state_monitor = VLCStateMonitor(self.player)

0 commit comments

Comments
 (0)