__init__.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. # flake8: noqa: F401
  2. """Imports all optional dependencies for the project.
  3. An attribute "_yt_dlp__identifier" may be inserted into the module if it uses an ambiguous namespace"""
  4. try:
  5. import brotlicffi as brotli
  6. except ImportError:
  7. try:
  8. import brotli
  9. except ImportError:
  10. brotli = None
  11. try:
  12. import certifi
  13. except ImportError:
  14. certifi = None
  15. else:
  16. from os.path import exists as _path_exists
  17. # The certificate may not be bundled in executable
  18. if not _path_exists(certifi.where()):
  19. certifi = None
  20. try:
  21. import mutagen
  22. except ImportError:
  23. mutagen = None
  24. secretstorage = None
  25. try:
  26. import secretstorage
  27. _SECRETSTORAGE_UNAVAILABLE_REASON = None
  28. except ImportError:
  29. _SECRETSTORAGE_UNAVAILABLE_REASON = (
  30. 'as the `secretstorage` module is not installed. '
  31. 'Please install by running `python3 -m pip install secretstorage`')
  32. except Exception as _err:
  33. _SECRETSTORAGE_UNAVAILABLE_REASON = f'as the `secretstorage` module could not be initialized. {_err}'
  34. try:
  35. import sqlite3
  36. except ImportError:
  37. # although sqlite3 is part of the standard library, it is possible to compile python without
  38. # sqlite support. See: https://github.com/yt-dlp/yt-dlp/issues/544
  39. sqlite3 = None
  40. try:
  41. import websockets
  42. except (ImportError, SyntaxError):
  43. # websockets 3.10 on python 3.6 causes SyntaxError
  44. # See https://github.com/yt-dlp/yt-dlp/issues/2633
  45. websockets = None
  46. try:
  47. import xattr # xattr or pyxattr
  48. except ImportError:
  49. xattr = None
  50. else:
  51. if hasattr(xattr, 'set'): # pyxattr
  52. xattr._yt_dlp__identifier = 'pyxattr'
  53. from . import Cryptodome
  54. all_dependencies = {k: v for k, v in globals().items() if not k.startswith('_')}
  55. available_dependencies = {k: v for k, v in all_dependencies.items() if v}
  56. # Deprecated
  57. Cryptodome_AES = Cryptodome.AES
  58. __all__ = [
  59. 'all_dependencies',
  60. 'available_dependencies',
  61. *all_dependencies.keys(),
  62. ]