]> jfr.im git - yt-dlp.git/blame - yt_dlp/dependencies.py
[XAttrMetadata] Refactor and document dependencies
[yt-dlp.git] / yt_dlp / dependencies.py
CommitLineData
9b8ee23b 1# flake8: noqa: F401
1d485a1a 2"""Imports all optional dependencies for the project.
3An attribute "_yt_dlp__identifier" may be inserted into the module if it uses an ambigious namespace"""
9b8ee23b 4
5try:
6 import brotlicffi as brotli
7except ImportError:
8 try:
9 import brotli
10 except ImportError:
11 brotli = None
12
13
14try:
15 import certifi
16except ImportError:
17 certifi = None
18else:
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
26try:
27 from Cryptodome.Cipher import AES as Cryptodome_AES
28except 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
44try:
45 import mutagen
46except ImportError:
47 mutagen = None
48
49
50secretstorage = None
51try:
52 import secretstorage
53 _SECRETSTORAGE_UNAVAILABLE_REASON = None
54except ImportError:
55 _SECRETSTORAGE_UNAVAILABLE_REASON = (
56 'as the `secretstorage` module is not installed. '
57 'Please install by running `python3 -m pip install secretstorage`')
58except Exception as _err:
59 _SECRETSTORAGE_UNAVAILABLE_REASON = f'as the `secretstorage` module could not be initialized. {_err}'
60
61
62try:
63 import sqlite3
64except 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
70try:
71 import websockets
72except (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 78try:
79 import xattr # xattr or pyxattr
80except ImportError:
81 xattr = None
82else:
83 if hasattr(xattr, 'set'): # pyxattr
84 xattr._yt_dlp__identifier = 'pyxattr'
85
86
9b8ee23b 87all_dependencies = {k: v for k, v in globals().items() if not k.startswith('_')}
88
89
90available_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]