Skip to content

A feature-rich command-line audio/video downloader

[utils] Deprecate `random_uuidv4` (#17301)

doe10800d1e029d1405
diff --git a/pyproject.toml b/pyproject.toml
index 125e969c4f..ec2a476f1f 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -397,6 +397,7 @@ banned-from = [
"yt_dlp.utils.jwt_encode_hs256".msg = "Use `yt_dlp.utils.jwt_encode` instead."
"yt_dlp.utils.make_dir".msg = "Use `yt_dlp.utils.make_parent_dirs` instead."
"yt_dlp.utils.number_of_digits".msg = "Do not use"
+"yt_dlp.utils.random_uuidv4".msg = "Use `str(uuid.uuid4())` instead."
"yt_dlp.utils.decodeArgument".msg = "Do not use"
"yt_dlp.utils.decodeFilename".msg = "Do not use"
"yt_dlp.utils.encodeFilename".msg = "Do not use"
diff --git a/yt_dlp/extractor/tennistv.py b/yt_dlp/extractor/tennistv.py
index 197d7892d1..4709dab51d 100644
--- a/yt_dlp/extractor/tennistv.py
+++ b/yt_dlp/extractor/tennistv.py
@@ -1,9 +1,9 @@
import urllib.parse
+import uuid
from .common import InfoExtractor
from ..utils import (
ExtractorError,
- random_uuidv4,
unified_timestamp,
urlencode_postdata,
)
@@ -77,11 +77,11 @@ class TennisTVIE(InfoExtractor):
query={
'client_id': 'tennis-tv-web',
'redirect_uri': 'https://www.tennistv.com/resources/v1.1.10/html/silent-check-sso.html',
- 'state': random_uuidv4(),
+ 'state': str(uuid.uuid4()),
'response_mode': 'fragment',
'response_type': 'code',
'scope': 'openid',
- 'nonce': random_uuidv4(),
+ 'nonce': str(uuid.uuid4()),
'prompt': 'none',
})
diff --git a/yt_dlp/utils/_deprecated.py b/yt_dlp/utils/_deprecated.py
index 3f8aea1b20..cd39f99325 100644
--- a/yt_dlp/utils/_deprecated.py
+++ b/yt_dlp/utils/_deprecated.py
@@ -3,6 +3,7 @@ import base64
import hashlib
import hmac
import json
+import uuid
import warnings
from ..compat.compat_utils import passthrough_module
@@ -62,4 +63,8 @@ def number_of_digits(number):
return len('%d' % number)
+def random_uuidv4():
+ return str(uuid.uuid4())
+
+
compiled_regex_type = type(re.compile(''))
diff --git a/yt_dlp/utils/_utils.py b/yt_dlp/utils/_utils.py
index 526d1ab9eb..81d4ee3bc8 100644
--- a/yt_dlp/utils/_utils.py
+++ b/yt_dlp/utils/_utils.py
@@ -4730,13 +4730,6 @@ def clean_podcast_url(url):
return re.sub(r'^\w+://(\w+://)', r'\1', url)
-_HEX_TABLE = '0123456789abcdef'
-
-
-def random_uuidv4():
- return re.sub(r'[xy]', lambda x: _HEX_TABLE[random.randint(0, 15)], 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx')
-
-
def make_parent_dirs(path):
if dir_name := os.path.dirname(path):
os.makedirs(dir_name, exist_ok=True)