# -*- mode: python ; coding: utf-8 -*-

block_cipher = None

import os, glob

# Find VLC installation
VLC_PATH = None
for _p in [
    r'C:\Program Files\VideoLAN\VLC',
    r'C:\Program Files (x86)\VideoLAN\VLC',
]:
    if os.path.exists(os.path.join(_p, 'libvlc.dll')):
        VLC_PATH = _p
        break

VLC_BINARIES = []
if VLC_PATH:
    VLC_BINARIES = [
        (os.path.join(VLC_PATH, 'libvlc.dll'),    '.'),
        (os.path.join(VLC_PATH, 'libvlccore.dll'), '.'),
    ]
    for _dll in glob.glob(os.path.join(VLC_PATH, 'plugins', '**', '*.dll'), recursive=True):
        _rel = os.path.relpath(os.path.dirname(_dll), VLC_PATH)
        VLC_BINARIES.append((_dll, _rel))

a = Analysis(
    ['main.py'],
    pathex=['.'],
    binaries=VLC_BINARIES,
    datas=[
        ('translations', 'translations'),
    ],
    hiddenimports=[
        'PyQt6.sip',
        'PyQt6.QtCore',
        'PyQt6.QtGui',
        'PyQt6.QtWidgets',
        'PyQt6.QtNetwork',
        'ui.main_window', 'ui.playlist_panel', 'ui.library_panel',
        'ui.library_manager', 'ui.themes', 'ui.vu_meter',
        'ui.scan_worker', 'ui.bpm_worker', 'ui.tag_editor',
        'ui.settings_dialog', 'ui.playlist_browser',
        'ui.playlist_info_dialog', 'ui.dance_info_dialog',
        'ui.dance_picker_dialog', 'ui.alt_dance_picker_dialog', 'ui.share_dialog',
        'ui.register_dialog',
        'player.player',
        'local.local_db', 'local.scanner', 'local.file_watcher',
        'local.sync_manager', 'local.linked_playlist',
        'translations', 'translations.da', 'translations.en',
        'mutagen', 'mutagen.mp3', 'mutagen.id3', 'mutagen.flac',
        'mutagen.mp4', 'mutagen.oggvorbis', 'mutagen.ogg',
        'mutagen.wave', 'mutagen.aiff', 'mutagen.asf',
        'vlc', 'sqlite3',
    ],
    hookspath=[],
    runtime_hooks=[],
    excludes=[
        'tkinter', 'tk', 'tcl',
        'matplotlib', 'pandas', 'scipy', 'numpy',
        'IPython', 'jupyter', 'PIL', 'cv2', 'sklearn',
        'PyQt6.QtWebEngine', 'PyQt6.QtWebEngineWidgets',
        'PyQt6.QtWebEngineCore', 'PyQt6.QtMultimedia',
        'PyQt6.QtMultimediaWidgets', 'PyQt6.QtBluetooth',
        'PyQt6.QtNfc', 'PyQt6.QtPositioning', 'PyQt6.QtLocation',
        'PyQt6.QtSensors', 'PyQt6.QtSerialPort', 'PyQt6.QtSql',
        'PyQt6.QtTest', 'PyQt6.QtXml', 'PyQt6.QtOpenGL',
        'PyQt6.QtOpenGLWidgets', 'PyQt6.Qt3DCore', 'PyQt6.Qt3DRender',
        'PyQt6.Qt3DInput', 'PyQt6.Qt3DLogic', 'PyQt6.Qt3DAnimation',
        'PyQt6.Qt3DExtras', 'PyQt6.QtCharts', 'PyQt6.QtDataVisualization',
        'PyQt6.QtQuick', 'PyQt6.QtQuickWidgets', 'PyQt6.QtQml',
        'PyQt6.QtRemoteObjects', 'PyQt6.QtScxml', 'PyQt6.QtStateMachine',
        'PyQt6.QtDesigner', 'PyQt6.QtHelp', 'PyQt6.QtPrintSupport',
        'unittest', 'doctest', 'pdb', 'pydoc',
    ],
    cipher=block_cipher,
    noarchive=False,
)

# Fjern store ubrugte Qt DLL-filer
REMOVE_PATTERNS = [
    'Qt6WebEngine', 'Qt6Quick', 'Qt6Qml', 'Qt6Designer',
    'Qt6Help', 'Qt6Multimedia', 'Qt6Location', 'Qt6Sensors',
    'Qt6Bluetooth', 'Qt6Nfc', 'Qt63D', 'Qt6Charts',
    'Qt6DataVisualization', 'Qt6RemoteObjects', 'Qt6Scxml',
    'Qt6StateMachine', 'Qt6VirtualKeyboard',
    'd3dcompiler', 'opengl32sw',
]
a.binaries = [
    (name, path, kind)
    for name, path, kind in a.binaries
    if not any(p.lower() in name.lower() for p in REMOVE_PATTERNS)
]

pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher)

exe = EXE(
    pyz,
    a.scripts,
    [],
    exclude_binaries=True,
    name='LineDancePlayer',
    debug=False,
    bootloader_ignore_signals=False,
    strip=False,
    upx=False,
    console=False,
    icon='installer\\icon.ico',
)

coll = COLLECT(
    exe,
    a.binaries,
    a.zipfiles,
    a.datas,
    strip=False,
    upx=False,
    name='LineDancePlayer',
)
