Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable use of session cookies in chrome #9747

Merged
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 7 additions & 2 deletions yt_dlp/cookies.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ def _extract_chrome_cookies(browser_name, profile, keyring, logger):
cursor.connection.text_factory = bytes
column_names = _get_column_names(cursor, 'cookies')
secure_column = 'is_secure' if 'is_secure' in column_names else 'secure'
cursor.execute(f'SELECT host_key, name, value, encrypted_value, path, expires_utc, {secure_column} FROM cookies')
cursor.execute(f'SELECT host_key, name, value, encrypted_value, path, expires_utc, has_expires, {secure_column} FROM cookies')
StefanLobbenmeier marked this conversation as resolved.
Show resolved Hide resolved
jar = YoutubeDLCookieJar()
failed_cookies = 0
unencrypted_cookies = 0
Expand Down Expand Up @@ -335,7 +335,7 @@ def _extract_chrome_cookies(browser_name, profile, keyring, logger):
cursor.connection.close()


def _process_chrome_cookie(decryptor, host_key, name, value, encrypted_value, path, expires_utc, is_secure):
def _process_chrome_cookie(decryptor, host_key, name, value, encrypted_value, path, expires_utc, has_expires, is_secure):
host_key = host_key.decode()
name = name.decode()
value = value.decode()
Expand All @@ -347,6 +347,11 @@ def _process_chrome_cookie(decryptor, host_key, name, value, encrypted_value, pa
if value is None:
return is_encrypted, None

# In chrome, session cookies have has_expires and expires_utc set to 0
# In Python, cookies that do not expire have expires set to None
if not has_expires:
expires_utc = None
StefanLobbenmeier marked this conversation as resolved.
Show resolved Hide resolved

return is_encrypted, http.cookiejar.Cookie(
version=0, name=name, value=value, port=None, port_specified=False,
domain=host_key, domain_specified=bool(host_key), domain_initial_dot=host_key.startswith('.'),
Expand Down