Skip to content

Commit f196434

Browse files
committed
Ajout path frozen et binaire
1 parent 2d9c565 commit f196434

1 file changed

Lines changed: 27 additions & 17 deletions

File tree

main.py

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,27 @@
1616
import logging
1717
from logging.handlers import RotatingFileHandler
1818

19+
if getattr(sys, 'frozen', False):
20+
# If the application is run as a bundle, the PyInstaller bootloader
21+
# extends the sys module by a flag frozen=True and sets the app
22+
# path into variable _MEIPASS'.
23+
application_path = sys._MEIPASS
24+
else:
25+
application_path = os.path.dirname(os.path.abspath(__file__))
26+
1927
# Définir le répertoire de base des logs selon le système d'exploitation
2028
if platform.system() == "Windows":
2129
log_directory = "C:\\ProgramData\\IPTVAPP\\Logs"
30+
# Set environment variables
31+
os.environ['VLC_PLUGIN_PATH'] = 'C:·\\Program Files\\VideoLAN\\VLC\\plugins'
2232
elif platform.system() == "Linux":
2333
log_directory = os.path.expanduser("~/.local/share/IPTVAPP/logs")
34+
# Set environment variables
35+
os.environ['VLC_PLUGIN_PATH'] = '/usr/lib/x86_64-linux-gnu/vlc/plugins'
2436
elif platform.system() == "Darwin": # macOS
2537
log_directory = os.path.expanduser("~/Library/Logs/IPTVAPP")
38+
# Set environment variables
39+
os.environ['VLC_PLUGIN_PATH'] = '/Applications/VLC.app/Contents/MacOS/plugins'
2640
else:
2741
print("Système d'Exploitation Inconnu, utilisation du répertoire temporaire")
2842
log_directory = "/tmp" # Utiliser un répertoire temporaire comme secours
@@ -207,13 +221,12 @@ def emit_sorted_data(self, channel_info, epg_data):
207221

208222
def get_channel_icon(self, channel_name):
209223
sanitized_name = channel_name.replace(" ", "_").replace("-", "_").replace("'", "")
210-
script_dir = os.path.dirname(os.path.abspath(__file__))
211224
icon_formats = ['svg', 'png']
212225
for fmt in icon_formats:
213-
icon_path = os.path.join(script_dir, 'logos', f'{sanitized_name}.{fmt}')
226+
icon_path = os.path.join(application_path, 'logos', f'{sanitized_name}.{fmt}')
214227
if os.path.exists(icon_path):
215228
return icon_path
216-
return os.path.join(script_dir, 'image', 'missing_icon.png')
229+
return os.path.join(application_path, 'image', 'missing_icon.png')
217230

218231
class EPGTable(QtWidgets.QTableWidget):
219232
def __init__(self, parent=None):
@@ -420,7 +433,7 @@ def create_channel_widget(self, channel_number, channel_name, channel_icon_url):
420433

421434
if logo_pixmap.isNull():
422435
logger.error(f"Failed to load image from {channel_icon_url}")
423-
logo_pixmap = QPixmap('image/missing_icon.png') # Chemin vers une image par défaut
436+
logo_pixmap = QPixmap(os.path.join(application_path, 'image/missing_icon.png')) # Chemin vers une image par défaut
424437

425438
logo_item.setPixmap(logo_pixmap.scaled(50, 50, Qt.AspectRatioMode.KeepAspectRatio, Qt.TransformationMode.SmoothTransformation))
426439
logo_item.setAlignment(Qt.AlignmentFlag.AlignCenter | Qt.AlignmentFlag.AlignCenter)
@@ -666,12 +679,9 @@ def __init__(self):
666679
self.config = load_config()
667680
self.hdhomerun_url = self.config.get("hdhomerun_url")
668681
self.setup_ui()
669-
670-
# Obtenir le chemin du répertoire du script en cours
671-
script_dir = os.path.dirname(os.path.abspath(__file__))
672682

673683
# Joindre le chemin du répertoire du script avec le nom du fichier image
674-
window_icon_path = os.path.join(script_dir, "image", "missing_icon.png")
684+
window_icon_path = os.path.join(application_path, "image", "missing_icon.png")
675685

