diff --git a/yt_dlp/cookies.py b/yt_dlp/cookies.py index 459a4b7de0..b72aa3f348 100644 --- a/yt_dlp/cookies.py +++ b/yt_dlp/cookies.py @@ -125,6 +125,8 @@ def extract_cookies_from_browser(browser_name, profile=None, logger=YDLLogger(), def _extract_firefox_cookies(profile, container, logger): + MAX_SUPPORTED_DB_SCHEMA_VERSION = 16 + logger.info('Extracting cookies from firefox') if not sqlite3: logger.warning('Cannot extract cookies from firefox without sqlite3 support. ' @@ -159,9 +161,12 @@ def _extract_firefox_cookies(profile, container, logger): raise ValueError(f'could not find firefox container "{container}" in containers.json') with tempfile.TemporaryDirectory(prefix='yt_dlp') as tmpdir: - cursor = None - try: + cursor = _open_database_copy(cookie_database_path, tmpdir) + with contextlib.closing(cursor.connection): cursor = _open_database_copy(cookie_database_path, tmpdir) + db_schema_version = cursor.execute('PRAGMA user_version;').fetchone()[0] + if db_schema_version > MAX_SUPPORTED_DB_SCHEMA_VERSION: + logger.warning(f'Possibly unsupported firefox cookies database version: {db_schema_version}') if isinstance(container_id, int): logger.debug( f'Only loading cookies from firefox container "{container}", ID {container_id}') @@ -180,6 +185,10 @@ def _extract_firefox_cookies(profile, container, logger): total_cookie_count = len(table) for i, (host, name, value, path, expiry, is_secure) in enumerate(table): progress_bar.print(f'Loading cookie {i: 6d}/{total_cookie_count: 6d}') + # FF142 upgraded cookies DB to schema version 16 and started using milliseconds for cookie expiry + # Ref: https://github.com/mozilla-firefox/firefox/commit/5869af852cd20425165837f6c2d9971f3efba83d + if db_schema_version >= 16 and expiry is not None: + expiry /= 1000 cookie = http.cookiejar.Cookie( version=0, name=name, value=value, port=None, port_specified=False, domain=host, domain_specified=bool(host), domain_initial_dot=host.startswith('.'), @@ -188,9 +197,6 @@ def _extract_firefox_cookies(profile, container, logger): jar.set_cookie(cookie) logger.info(f'Extracted {len(jar)} cookies from firefox') return jar - finally: - if cursor is not None: - cursor.connection.close() def _firefox_browser_dirs():