]> jfr.im git - yt-dlp.git/blob - yt_dlp/dependencies/__init__.py
Fix 5cc0a8fd2e9fec50026fb92170b57993af939e4a
[yt-dlp.git] / yt_dlp / dependencies / __init__.py
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
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 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
46 except ImportError:
47 # although sqlite3 is part of the standard library, it is possible to compile python without
48 # sqlite support. See: https://github.com/yt-dlp/yt-dlp/issues/544
49 sqlite3 = None
50
51
52 try:
53 import websockets
54 except (ImportError, SyntaxError):
55 # websockets 3.10 on python 3.6 causes SyntaxError
56 # See https://github.com/yt-dlp/yt-dlp/issues/2633
57 websockets = None
58
59
60 try:
61 import xattr # xattr or pyxattr
62 except ImportError:
63 xattr = None
64 else:
65 if hasattr(xattr, 'set'): # pyxattr
66 xattr._yt_dlp__identifier = 'pyxattr'
67
68
69 from . import Cryptodome
70
71 all_dependencies = {k: v for k, v in globals().items() if not k.startswith('_')}
72 available_dependencies = {k: v for k, v in all_dependencies.items() if v}
73
74
75 # Deprecated
76 Cryptodome_AES = Cryptodome.AES
77
78
79 __all__ = [
80 'all_dependencies',
81 'available_dependencies',
82 *all_dependencies.keys(),
83 ]