|
|
@ -128,9 +128,14 @@ def _extract_firefox_cookies(profile, container, logger):
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
search_root = os.path.join(_firefox_browser_dir(), profile)
|
|
|
|
search_root = os.path.join(_firefox_browser_dir(), profile)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cookie_database_path = _find_most_recently_used_file(search_root, 'cookies.sqlite', logger)
|
|
|
|
|
|
|
|
if cookie_database_path is None:
|
|
|
|
|
|
|
|
raise FileNotFoundError(f'could not find firefox cookies database in {search_root}')
|
|
|
|
|
|
|
|
logger.debug(f'Extracting cookies from: "{cookie_database_path}"')
|
|
|
|
|
|
|
|
|
|
|
|
container_id = None
|
|
|
|
container_id = None
|
|
|
|
if container is not None:
|
|
|
|
if container not in (None, 'none'):
|
|
|
|
containers_path = os.path.join(search_root, 'containers.json')
|
|
|
|
containers_path = os.path.join(os.path.dirname(cookie_database_path), 'containers.json')
|
|
|
|
if not os.path.isfile(containers_path) or not os.access(containers_path, os.R_OK):
|
|
|
|
if not os.path.isfile(containers_path) or not os.access(containers_path, os.R_OK):
|
|
|
|
raise FileNotFoundError(f'could not read containers.json in {search_root}')
|
|
|
|
raise FileNotFoundError(f'could not read containers.json in {search_root}')
|
|
|
|
with open(containers_path, 'r') as containers:
|
|
|
|
with open(containers_path, 'r') as containers:
|
|
|
@ -142,26 +147,21 @@ def _extract_firefox_cookies(profile, container, logger):
|
|
|
|
if not isinstance(container_id, int):
|
|
|
|
if not isinstance(container_id, int):
|
|
|
|
raise ValueError(f'could not find firefox container "{container}" in containers.json')
|
|
|
|
raise ValueError(f'could not find firefox container "{container}" in containers.json')
|
|
|
|
|
|
|
|
|
|
|
|
cookie_database_path = _find_most_recently_used_file(search_root, 'cookies.sqlite', logger)
|
|
|
|
|
|
|
|
if cookie_database_path is None:
|
|
|
|
|
|
|
|
raise FileNotFoundError(f'could not find firefox cookies database in {search_root}')
|
|
|
|
|
|
|
|
logger.debug(f'Extracting cookies from: "{cookie_database_path}"')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
with tempfile.TemporaryDirectory(prefix='yt_dlp') as tmpdir:
|
|
|
|
with tempfile.TemporaryDirectory(prefix='yt_dlp') as tmpdir:
|
|
|
|
cursor = None
|
|
|
|
cursor = None
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
cursor = _open_database_copy(cookie_database_path, tmpdir)
|
|
|
|
cursor = _open_database_copy(cookie_database_path, tmpdir)
|
|
|
|
origin_attributes = ''
|
|
|
|
|
|
|
|
if isinstance(container_id, int):
|
|
|
|
if isinstance(container_id, int):
|
|
|
|
origin_attributes = f'^userContextId={container_id}'
|
|
|
|
|
|
|
|
logger.debug(
|
|
|
|
logger.debug(
|
|
|
|
f'Only loading cookies from firefox container "{container}", ID {container_id}')
|
|
|
|
f'Only loading cookies from firefox container "{container}", ID {container_id}')
|
|
|
|
try:
|
|
|
|
|
|
|
|
cursor.execute(
|
|
|
|
cursor.execute(
|
|
|
|
'SELECT host, name, value, path, expiry, isSecure FROM moz_cookies WHERE originAttributes=?',
|
|
|
|
'SELECT host, name, value, path, expiry, isSecure FROM moz_cookies WHERE originAttributes LIKE ? OR originAttributes LIKE ?',
|
|
|
|
(origin_attributes, ))
|
|
|
|
(f'%userContextId={container_id}', f'%userContextId={container_id}&%'))
|
|
|
|
except sqlite3.OperationalError:
|
|
|
|
elif container == 'none':
|
|
|
|
logger.debug('Database exception, loading all cookies')
|
|
|
|
logger.debug('Only loading cookies not belonging to any container')
|
|
|
|
|
|
|
|
cursor.execute(
|
|
|
|
|
|
|
|
'SELECT host, name, value, path, expiry, isSecure FROM moz_cookies WHERE NOT INSTR(originAttributes,"userContextId=")')
|
|
|
|
|
|
|
|
else:
|
|
|
|
cursor.execute('SELECT host, name, value, path, expiry, isSecure FROM moz_cookies')
|
|
|
|
cursor.execute('SELECT host, name, value, path, expiry, isSecure FROM moz_cookies')
|
|
|
|
jar = YoutubeDLCookieJar()
|
|
|
|
jar = YoutubeDLCookieJar()
|
|
|
|
with _create_progress_bar(logger) as progress_bar:
|
|
|
|
with _create_progress_bar(logger) as progress_bar:
|
|
|
|