Fix iOS date: use 'datetime' tuple key from AFC stat
pymobiledevice3 AfcService.stat() returns 'datetime' as a tuple (year, month, day, hour, minute, second, microsecond) not 'st_mtime'. Parse it directly into a datetime object and emit as ISO string.
This commit is contained in:
@@ -91,20 +91,25 @@ async def cmd_list_photos():
|
|||||||
try:
|
try:
|
||||||
info = await afc.stat(device_path)
|
info = await afc.stat(device_path)
|
||||||
if not debug_logged:
|
if not debug_logged:
|
||||||
print(f'DEBUG stat keys: {list(info.keys())}', file=sys.stderr)
|
print(f'DEBUG stat: {dict(info)}', file=sys.stderr)
|
||||||
print(f'DEBUG stat values: {dict(info)}', file=sys.stderr)
|
|
||||||
debug_logged = True
|
debug_logged = True
|
||||||
size_bytes = int(info.get('st_size', 0))
|
size_bytes = int(info.get('st_size', 0))
|
||||||
mtime_raw = int(info.get('st_mtime', 0))
|
# pymobiledevice3 returns 'datetime' as a tuple:
|
||||||
# Determine if nanoseconds (>1e15) or seconds (>1e9)
|
# (year, month, day, hour, minute, second, microsecond)
|
||||||
if mtime_raw > 1_000_000_000_000_000:
|
dt = info.get('datetime')
|
||||||
mtime_s = mtime_raw / 1_000_000_000
|
if dt is not None:
|
||||||
elif mtime_raw > 1_000_000_000:
|
if hasattr(dt, 'isoformat'):
|
||||||
mtime_s = float(mtime_raw)
|
date_iso = dt.isoformat()
|
||||||
|
elif isinstance(dt, (list, tuple)) and len(dt) >= 6:
|
||||||
|
date_iso = datetime(int(dt[0]), int(dt[1]), int(dt[2]),
|
||||||
|
int(dt[3]), int(dt[4]), int(dt[5])).isoformat()
|
||||||
else:
|
else:
|
||||||
mtime_s = 0.0
|
# Fallback: try st_mtime as integer timestamp
|
||||||
if mtime_s > 0:
|
mtime_raw = int(info.get('st_mtime', 0))
|
||||||
date_iso = datetime.fromtimestamp(mtime_s).isoformat()
|
if mtime_raw > 1_000_000_000_000_000:
|
||||||
|
mtime_raw = mtime_raw // 1_000_000_000
|
||||||
|
if mtime_raw > 1_000_000_000:
|
||||||
|
date_iso = datetime.fromtimestamp(float(mtime_raw)).isoformat()
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user