__init__.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. # We need to get the underlying `sqlite` version, see https://github.com/yt-dlp/yt-dlp/issues/8152
  37. sqlite3._yt_dlp__version = sqlite3.sqlite_version
  38. except ImportError:
  39. # although sqlite3 is part of the standard library, it is possible to compile Python without
  40. # sqlite support. See: https://github.com/yt-dlp/yt-dlp/issues/544
  41. sqlite3 = None
  42. try:
  43. import websockets
  44. except ImportError:
  45. websockets = None
  46. try:
  47. import urllib3
  48. except ImportError:
  49. urllib3 = None
  50. try:
  51. import requests
  52. except ImportError:
  53. requests = None
  54. try:
  55. import xattr # xattr or pyxattr
  56. except ImportError:
  57. xattr = None
  58. else:
  59. if hasattr(xattr, 'set'): # pyxattr
  60. xattr._yt_dlp__identifier = 'pyxattr'
  61. try:
  62. import curl_cffi
  63. except ImportError:
  64. curl_cffi = None
  65. from . import Cryptodome
  66. all_dependencies = {k: v for k, v in globals().items() if not k.startswith('_')}
  67. available_dependencies = {k: v for k, v in all_dependencies.items() if v}
  68. # Deprecated
  69. Cryptodome_AES = Cryptodome.AES
  70. __all__ = [
  71. 'all_dependencies',
  72. 'available_dependencies',
  73. *all_dependencies.keys(),
  74. ]