aboutsummaryrefslogtreecommitdiffstats
path: root/yt_dlp/compat.py
diff options
context:
space:
mode:
Diffstat (limited to 'yt_dlp/compat.py')
-rw-r--r--yt_dlp/compat.py19
1 files changed, 18 insertions, 1 deletions
diff --git a/yt_dlp/compat.py b/yt_dlp/compat.py
index ab1a3ba44..363c2d57a 100644
--- a/yt_dlp/compat.py
+++ b/yt_dlp/compat.py
@@ -130,6 +130,24 @@ except AttributeError:
asyncio.run = compat_asyncio_run
+# Python 3.8+ does not honor %HOME% on windows, but this breaks compatibility with youtube-dl
+# See https://github.com/yt-dlp/yt-dlp/issues/792
+# https://docs.python.org/3/library/os.path.html#os.path.expanduser
+if compat_os_name in ('nt', 'ce') and 'HOME' in os.environ:
+ _userhome = os.environ['HOME']
+
+ def compat_expanduser(path):
+ if not path.startswith('~'):
+ return path
+ i = path.replace('\\', '/', 1).find('/') # ~user
+ if i < 0:
+ i = len(path)
+ userhome = os.path.join(os.path.dirname(_userhome), path[1:i]) if i > 1 else _userhome
+ return userhome + path[i:]
+else:
+ compat_expanduser = os.path.expanduser
+
+
# Deprecated
compat_basestring = str
@@ -152,7 +170,6 @@ compat_cookies = http.cookies
compat_cookies_SimpleCookie = compat_cookies.SimpleCookie
compat_etree_Element = etree.Element
compat_etree_register_namespace = etree.register_namespace
-compat_expanduser = os.path.expanduser
compat_get_terminal_size = shutil.get_terminal_size
compat_getenv = os.getenv
compat_getpass = getpass.getpass