Permalink
Browse files

Merge 6f5e6f9 into fd3cab4

  • Loading branch information...
jmathai committed Oct 8, 2017
2 parents fd3cab4 + 6f5e6f9 commit 68a97e179a337024160a80e7953e64dcb5e92a46
Showing with 90 additions and 3 deletions.
  1. +3 −3 elodie/filesystem.py
  2. +8 −0 elodie/media/base.py
  3. +38 −0 elodie/media/media.py
  4. +17 −0 elodie/tests/filesystem_test.py
  5. +24 −0 elodie/tests/media/photo_test.py
View
@@ -251,9 +251,9 @@ def get_folder_path(self, metadata):
)
path.append(parsed_folder_name)
break
elif part in ('album'):
if metadata['album']:
path.append(metadata['album'])
elif part in ('album', 'camera_make', 'camera_model'):
if metadata[part]:
path.append(metadata[part])
break
elif part.startswith('"') and part.endswith('"'):
path.append(part[1:-1])
View
@@ -68,6 +68,12 @@ def get_extension(self):
source = self.source
return os.path.splitext(source)[1][1:].lower()
def get_camera_make(self):
return None
def get_camera_model(self):
return None
def get_metadata(self, update_cache=False):
"""Get a dictionary of metadata for any file.
@@ -85,6 +91,8 @@ def get_metadata(self, update_cache=False):
self.metadata = {
'date_taken': self.get_date_taken(),
'camera_make': self.get_camera_make(),
'camera_model': self.get_camera_model(),
'latitude': self.get_coordinate('latitude'),
'longitude': self.get_coordinate('longitude'),
'album': self.get_album(),
View
@@ -42,6 +42,8 @@ def __init__(self, source=None):
'EXIF:ModifyDate'
]
}
self.camera_make_key = 'EXIF:Make'
self.camera_model_key = 'EXIF:Model'
self.album_keys = ['XMP-xmpDM:Album', 'XMP:Album']
self.title_key = 'XMP:Title'
self.latitude_keys = ['EXIF:GPSLatitude']
@@ -132,6 +134,42 @@ def get_exiftool_attributes(self):
return metadata
def get_camera_make(self):
"""Get the camera make stored in EXIF.
:returns: str
"""
if(not self.is_valid()):
return None
exiftool_attributes = self.get_exiftool_attributes()
if exiftool_attributes is None:
return None
if(self.camera_make_key not in exiftool_attributes):
return None
return exiftool_attributes[self.camera_make_key]
def get_camera_model(self):
"""Get the camera make stored in EXIF.
:returns: str
"""
if(not self.is_valid()):
return None
exiftool_attributes = self.get_exiftool_attributes()
if exiftool_attributes is None:
return None
if(self.camera_model_key not in exiftool_attributes):
return None
return exiftool_attributes[self.camera_model_key]
def get_original_name(self):
"""Get the original name stored in EXIF.
@@ -226,6 +226,23 @@ def test_get_folder_path_with_location():
assert path == os.path.join('2015-12-Dec','Sunnyvale'), path
@mock.patch('elodie.config.config_file', '%s/config.ini-original-with-camera-make-and-model' % gettempdir())
def test_get_folder_path_with_camera_make_and_model():
with open('%s/config.ini-original-with-camera-make-and-model' % gettempdir(), 'w') as f:
f.write("""
[Directory]
full_path=%camera_make/%camera_model
""")
if hasattr(load_config, 'config'):
del load_config.config
filesystem = FileSystem()
media = Photo(helper.get_file('plain.jpg'))
path = filesystem.get_folder_path(media.get_metadata())
if hasattr(load_config, 'config'):
del load_config.config
assert path == os.path.join('Canon', 'Canon EOS REBEL T2i'), path
@mock.patch('elodie.config.config_file', '%s/config.ini-original-default-unknown-location' % gettempdir())
def test_get_folder_path_with_original_default_unknown_location():
with open('%s/config.ini-original-default-with-unknown-location' % gettempdir(), 'w') as f:
@@ -125,6 +125,30 @@ def test_get_date_taken_without_exif():
assert date_taken == date_taken_from_file, date_taken
def test_get_camera_make():
photo = Photo(helper.get_file('with-location.jpg'))
make = photo.get_camera_make()
assert make == 'Canon', make
def test_get_camera_make_not_set():
photo = Photo(helper.get_file('no-exif.jpg'))
make = photo.get_camera_make()
assert make is None, make
def test_get_camera_model():
photo = Photo(helper.get_file('with-location.jpg'))
model = photo.get_camera_model()
assert model == 'Canon EOS REBEL T2i', model
def test_get_camera_model_not_set():
photo = Photo(helper.get_file('no-exif.jpg'))
model = photo.get_camera_model()
assert model is None, model
def test_is_valid():
photo = Photo(helper.get_file('with-location.jpg'))

0 comments on commit 68a97e1

Please sign in to comment.