hook-yt_dlp.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import sys
  2. from PyInstaller.utils.hooks import collect_submodules, collect_data_files
  3. def pycryptodome_module():
  4. try:
  5. import Cryptodome # noqa: F401
  6. except ImportError:
  7. try:
  8. import Crypto # noqa: F401
  9. print('WARNING: Using Crypto since Cryptodome is not available. '
  10. 'Install with: python3 -m pip install pycryptodomex', file=sys.stderr)
  11. return 'Crypto'
  12. except ImportError:
  13. pass
  14. return 'Cryptodome'
  15. def get_hidden_imports():
  16. yield from ('yt_dlp.compat._legacy', 'yt_dlp.compat._deprecated')
  17. yield from ('yt_dlp.utils._legacy', 'yt_dlp.utils._deprecated')
  18. yield pycryptodome_module()
  19. # Only `websockets` is required, others are collected just in case
  20. for module in ('websockets', 'requests', 'urllib3'):
  21. yield from collect_submodules(module)
  22. # These are auto-detected, but explicitly add them just in case
  23. yield from ('mutagen', 'brotli', 'certifi', 'secretstorage', 'curl_cffi')
  24. hiddenimports = list(get_hidden_imports())
  25. print(f'Adding imports: {hiddenimports}')
  26. excludedimports = ['youtube_dl', 'youtube_dlc', 'test', 'ytdlp_plugins', 'devscripts', 'bundle']
  27. datas = collect_data_files('curl_cffi', includes=['cacert.pem'])