676686
# Charger l'icône de fenêtre
677687
window_icon = QIcon(window_icon_path)
@@ -826,7 +836,7 @@ def get_ordered_uuids(self):
826836
# Ajouter le tuple à la liste
827837
ordered_uuids.append((channel_number, channel_name, icon_path, uuid))
828838
if channel_name == "France 3" and channel_number != 301:
829-
ordered_uuids.append(("3", channel_name, 'logos/France_3.png', uuid))
839+
ordered_uuids.append(("3", channel_name, os.path.join(application_path, 'logos/France_3.png'), uuid))
830840

831841
ordered_uuids = sorted(ordered_uuids, key=lambda x: int(x[0]))
832842
return ordered_uuids
@@ -852,11 +862,11 @@ def showError(self, message):
852862
# Charger le logo de la chaîne
853863
channel_logo = QLabel(self)
854864
sanitized_name = current_channel_name.replace(" ", "_").replace("-", "_").replace("'", "")
855-
logo_path = f'logos/{sanitized_name}.png'
865+
logo_path = os.path.join(application_path, f'logos/{sanitized_name}.png')
856866
if os.path.exists(logo_path):
857867
pixmap = QPixmap(logo_path)
858868
else:
859-
pixmap = QPixmap('image/missing_icon.png')
869+
pixmap = QPixmap(os.path.join(application_path, 'image/missing_icon.png'))
860870
pixmap_resized = QPixmap(pixmap).scaled(125,125, Qt.AspectRatioMode.KeepAspectRatio, Qt.TransformationMode.SmoothTransformation)
861871
channel_logo.setPixmap(pixmap_resized)
862872
channel_logo.setAlignment(Qt.AlignmentFlag.AlignCenter)
@@ -1209,12 +1219,12 @@ def get_channel_icon(self, channel_name):
12091219
sanitized_name = channel_name.replace(" ", "_").replace("-", "_").replace("'", "")
12101220
icon_formats = ['svg', 'png']
12111221
for fmt in icon_formats:
1212-
icon_path = os.path.join('logos', f'{sanitized_name}.{fmt}')
1222+
icon_path = os.path.join(application_path, 'logos', f'{sanitized_name}.{fmt}')
12131223
if os.path.exists(icon_path):
12141224
return icon_path
12151225

12161226
# Fallback to a generic icon
1217-
return 'image/missing_icon.png'
1227+
return os.path.join(application_path, 'image/missing_icon.png')
12181228

12191229
def playStream(self, url, name):
12201230
try:
@@ -1353,9 +1363,9 @@ def get_uuid_of_current_channel(self, channel_name):
13531363
find = True
13541364
program_name, program_desc, program_picture_url, program_start_date, program_duration = self.get_current_program(uuid)
13551365
sanitized_name = channel_name.replace(" ", "_").replace("-", "_").replace("'", "")
1356-
icon_path = os.path.join('logos', f'{sanitized_name}.png')
1366+
icon_path = os.path.join(application_path, 'logos', f'{sanitized_name}.png')
13571367
if not icon_path:
1358-
icon_path = 'image/missing_icon.png'
1368+
icon_path = os.path.join(application_path, 'image/missing_icon.png')
13591369
has_service = channel_info.get('has_service', False) # Par défaut False si non spécifié
13601370
has_abo = channel_info.get('has_abo', False) # Par défaut False si non spécifié
13611371
available = channel_info.get('available', False) # Par défaut False si non spécifié
@@ -1378,7 +1388,7 @@ def get_uuid_of_current_channel(self, channel_name):
13781388
self.show_semitransparent_blur_widget(channel_name, program_name, program_desc, program_picture_url, icon_path, program_start_date, program_duration, has_service, has_abo, available)
13791389
if not find:
13801390
program_name, program_desc, program_picture_url, program_start_date, program_duration = self.get_default_program_details()
1381-
icon_path = 'image/missing_icon.png'
1391+
icon_path = os.path.join(application_path, 'image/missing_icon.png')
13821392
self.show_semitransparent_blur_widget(channel_name, program_name, program_desc, program_picture_url, icon_path, program_start_date, program_duration, False, False, False)
13831393

13841394
# Fonction pour récupérer les informations sur le programme actuel d'une chaîne
@@ -1436,7 +1446,7 @@ def setProgress(self, value):
14361446

14371447
def main():
14381448
app = QApplication(sys.argv)
1439-
splash_pix = QPixmap('./image/splash_screen.png')
1449+
splash_pix = QPixmap(os.path.join(application_path, './image/splash_screen.png'))
14401450
splash = CustomSplashScreen(splash_pix)
14411451
splash.show()
14421452

0 commit comments

Comments
 (0)