From 5ff34751a3a9cfb8992ac61daed17e58f3bd0374 Mon Sep 17 00:00:00 2001 From: PuppyPi <48111833+PuppyPi@users.noreply.github.com> Date: Sun, 22 Dec 2024 06:42:41 +0000 Subject: [PATCH] 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. --- yt_dlp/cookies.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/yt_dlp/cookies.py b/yt_dlp/cookies.py index fad323c901..d9b211cda3 100644 --- a/yt_dlp/cookies.py +++ b/yt_dlp/cookies.py @@ -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: