iOS thumbnails: add batch-thumbs command for future optimization
batch-thumbs pulls multiple files in one Python process session, amortising the pymobiledevice3 startup cost. Not yet wired into the app — thumbnails load lazily per-cell and cache permanently. Known limitation: first load of iPhone thumbnails is slow (~2-3s each) because each pull spawns a new Python process. After first view they are instant from the on-disk cache.
This commit is contained in:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user