Initial version of photo importer

This commit is contained in:
Jaisen Mathai 2015-10-08 02:22:30 -07:00
parent 6b91c06a51
commit c9d52aaa59
4 changed files with 41 additions and 7 deletions

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
**/.DS_Store **/.DS_Store
**/*.pyc **/*.pyc
**/config.ini

View File

@ -1,3 +1,6 @@
# elodie # elodie
pip install exifread pip install exifread
pip install LatLon pip install LatLon
pip install requests
Need config.ini for reverse lookup

View File

@ -6,6 +6,8 @@ import os
import re import re
import time import time
from elodie import geolocation
""" """
General file system methods General file system methods
""" """
@ -51,7 +53,7 @@ class FileSystem:
@param, video, Video, A Video instance @param, video, Video, A Video instance
@returns, string or None for non-videos @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()): if(not video.is_valid()):
return None return None
@ -71,6 +73,26 @@ class FileSystem:
def get_folder_name_by_date(self, time_obj): def get_folder_name_by_date(self, time_obj):
return time.strftime('%Y-%m-%b', 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. 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. Noop if the path doesn't match the format YYYY-MM/DD-IMG_0001.JPG.

View File

@ -52,11 +52,11 @@ class Photo(Media):
# Sourced from https://github.com/photo/frontend/blob/master/src/libraries/models/Photo.php#L500 # Sourced from https://github.com/photo/frontend/blob/master/src/libraries/models/Photo.php#L500
exif = self.get_exif() exif = self.get_exif()
if('EXIF DateTimeOriginal' in 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): 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): elif('EXIF FileDateTime' in exif):
seconds_since_epoch = exif['EXIF DateTime'] seconds_since_epoch = str(exif['EXIF DateTime'])
if(seconds_since_epoch == 0): if(seconds_since_epoch == 0):
return None return None
@ -115,11 +115,19 @@ class Photo(Media):
if(key not in exif): if(key not in exif):
return None 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] coords = [float(Fraction(ratio.num, ratio.den)) for ratio in exif[key].values]
if(key == 'latitude'): 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: 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. Get a dictionary of metadata for a photo.
@ -134,7 +142,7 @@ class Photo(Media):
source = self.source source = self.source
metadata = { metadata = {
#"date_taken": self.get_date_taken(), "date_taken": self.get_date_taken(),
"latitude": self.get_coordinate('latitude'), "latitude": self.get_coordinate('latitude'),
"longitude": self.get_coordinate('longitude'), "longitude": self.get_coordinate('longitude'),
"mime_type": self.get_mimetype(), "mime_type": self.get_mimetype(),