diff --git a/.attach_pid3511 b/.attach_pid3511 new file mode 100644 index 0000000..e69de29 diff --git a/src/main/resources/scripts/photophetch-ios-helper.py b/src/main/resources/scripts/photophetch-ios-helper.py index 47176ef..3c8a29c 100644 --- a/src/main/resources/scripts/photophetch-ios-helper.py +++ b/src/main/resources/scripts/photophetch-ios-helper.py @@ -157,6 +157,37 @@ async def cmd_pull_thumb(device_path: str, local_path: str): sys.exit(1) +async def cmd_batch_thumbs(pairs_json: str): + """ + Pull thumbnails for multiple files in a single AFC session. + Input: JSON array of [device_path, local_path] pairs. + Output: JSON array of {devicePath, ok} results. + """ + try: + pairs = json.loads(pairs_json) + lockdown = await get_lockdown() + afc = await get_afc(lockdown) + results = [] + for device_path, local_path in pairs: + try: + os.makedirs(os.path.dirname(os.path.abspath(local_path)), exist_ok=True) + try: + data = await afc.fread(device_path, 512 * 1024, 0) + except Exception: + await afc.pull(device_path, local_path) + results.append({'devicePath': device_path, 'ok': True}) + continue + with open(local_path, 'wb') as f: + f.write(data) + results.append({'devicePath': device_path, 'ok': True}) + except Exception as e: + results.append({'devicePath': device_path, 'ok': False, 'error': str(e)}) + print(json.dumps(results)) + except Exception as e: + print(f'Error: {e}', file=sys.stderr) + sys.exit(1) + + async def cmd_delete(device_path: str): try: lockdown = await get_lockdown() @@ -183,6 +214,8 @@ if __name__ == '__main__': asyncio.run(cmd_pull(sys.argv[2], sys.argv[3])) elif command == 'pull-thumb' and len(sys.argv) == 4: asyncio.run(cmd_pull_thumb(sys.argv[2], sys.argv[3])) + elif command == 'batch-thumbs' and len(sys.argv) == 3: + asyncio.run(cmd_batch_thumbs(sys.argv[2])) elif command == 'delete' and len(sys.argv) == 3: asyncio.run(cmd_delete(sys.argv[2])) else: