Update cookies.py to support parsing manual cookies files

Fix the "invalid length 8" errors for valid lines.

Previously, on my system at least, it couldn't parse either its own output or the output of cookies.txt files I had because of not removing the trailing '\n' from the line and considering it an extra entry, putting the number at 8 not 7.
pull/11872/head
PuppyPi 3 days ago committed by GitHub
parent d298693b1b
commit 5ff34751a3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -1327,18 +1327,20 @@ class YoutubeDLCookieJar(http.cookiejar.MozillaCookieJar):
raise ValueError(http.cookiejar.MISSING_FILENAME_TEXT)
def prepare_line(line):
assert line.endswith('\n')
line = line[:-1]
if line.startswith(self._HTTPONLY_PREFIX):
line = line[len(self._HTTPONLY_PREFIX):]
# comments and empty lines are fine
if line.startswith('#') or not line.strip():
return line
return line + '\n'
cookie_list = line.split('\t')
if len(cookie_list) != self._ENTRY_LEN:
raise http.cookiejar.LoadError(f'invalid length {len(cookie_list)}')
cookie = self._CookieFileEntry(*cookie_list)
if cookie.expires_at and not cookie.expires_at.isdigit():
raise http.cookiejar.LoadError(f'invalid expires at {cookie.expires_at}')
return line
return line + '\n'
cf = io.StringIO()
with self.open(filename) as f:

Loading…
Cancel
Save