Skip to content

Instantly share code, notes, and snippets.

@dulacp
Created August 26, 2020 17:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dulacp/0a515aece8b2a17ffb598b91a633bc53 to your computer and use it in GitHub Desktop.
Save dulacp/0a515aece8b2a17ffb598b91a633bc53 to your computer and use it in GitHub Desktop.
Download all images from Zenfolio
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)
@graz68a
Copy link

graz68a commented Jun 13, 2021

Hello

it works great for images, but what to do to download videos too ?

Thank you!

@dulacp
Copy link
Author

dulacp commented Jan 3, 2022

Late reply, sorry for this.
For posterity, in case others bump into this, to download videos too you will need to implement the logic at lines L14-L15, you could probably even just remove these lines and see if there is any bug.

Cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment