]>
Commit | Line | Data |
---|---|---|
9b8ee23b | 1 | # flake8: noqa: F401 |
1d485a1a | 2 | """Imports all optional dependencies for the project. |
962ffcf8 | 3 | An attribute "_yt_dlp__identifier" may be inserted into the module if it uses an ambiguous namespace""" |
9b8ee23b | 4 | |
5 | try: | |
6 | import brotlicffi as brotli | |
7 | except ImportError: | |
8 | try: | |
9 | import brotli | |
10 | except ImportError: | |
11 | brotli = None | |
12 | ||
13 | ||
14 | try: | |
15 | import certifi | |
16 | except ImportError: | |
17 | certifi = None | |
18 | else: | |
19 | from os.path import exists as _path_exists | |
20 | ||
21 | # The certificate may not be bundled in executable | |
22 | if not _path_exists(certifi.where()): | |
23 | certifi = None | |
24 | ||
25 | ||
9b8ee23b | 26 | try: |
27 | import mutagen | |
28 | except ImportError: | |
29 | mutagen = None | |
30 | ||
31 | ||
32 | secretstorage = None | |
33 | try: | |
34 | import secretstorage | |
35 | _SECRETSTORAGE_UNAVAILABLE_REASON = None | |
36 | except ImportError: | |
37 | _SECRETSTORAGE_UNAVAILABLE_REASON = ( | |
38 | 'as the `secretstorage` module is not installed. ' | |
39 | 'Please install by running `python3 -m pip install secretstorage`') | |
40 | except Exception as _err: | |
41 | _SECRETSTORAGE_UNAVAILABLE_REASON = f'as the `secretstorage` module could not be initialized. {_err}' | |
42 | ||
43 | ||
44 | try: | |
45 | import sqlite3 | |
35f9a306 | 46 | # We need to get the underlying `sqlite` version, see https://github.com/yt-dlp/yt-dlp/issues/8152 |
47 | sqlite3._yt_dlp__version = sqlite3.sqlite_version | |
9b8ee23b | 48 | except ImportError: |
47ab66db | 49 | # although sqlite3 is part of the standard library, it is possible to compile Python without |
9b8ee23b | 50 | # sqlite support. See: https://github.com/yt-dlp/yt-dlp/issues/544 |
51 | sqlite3 = None | |
52 | ||
53 | ||
54 | try: | |
55 | import websockets | |
ed3bb2b0 | 56 | except ImportError: |
9b8ee23b | 57 | websockets = None |
58 | ||
8a8b5452 | 59 | try: |
60 | import urllib3 | |
61 | except ImportError: | |
62 | urllib3 = None | |
63 | ||
64 | try: | |
65 | import requests | |
66 | except ImportError: | |
67 | requests = None | |
9b8ee23b | 68 | |
6f7563be | 69 | try: |
70 | import xattr # xattr or pyxattr | |
71 | except ImportError: | |
72 | xattr = None | |
73 | else: | |
74 | if hasattr(xattr, 'set'): # pyxattr | |
75 | xattr._yt_dlp__identifier = 'pyxattr' | |
76 | ||
52f5be1f | 77 | try: |
78 | import curl_cffi | |
79 | except ImportError: | |
80 | curl_cffi = None | |
6f7563be | 81 | |
f6a765ce | 82 | from . import Cryptodome |
83 | ||
9b8ee23b | 84 | all_dependencies = {k: v for k, v in globals().items() if not k.startswith('_')} |
f6a765ce | 85 | available_dependencies = {k: v for k, v in all_dependencies.items() if v} |
9b8ee23b | 86 | |
87 | ||
f6a765ce | 88 | # Deprecated |
65f6e807 | 89 | Cryptodome_AES = Cryptodome.AES |
9b8ee23b | 90 | |
91 | ||
92 | __all__ = [ | |
93 | 'all_dependencies', | |
94 | 'available_dependencies', | |
95 | *all_dependencies.keys(), | |
96 | ] |