]> gitweb @ CieloNegro.org - youtube-dl.git/blobdiff - youtube_dl/utils.py
[utils] Add convenience urljoin
[youtube-dl.git] / youtube_dl / utils.py
index 3d4951ad94948ac753b21812626f94be17d9e942..694e9a600387977cd99f0af5ba63e87d26ba0f5e 100644 (file)
@@ -1700,6 +1700,16 @@ def base_url(url):
     return re.match(r'https?://[^?#&]+/', url).group()
 
 
+def urljoin(base, path):
+    if not isinstance(path, compat_str) or not path:
+        return None
+    if re.match(r'https?://', path):
+        return path
+    if not isinstance(base, compat_str) or not re.match(r'https?://', base):
+        return None
+    return compat_urlparse.urljoin(base, path)
+
+
 class HEADRequest(compat_urllib_request.Request):
     def get_method(self):
         return 'HEAD'