diff --git a/gallery_dl/cookies.py b/gallery_dl/cookies.py index 71a45f008c8..08723fbb0b8 100644 --- a/gallery_dl/cookies.py +++ b/gallery_dl/cookies.py @@ -1001,15 +1001,21 @@ class DATA_BLOB(ctypes.Structure): def _find_most_recently_used_file(root, filename): - # if there are multiple browser profiles, take the most recently used one - paths = [] - for curr_root, dirs, files in os.walk(root): - for file in files: - if file == filename: - paths.append(os.path.join(curr_root, file)) - if not paths: - return None - return max(paths, key=lambda path: os.lstat(path).st_mtime) + # if the provided root points to an exact profile path + # check if it contains the wanted filename + first_choice = os.path.join(root, filename) + if os.path.exists(first_choice): + return first_choice + else: + # if there are multiple browser profiles, take the most recently used one + paths = [] + for curr_root, dirs, files in os.walk(root): + for file in files: + if file == filename: + paths.append(os.path.join(curr_root, file)) + if not paths: + return None + return max(paths, key=lambda path: os.lstat(path).st_mtime) def _is_path(value):