jdaymude / xbox2local

A command line utility for downloading Xbox screenshots and game clips to local storage
MIT License
8 stars 2 forks source link

Preserving creation metadata fails to accurately track date times. #25

Closed ktiedt closed 2 months ago

ktiedt commented 1 year ago

Description Looking at the results from this code today, it does not appear to be working correctly. In the screenshot here you can see there are now dates from in the future which were taken today. I also was not creating clips at 1am... Is there a timezone issue not being taken into account from the API maybe?

Screen Shot 2023-06-15 at 12 46 26 PM

To Reproduce Steps to reproduce the behavior:

  1. Just use the latest version, dates will be wrong.
  2. See error

Expected Behavior Dates should align with the current data and reality, ie: not assign dates in the future.

ktiedt commented 11 months ago

The below changes, appears to fix this in update.py at least... I confirmed with a local test clip this morning and the date time on my local laptop was accurately set to within a second (Xbox app rounds the time up occasionally it seems) of the reported timestamp when downloading the file directly thru the xbox app.

diff --git a/update.py b/update.py
index 787f8ad..f966023 100644
--- a/update.py
+++ b/update.py
@@ -33,11 +33,18 @@ def set_accmod_datetime(username):

     # Set all media's last accessed and modified times to their capture times.
     tqdm.write('Updating downloaded media\'s last access/modify times...')
+    from_zone = tz.tzutc()
+    to_zone = tz.tzlocal()
+
     for media in tqdm(list(history_df.itertuples())):
         fpath = osp.join(media_dir, media.game, media.capture_dt)
         ext = '.png' if media.type == 'screenshot' else '.mp4'
-        accmod_dt = datetime.strptime(media.capture_dt, DT_FMT)
-        os.utime(fpath + ext, (accmod_dt.timestamp(), accmod_dt.timestamp()))
+        accmod_dt_utc = datetime.strptime(media.capture_dt, DT_FMT)
+        accmod_dt_utc = accmod_dt_utc.replace(tzinfo=from_zone)
+        accmod_dt_local = accmod_dt_utc.astimezone(to_zone)
+
+        # tqdm.write(f"{fpath} created at {accmod_dt_local}\n");
+        os.utime(fpath + ext, (accmod_dt_local.timestamp(), accmod_dt_local.timestamp()))

 if __name__ == '__main__':
(END)