]> git.bitcoin.ninja Git - youtube-dl/blobdiff - youtube_dl/utils.py
[svtplay] Rename to svt
[youtube-dl] / youtube_dl / utils.py
index b3abfbc11b8ac5f9d036ad04800c820337252da8..de09b53b2d81150e355788f8f870dcaf112ae296 100644 (file)
@@ -1357,6 +1357,13 @@ def prepend_extension(filename, ext, expected_real_ext=None):
         else '{0}.{1}'.format(filename, ext))
 
 
+def replace_extension(filename, ext, expected_real_ext=None):
+    name, real_ext = os.path.splitext(filename)
+    return '{0}.{1}'.format(
+        name if not expected_real_ext or real_ext[1:] == expected_real_ext else filename,
+        ext)
+
+
 def check_executable(exe, args=[]):
     """ Checks if the given binary is installed somewhere in PATH, and returns its name.
     args can be a list of arguments for a short output (like -version) """
@@ -1373,7 +1380,7 @@ def get_exe_version(exe, args=['--version'],
     or False if the executable is not present """
     try:
         out, _ = subprocess.Popen(
-            [exe] + args,
+            [encodeArgument(exe)] + args,
             stdout=subprocess.PIPE, stderr=subprocess.STDOUT).communicate()
     except OSError:
         return False
@@ -1479,6 +1486,14 @@ def uppercase_escape(s):
         s)
 
 
+def lowercase_escape(s):
+    unicode_escape = codecs.getdecoder('unicode_escape')
+    return re.sub(
+        r'\\u[0-9a-fA-F]{4}',
+        lambda m: unicode_escape(m.group(0))[0],
+        s)
+
+
 def escape_rfc3986(s):
     """Escape non-ASCII characters as suggested by RFC 3986"""
     if sys.version_info < (3, 0) and isinstance(s, compat_str):