Rename compat_urllib_request_Request to sanitized_Request and move to utils
[youtube-dl] / youtube_dl / utils.py
index c0325f054ddfccd2c601acaee3812be5e00a4e6e..d7b737e21639679fe665d22e6ca4089f5c791618 100644 (file)
@@ -373,6 +373,13 @@ def sanitize_path(s):
     return os.path.join(*sanitized_path)
 
 
+# Prepend protocol-less URLs with `http:` scheme in order to mitigate the number of
+# unwanted failures due to missing protocol
+def sanitized_Request(url, *args, **kwargs):
+    return compat_urllib_request.Request(
+        'http:%s' % url if url.startswith('//') else url, *args, **kwargs)
+
+
 def orderedSet(iterable):
     """ Remove all duplicates from the input iterable """
     res = []