Skip to content
This repository has been archived by the owner on Mar 24, 2024. It is now read-only.

Preserve session cookies #39

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions gimme_iphotos/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ def get_cli_args() -> argparse.Namespace:
"--password",
help="iCloud password. Can be specified interactively if not set.",
)
parser.add_argument(
"--cookie-directory",
dest="cookie_directory",
help="Directory to store cookie files.\n"
+ "Cookies can be used to avoid authentication step for subsequent runs.\n"
+ "If not set, cookies are stored in a temporary directory and usually deleted between restarts.",
)
parser.add_argument(
"-d",
"--destination",
Expand Down
13 changes: 10 additions & 3 deletions gimme_iphotos/downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class DownloaderApp:
DEFAULTS = {
"username": None,
"password": None,
"cookie_directory": None,
"destination": None,
"overwrite": False,
"remove": False,
Expand Down Expand Up @@ -119,9 +120,15 @@ def connect_to_icloud(
) -> PyiCloudService:
self.logger.info("Connecting to iCloud…")
if config["password"] == "":
api = PyiCloudService(config["username"])
api = PyiCloudService(
config["username"], cookie_directory=config["cookie_directory"]
)
else:
api = PyiCloudService(config["username"], config["password"])
api = PyiCloudService(
config["username"],
password=config["password"],
cookie_directory=config["cookie_directory"],
)

if api.requires_2sa:
print("Two-step authentication required.")
Expand Down Expand Up @@ -193,8 +200,8 @@ def download_photos(
# FIXME Cancelling doesn't work well with ThreadPoolExecutor. I didn't find a way to cancel tasks if they're
# already running. Maybe it makes sense using lower level of threading API.
with ThreadPoolExecutor(max_workers=parallel) as executor:
downloads = []
try:
downloads = []
for photo in collection:
total_count += 1
filename = self.name_photo(photo, icloud_photos, destination)
Expand Down