Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please add example for download all album and all photo from google photo to local #23

Open
patsevanton opened this issue Apr 18, 2022 · 1 comment

Comments

@patsevanton
Copy link

patsevanton commented Apr 18, 2022

Hello! Thanks for gphotospy.
Please add example for download all album and all photo from google photo to local.
Thanks!

@goneri
Copy link

goneri commented May 7, 2023

This is how I did it. Just create the local_storage directory first.

#!/usr/bin/env python3

from gphotospy import authorize
from gphotospy.media import Media, MediaItem
from pathlib import Path
import urllib.error


# Select secrets file (got through Google's API console)
CLIENT_SECRET_FILE = "credentials.json" # Here your secret's file. See below.

# Get authorization and return a service object
service = authorize.init(CLIENT_SECRET_FILE)


local_storage = Path("local_storage")


media_manager = Media(service)
for i in media_manager.list():
    i = MediaItem(i)
    print(i.filename())
    local_file = local_storage / i.filename()
    if not local_file.exists():
        try:
            content = i.raw_download()
        except urllib.error.HTTPError:
            print(f"Cannot download: {i.filename()}")
            continue
        local_file.write_bytes(content)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants