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
**/*.pyc
**/config.ini

View File

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

View File

@ -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.

View File

@ -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(),