hook-pymediainfo.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. # ------------------------------------------------------------------
  2. # Copyright (c) 2021 PyInstaller Development Team.
  3. #
  4. # This file is distributed under the terms of the GNU General Public
  5. # License (version 2.0 or later).
  6. #
  7. # The full license is available in LICENSE, distributed with
  8. # this software.
  9. #
  10. # SPDX-License-Identifier: GPL-2.0-or-later
  11. # ------------------------------------------------------------------
  12. from PyInstaller.compat import is_win, is_darwin
  13. from PyInstaller.utils.hooks import collect_dynamic_libs, logger
  14. # Collect bundled mediainfo shared library (available in Windows and macOS wheels on PyPI).
  15. binaries = collect_dynamic_libs("pymediainfo")
  16. # On linux, no wheels are available, and pymediainfo uses system shared library.
  17. if not binaries and not (is_win or is_darwin):
  18. def _find_system_mediainfo_library():
  19. import os
  20. import ctypes.util
  21. from PyInstaller.depend.utils import _resolveCtypesImports
  22. libname = ctypes.util.find_library("mediainfo")
  23. if libname is not None:
  24. resolved_binary = _resolveCtypesImports([os.path.basename(libname)])
  25. if resolved_binary:
  26. return resolved_binary[0][1]
  27. try:
  28. mediainfo_lib = _find_system_mediainfo_library()
  29. except Exception as e:
  30. logger.warning("Error while trying to find system-installed MediaInfo library: %s", e)
  31. mediainfo_lib = None
  32. if mediainfo_lib:
  33. # Put the library into pymediainfo sub-directory, to keep layout consistent with that of wheels.
  34. binaries += [(mediainfo_lib, 'pymediainfo')]
  35. if not binaries:
  36. logger.warning("MediaInfo shared library not found - pymediainfo will likely fail to work!")