]>
Commit | Line | Data |
---|---|---|
9b8ee23b | 1 | # flake8: noqa: F401 |
1d485a1a | 2 | """Imports all optional dependencies for the project. |
3 | An attribute "_yt_dlp__identifier" may be inserted into the module if it uses an ambigious 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 | ||
26 | try: | |
27 | from Cryptodome.Cipher import AES as Cryptodome_AES | |
28 | except ImportError: | |
29 | try: | |
30 | from Crypto.Cipher import AES as Cryptodome_AES | |
31 | except ImportError: | |
32 | Cryptodome_AES = None | |
1d485a1a | 33 | else: |
34 | try: | |
35 | # In pycrypto, mode defaults to ECB. See: | |
36 | # https://www.pycryptodome.org/en/latest/src/vs_pycrypto.html#:~:text=not%20have%20ECB%20as%20default%20mode | |
37 | Cryptodome_AES.new(b'abcdefghijklmnop') | |
38 | except TypeError: | |
39 | pass | |
40 | else: | |
41 | Cryptodome_AES._yt_dlp__identifier = 'pycrypto' | |
9b8ee23b | 42 | |
43 | ||
44 | try: | |
45 | import mutagen | |
46 | except ImportError: | |
47 | mutagen = None | |
48 | ||
49 | ||
50 | secretstorage = None | |
51 | try: | |
52 | import secretstorage | |
53 | _SECRETSTORAGE_UNAVAILABLE_REASON = None | |
54 | except ImportError: | |
55 | _SECRETSTORAGE_UNAVAILABLE_REASON = ( | |
56 | 'as the `secretstorage` module is not installed. ' | |
57 | 'Please install by running `python3 -m pip install secretstorage`') | |
58 | except Exception as _err: | |
59 | _SECRETSTORAGE_UNAVAILABLE_REASON = f'as the `secretstorage` module could not be initialized. {_err}' | |
60 | ||
61 | ||
62 | try: | |
63 | import sqlite3 | |
64 | except ImportError: | |
65 | # although sqlite3 is part of the standard library, it is possible to compile python without | |
66 | # sqlite support. See: https://github.com/yt-dlp/yt-dlp/issues/544 | |
67 | sqlite3 = None | |
68 | ||
69 | ||
70 | try: | |
71 | import websockets | |
72 | except (ImportError, SyntaxError): | |
73 | # websockets 3.10 on python 3.6 causes SyntaxError | |
74 | # See https://github.com/yt-dlp/yt-dlp/issues/2633 | |
75 | websockets = None | |
76 | ||
77 | ||
6f7563be | 78 | try: |
79 | import xattr # xattr or pyxattr | |
80 | except ImportError: | |
81 | xattr = None | |
82 | else: | |
83 | if hasattr(xattr, 'set'): # pyxattr | |
84 | xattr._yt_dlp__identifier = 'pyxattr' | |
85 | ||
86 | ||
9b8ee23b | 87 | all_dependencies = {k: v for k, v in globals().items() if not k.startswith('_')} |
88 | ||
89 | ||
90 | available_dependencies = {k: v for k, v in all_dependencies.items() if v} | |
91 | ||
92 | ||
93 | __all__ = [ | |
94 | 'all_dependencies', | |
95 | 'available_dependencies', | |
96 | *all_dependencies.keys(), | |
97 | ] |