mirror of
https://github.com/yt-dlp/yt-dlp
synced 2024-12-26 21:59:08 +01:00
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.
This commit is contained in:
parent
d298693b1b
commit
5ff34751a3
1 changed files with 4 additions and 2 deletions
|
@ -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…
Reference in a new issue