From c9d38e47e1f670f11e12fb0922a82d2ae8ebaa6f Mon Sep 17 00:00:00 2001 From: Matthew Broadway Date: Sat, 12 Jun 2021 17:01:55 +0100 Subject: [PATCH] a few fixes to add Chromium support on Windows --- youtube_dl/cookies.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/youtube_dl/cookies.py b/youtube_dl/cookies.py index e0530a9fd..04e30dc7c 100644 --- a/youtube_dl/cookies.py +++ b/youtube_dl/cookies.py @@ -130,7 +130,7 @@ def _get_chromium_based_browser_settings(browser_name): browser_dir = { 'brave': os.path.join(appdata_local, r'BraveSoftware\Brave-Browser\User Data'), 'chrome': os.path.join(appdata_local, r'Google\Chrome\User Data'), - 'chromium': os.path.join(appdata_local, r'Google\Chromium\User Data'), + 'chromium': os.path.join(appdata_local, r'Chromium\User Data'), 'edge': os.path.join(appdata_local, r'Microsoft\Edge\User Data'), 'opera': os.path.join(appdata_roaming, r'Opera Software\Opera Stable'), 'vivaldi': os.path.join(appdata_local, r'Vivaldi\User Data'), @@ -198,7 +198,10 @@ def _extract_chrome_cookies(browser_name, profile, logger): try: cursor = _open_database_copy(cookie_database_path, tmpdir) cursor.connection.text_factory = bytes - cursor.execute('SELECT host_key, name, value, encrypted_value, path, expires_utc, is_secure FROM cookies') + column_names = _get_column_names(cursor, 'cookies') + secure_column = 'is_secure' if 'is_secure' in column_names else 'secure' + cursor.execute('SELECT host_key, name, value, encrypted_value, path, ' + 'expires_utc, {} FROM cookies'.format(secure_column)) jar = YoutubeDLCookieJar() failed_cookies = 0 for host_key, name, value, encrypted_value, path, expires_utc, is_secure in cursor.fetchall(): @@ -360,7 +363,7 @@ class WindowsChromeCookieDecryptor(ChromeCookieDecryptor): else: # any other prefix means the data is DPAPI encrypted # https://chromium.googlesource.com/chromium/src/+/refs/heads/main/components/os_crypt/os_crypt_win.cc - return _decrypt_windows_dpapi(encrypted_value, self._logger) + return _decrypt_windows_dpapi(encrypted_value, self._logger).decode('utf-8') def _get_linux_keyring_password(browser_keyring_name): @@ -487,6 +490,11 @@ def _open_database_copy(database_path, tmpdir): return conn.cursor() +def _get_column_names(cursor, table_name): + table_info = cursor.execute('PRAGMA table_info({})'.format(table_name)).fetchall() + return [row[1].decode('utf-8') for row in table_info] + + def _find_most_recently_used_file(root, filename): # if there are multiple browser profiles, take the most recently used one paths = []