Created
April 4, 2018 15:45
-
-
Save omz/a307516e9d1b64410210e030211625be to your computer and use it in GitHub Desktop.
DownloadPhotosFromCloud.py
This file contains 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
# Quick workaround for photos module (Pythonista) not downloading photos from iCloud | |
import photos | |
from objc_util import ObjCClass, ObjCInstance, ObjCBlock | |
def download_cloud_asset(asset): | |
PHImageManager = ObjCClass('PHImageManager') | |
PHImageRequestOptions = ObjCClass('PHImageRequestOptions') | |
ph_asset = ObjCInstance(asset) | |
ph_image_mgr = PHImageManager.defaultManager() | |
req_options = PHImageRequestOptions.alloc().init().autorelease() | |
req_options.synchronous = True | |
req_options.networkAccessAllowed = True | |
def handler_f(*args): | |
pass | |
handler_block = ObjCBlock(handler_f) | |
ph_image_mgr.requestImageDataForAsset(ph_asset, options=req_options, resultHandler=handler_block) | |
def main(): | |
a = photos.get_assets()[-1] | |
print('Downloading data for last asset... (if needed)') | |
download_cloud_asset(a) | |
print('Done') | |
if __name__ == '__main__': | |
main() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment