Created
August 26, 2020 17:02
-
-
Save dulacp/0a515aece8b2a17ffb598b91a633bc53 to your computer and use it in GitHub Desktop.
Download all images from Zenfolio
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import re | |
import requests | |
import zenapi | |
_dir_root = '~/Downloads/ZenfolioBackup' | |
def process_gallery(gallery, curr_dir): | |
gallery = zen.LoadPhotoSet( | |
gallery.Id, level=zenapi._zapi.InformationLevel.Level2, includePhotos=True) | |
for photo in gallery.Photos: | |
if photo.IsVideo: | |
continue | |
fp = os.path.join(curr_dir, photo.FileName) | |
if not os.path.exists(fp): | |
headers = {'X-Zenfolio-Token': zen.auth} | |
response = requests.get(photo.OriginalUrl, headers=headers, stream=True) | |
if response.status_code == 200: | |
with open(fp, 'wb') as f: | |
for chunk in response.iter_content(1024): | |
f.write(chunk) | |
def process_group(group, curr_dir): | |
for element in group.Elements: | |
dir_name = re.sub(r'[/\\:*?""<>|]', '_', element.Title) | |
dir = os.path.join(curr_dir, dir_name) | |
if isinstance(element, zenapi._zapi.Group): | |
process_group(element, dir) | |
continue | |
# Download physical galleries only. Collections are skipped. | |
if element.Type == 'Gallery': | |
if not os.path.exists(dir): | |
os.makedirs(dir) | |
process_gallery(element, dir) | |
if __name__ == '__main__': | |
zen = zenapi.ZenConnection(username='YOUR_USERNAME', password='YOUR_PASSWORD') | |
zen.Authenticate() | |
root = zen.LoadGroupHierarchy() | |
process_group(root, _dir_root) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi. Where can I find the Zen API (zenapi) module to install?