From f67314f6bcfc8ccc1621e8c3d21dd2a76849fa64 Mon Sep 17 00:00:00 2001 From: Jaisen Mathai Date: Sun, 29 Nov 2015 22:01:27 -0800 Subject: [PATCH] gh-2 Write to EXIF from earlier of modified or access time if no date is found in EXIF --- elodie.py | 2 +- elodie/filesystem.py | 2 ++ elodie/media/media.py | 1 - elodie/media/photo.py | 2 +- elodie/media/video.py | 11 ++++++++--- 5 files changed, 12 insertions(+), 6 deletions(-) diff --git a/elodie.py b/elodie.py index 0222842..5980096 100755 --- a/elodie.py +++ b/elodie.py @@ -98,7 +98,7 @@ def _update(params): if(time_format is not None): time = datetime.strptime(time_string, time_format) - media.set_datetime(time) + media.set_date_taken(time) updated = True if(params['--album'] is not None): diff --git a/elodie/filesystem.py b/elodie/filesystem.py index 495cbb9..cf99d09 100644 --- a/elodie/filesystem.py +++ b/elodie/filesystem.py @@ -158,7 +158,9 @@ class FileSystem: self.create_directory(dest_directory) if(move == True): + stat = os.stat(_file) shutil.move(_file, dest_path) + os.utime(dest_path, (stat.st_atime, stat.st_mtime)) else: shutil.copy2(_file, dest_path) diff --git a/elodie/media/media.py b/elodie/media/media.py index 6627c1d..3c1ac31 100644 --- a/elodie/media/media.py +++ b/elodie/media/media.py @@ -335,7 +335,6 @@ class Media(object): name = 'Video' for i in classes: - print i.__name__ if(name == i.__name__): return i(_file) diff --git a/elodie/media/photo.py b/elodie/media/photo.py index 6ed46a6..f826dbb 100644 --- a/elodie/media/photo.py +++ b/elodie/media/photo.py @@ -57,7 +57,7 @@ class Photo(Media): @returns, boolean """ - def set_datetime(self, time): + def set_date_taken(self, time): if(time is None): return False diff --git a/elodie/media/video.py b/elodie/media/video.py index 80cba3f..b1857a6 100644 --- a/elodie/media/video.py +++ b/elodie/media/video.py @@ -111,7 +111,7 @@ class Video(Media): # If the time wasn't found in EXIF we need to add it there since the modified/access times frequently change if(time_found_in_exif == False): - self.set_datetime(datetime.fromtimestamp(seconds_since_epoch)) + self.set_date_taken(datetime.fromtimestamp(seconds_since_epoch)) return time.gmtime(seconds_since_epoch) @@ -155,11 +155,16 @@ class Video(Media): @returns, boolean """ - def set_datetime(self, time): + def set_date_taken(self, date_taken_as_datetime): if(time is None): return False - result = self.__update_using_plist(time=time) + source = self.source + + result = self.__update_using_plist(time=date_taken_as_datetime) + if(result == True): + os.utime(source, (int(time.time()), time.mktime(date_taken_as_datetime.timetuple()))) + return result """