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.
This commit is contained in:
@@ -91,15 +91,13 @@ async def cmd_list_photos():
|
|||||||
info = await afc.stat(device_path)
|
info = await afc.stat(device_path)
|
||||||
size_bytes = int(info.get('st_size', 0))
|
size_bytes = int(info.get('st_size', 0))
|
||||||
mtime_raw = int(info.get('st_mtime', 0))
|
mtime_raw = int(info.get('st_mtime', 0))
|
||||||
# AFC st_mtime is nanoseconds since epoch (not seconds)
|
# Determine if nanoseconds (>1e15) or seconds (>1e9)
|
||||||
# A reasonable photo date in nanoseconds is > 1e18
|
if mtime_raw > 1_000_000_000_000_000:
|
||||||
# In seconds it would be > 1e9 (year 2001+)
|
|
||||||
if mtime_raw > 1_000_000_000_000_000_000:
|
|
||||||
mtime_s = mtime_raw / 1_000_000_000
|
mtime_s = mtime_raw / 1_000_000_000
|
||||||
elif 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:
|
else:
|
||||||
mtime_s = 0
|
mtime_s = 0.0
|
||||||
if mtime_s > 0:
|
if mtime_s > 0:
|
||||||
date_iso = datetime.fromtimestamp(mtime_s).isoformat()
|
date_iso = datetime.fromtimestamp(mtime_s).isoformat()
|
||||||
except Exception:
|
except Exception:
|
||||||
@@ -127,9 +125,8 @@ async def cmd_pull(device_path: str, local_path: str):
|
|||||||
lockdown = await get_lockdown()
|
lockdown = await get_lockdown()
|
||||||
afc = await get_afc(lockdown)
|
afc = await get_afc(lockdown)
|
||||||
os.makedirs(os.path.dirname(os.path.abspath(local_path)), exist_ok=True)
|
os.makedirs(os.path.dirname(os.path.abspath(local_path)), exist_ok=True)
|
||||||
data = await afc.get_file_contents(device_path)
|
# afc.pull(src, dst) — copies remote file to local path
|
||||||
with open(local_path, 'wb') as f:
|
await afc.pull(device_path, local_path)
|
||||||
f.write(data)
|
|
||||||
print(json.dumps({'ok': True, 'path': local_path}))
|
print(json.dumps({'ok': True, 'path': local_path}))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f'Error: {e}', file=sys.stderr)
|
print(f'Error: {e}', file=sys.stderr)
|
||||||
|
|||||||
Reference in New Issue
Block a user