From c9d52aaa594a5f0a1303d72a64e6748d32fd644b Mon Sep 17 00:00:00 2001 From: Jaisen Mathai Date: Thu, 8 Oct 2015 02:22:30 -0700 Subject: [PATCH] Initial version of photo importer --- .gitignore | 1 + README.md | 3 +++ elodie/filesystem.py | 24 +++++++++++++++++++++++- elodie/media/photo.py | 20 ++++++++++++++------ 4 files changed, 41 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index a5e4b19..9fa5594 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ **/.DS_Store **/*.pyc +**/config.ini diff --git a/README.md b/README.md index fc4bccf..bfbd3a0 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,6 @@ # elodie pip install exifread pip install LatLon +pip install requests + +Need config.ini for reverse lookup diff --git a/elodie/filesystem.py b/elodie/filesystem.py index 7978f86..3b949b0 100644 --- a/elodie/filesystem.py +++ b/elodie/filesystem.py @@ -6,6 +6,8 @@ import os import re import time +from elodie import geolocation + """ General file system methods """ @@ -51,7 +53,7 @@ class FileSystem: @param, video, Video, A Video instance @returns, string or None for non-videos """ - def get_file_name_for_video(self, video): + def get_file_name(self, video): if(not video.is_valid()): return None @@ -71,6 +73,26 @@ class FileSystem: def get_folder_name_by_date(self, time_obj): return time.strftime('%Y-%m-%b', time_obj) + """ + Get folder path by various parameters. + + @param, time_obj, time, Time object to be used to determine folder name. + @returns, string + """ + def get_folder_path(self, **kwargs): + path = [] + if('date' in kwargs): + path.append(time.strftime('%Y-%m-%b', kwargs['date'])) + + if('latitude' in kwargs and 'longitude' in kwargs): + place_name = geolocation.place_name(kwargs['latitude'], kwargs['longitude']) + if(place_name is None): + path.append('Unknown Location') + else: + path.append(place_name) + + return '/'.join(path) + """ Set the modification time on the file based on the file path. Noop if the path doesn't match the format YYYY-MM/DD-IMG_0001.JPG. diff --git a/elodie/media/photo.py b/elodie/media/photo.py index 6e91804..96ec33b 100644 --- a/elodie/media/photo.py +++ b/elodie/media/photo.py @@ -52,11 +52,11 @@ class Photo(Media): # Sourced from https://github.com/photo/frontend/blob/master/src/libraries/models/Photo.php#L500 exif = self.get_exif() if('EXIF DateTimeOriginal' in exif): - seconds_since_epoch = time.mktime(datetime.strptime(exif['EXIF DateTimeOriginal'], '%Y:%m:%d %H:%M:%S').timetuple()) + seconds_since_epoch = time.mktime(datetime.strptime(str(exif['EXIF DateTimeOriginal']), '%Y:%m:%d %H:%M:%S').timetuple()) elif('EXIF DateTime' in exif): - seconds_since_epoch = time.mktime(datetime.strptime(exif['EXIF DateTime'], '%Y:%m:%d %H:%M:%S').timetuple()) + seconds_since_epoch = time.mktime(datetime.strptime(str(exif['EXIF DateTime']), '%Y:%m:%d %H:%M:%S').timetuple()) elif('EXIF FileDateTime' in exif): - seconds_since_epoch = exif['EXIF DateTime'] + seconds_since_epoch = str(exif['EXIF DateTime']) if(seconds_since_epoch == 0): return None @@ -115,11 +115,19 @@ class Photo(Media): if(key not in exif): return None + # this is a hack to get the proper direction by negating the values for S and W + latdir = 1 + if(key == 'GPS GPSLatitude' and str(exif['GPS GPSLatitudeRef']) == 'S'): + latdir = -1 + londir = 1 + if(key == 'GPS GPSLongitude' and str(exif['GPS GPSLongitudeRef']) == 'W'): + londir = -1 + coords = [float(Fraction(ratio.num, ratio.den)) for ratio in exif[key].values] if(key == 'latitude'): - return str(LatLon.Latitude(degree=coords[0], minute=coords[1], second=coords[2])) + return float(str(LatLon.Latitude(degree=coords[0], minute=coords[1], second=coords[2]))) * latdir else: - return str(LatLon.Longitude(degree=coords[0], minute=coords[1], second=coords[2])) + return float(str(LatLon.Longitude(degree=coords[0], minute=coords[1], second=coords[2]))) * londir """ Get a dictionary of metadata for a photo. @@ -134,7 +142,7 @@ class Photo(Media): source = self.source metadata = { - #"date_taken": self.get_date_taken(), + "date_taken": self.get_date_taken(), "latitude": self.get_coordinate('latitude'), "longitude": self.get_coordinate('longitude'), "mime_type": self.get_mimetype(),