From fecdef3acfbb6d615ec7c14971843a5dd017354a Mon Sep 17 00:00:00 2001 From: Kyle Bolen Date: Tue, 28 Jul 2026 08:26:30 +0000 Subject: [PATCH] Fix date parsing: handle both nanosecond and second AFC timestamps Threshold: >1e15 = nanoseconds, >1e9 = seconds. Previous threshold of 1e18 was too high for nanosecond timestamps in the year 2025 range (which are ~1.75e18, so actually fine). Also revert pull to use afc.pull() since it exists in this pymobiledevice3 version. --- .../resources/scripts/photophetch-ios-helper.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/main/resources/scripts/photophetch-ios-helper.py b/src/main/resources/scripts/photophetch-ios-helper.py index dc0f769..ec9d0df 100644 --- a/src/main/resources/scripts/photophetch-ios-helper.py +++ b/src/main/resources/scripts/photophetch-ios-helper.py @@ -91,15 +91,13 @@ async def cmd_list_photos(): info = await afc.stat(device_path) size_bytes = int(info.get('st_size', 0)) mtime_raw = int(info.get('st_mtime', 0)) - # AFC st_mtime is nanoseconds since epoch (not seconds) - # A reasonable photo date in nanoseconds is > 1e18 - # In seconds it would be > 1e9 (year 2001+) - if mtime_raw > 1_000_000_000_000_000_000: + # Determine if nanoseconds (>1e15) or seconds (>1e9) + if mtime_raw > 1_000_000_000_000_000: mtime_s = mtime_raw / 1_000_000_000 elif mtime_raw > 1_000_000_000: - mtime_s = mtime_raw # already seconds + mtime_s = float(mtime_raw) else: - mtime_s = 0 + mtime_s = 0.0 if mtime_s > 0: date_iso = datetime.fromtimestamp(mtime_s).isoformat() except Exception: @@ -127,9 +125,8 @@ async def cmd_pull(device_path: str, local_path: str): lockdown = await get_lockdown() afc = await get_afc(lockdown) os.makedirs(os.path.dirname(os.path.abspath(local_path)), exist_ok=True) - data = await afc.get_file_contents(device_path) - with open(local_path, 'wb') as f: - f.write(data) + # afc.pull(src, dst) — copies remote file to local path + await afc.pull(device_path, local_path) print(json.dumps({'ok': True, 'path': local_path})) except Exception as e: print(f'Error: {e}', file=sys.stderr)