aboutsummaryrefslogtreecommitdiffstats
path: root/yt_dlp/utils.py
diff options
context:
space:
mode:
authorpukkandan <pukkandan.ytdlp@gmail.com>2022-04-21 00:35:57 +0530
committerpukkandan <pukkandan.ytdlp@gmail.com>2022-04-21 00:48:52 +0530
commit9b8ee23b99de91f9e463050baddfd76fa6580ad6 (patch)
tree4e161e06d5f3953b2a0e10b0e60e53cbf8b39ea3 /yt_dlp/utils.py
parent62f6f1cbf253240a026a70538b5b58945563fc90 (diff)
downloadhypervideo-pre-9b8ee23b99de91f9e463050baddfd76fa6580ad6.tar.lz
hypervideo-pre-9b8ee23b99de91f9e463050baddfd76fa6580ad6.tar.xz
hypervideo-pre-9b8ee23b99de91f9e463050baddfd76fa6580ad6.zip
[dependencies] Create module with all dependency imports
Diffstat (limited to 'yt_dlp/utils.py')
-rw-r--r--yt_dlp/utils.py25
1 files changed, 9 insertions, 16 deletions
diff --git a/yt_dlp/utils.py b/yt_dlp/utils.py
index ccea3c4e6..7f0c055ac 100644
--- a/yt_dlp/utils.py
+++ b/yt_dlp/utils.py
@@ -41,7 +41,6 @@ import zlib
from .compat import (
asyncio,
- compat_brotli,
compat_chr,
compat_cookiejar,
compat_etree_fromstring,
@@ -64,18 +63,10 @@ from .compat import (
compat_urllib_parse_urlparse,
compat_urllib_request,
compat_urlparse,
- compat_websockets,
)
+from .dependencies import brotli, certifi, websockets
from .socks import ProxyType, sockssocket
-try:
- import certifi
-
- # The certificate may not be bundled in executable
- has_certifi = os.path.exists(certifi.where())
-except ImportError:
- has_certifi = False
-
def register_socks_protocols():
# "Register" SOCKS protocols
@@ -138,7 +129,7 @@ def random_user_agent():
SUPPORTED_ENCODINGS = [
'gzip', 'deflate'
]
-if compat_brotli:
+if brotli:
SUPPORTED_ENCODINGS.append('br')
std_headers = {
@@ -1267,7 +1258,7 @@ class YoutubeDLHandler(compat_urllib_request.HTTPHandler):
def brotli(data):
if not data:
return data
- return compat_brotli.decompress(data)
+ return brotli.decompress(data)
def http_request(self, req):
# According to RFC 3986, URLs can not contain non-ASCII characters, however this is not
@@ -5231,7 +5222,7 @@ class WebSocketsWrapper():
def __init__(self, url, headers=None, connect=True):
self.loop = asyncio.events.new_event_loop()
- self.conn = compat_websockets.connect(
+ self.conn = websockets.connect(
url, extra_headers=headers, ping_interval=None,
close_timeout=float('inf'), loop=self.loop, ping_timeout=float('inf'))
if connect:
@@ -5294,9 +5285,6 @@ class WebSocketsWrapper():
})
-has_websockets = bool(compat_websockets)
-
-
def merge_headers(*dicts):
"""Merge dicts of http headers case insensitively, prioritizing the latter ones"""
return {k.title(): v for k, v in itertools.chain.from_iterable(map(dict.items, dicts))}
@@ -5312,3 +5300,8 @@ class classproperty:
def Namespace(**kwargs):
return collections.namedtuple('Namespace', kwargs)(**kwargs)
+
+
+# Deprecated
+has_certifi = bool(certifi)
+has_websockets = bool(websockets)