[utils] Add support for cookies with spaces used instead of tabs
[youtube-dl] / youtube_dl / utils.py
index 8ccf254895133f38d1c8e095718a0d53d53bd061..93d1dec0506207d6974689af1b9257ef9541c224 100644 (file)
@@ -2752,6 +2752,11 @@ class YoutubeDLCookieJar(compat_cookiejar.MozillaCookieJar):
             for line in f:
                 if line.startswith(self._HTTPONLY_PREFIX):
                     line = line[len(self._HTTPONLY_PREFIX):]
+                # Cookie file may contain spaces instead of tabs.
+                # Replace all spaces with tabs to make such cookie files work
+                # with MozillaCookieJar.
+                if not line.startswith('#'):
+                    line = re.sub(r' +', r'\t', line)
                 cf.write(compat_str(line))
         cf.seek(0)
         self._really_load(cf, filename, ignore_discard, ignore_expires)