diff --git a/.gitignore b/.gitignore index 16be19f..5114e68 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,5 @@ dist/** docs/_build build/** +**/*.nef +**/*.dng diff --git a/elodie/media/media.py b/elodie/media/media.py index 093ced0..e65ac2a 100644 --- a/elodie/media/media.py +++ b/elodie/media/media.py @@ -37,7 +37,7 @@ class Media(object): def __init__(self, source=None): self.source = source self.exif_map = { - 'date_taken': ['Exif.Photo.DateTimeOriginal', 'Exif.Image.DateTime'], # , 'EXIF FileDateTime'], # noqa + 'date_taken': ['Exif.Photo.DateTimeOriginal', 'Exif.Image.DateTime', 'Exif.Photo.DateTimeDigitized'], # , 'EXIF FileDateTime'], # noqa 'latitude': 'Exif.GPSInfo.GPSLatitude', 'latitude_ref': 'Exif.GPSInfo.GPSLatitudeRef', 'longitude': 'Exif.GPSInfo.GPSLongitude', @@ -256,8 +256,6 @@ class Media(object): def set_album_from_folder(self): metadata = self.get_metadata() - print 'huh/' - # If this file has an album already set we do not overwrite EXIF if(metadata['album'] is not None): return False diff --git a/elodie/media/photo.py b/elodie/media/photo.py index c181b4d..1f599b9 100644 --- a/elodie/media/photo.py +++ b/elodie/media/photo.py @@ -153,7 +153,7 @@ class Photo(Media): # Writing exif with pyexiv2 differs if the key already exists so we # handle both cases here. - for key in ['Exif.Photo.DateTimeOriginal', 'Exif.Image.DateTime']: + for key in self.exif_map['date_taken']: if(key in exif_metadata): exif_metadata[key].value = time else: diff --git a/elodie/tests/helper.py b/elodie/tests/helper.py index e54ce17..3c7afea 100644 --- a/elodie/tests/helper.py +++ b/elodie/tests/helper.py @@ -5,6 +5,7 @@ import string import tempfile import re import time +import urllib from datetime import datetime from datetime import timedelta @@ -27,7 +28,25 @@ def create_working_folder(): return (temporary_folder, folder) +def download_file(name, destination): + try: + final_name = '{}/{}{}'.format(destination, random_string(10), os.path.splitext(name)[1]) + urllib.urlretrieve( + 'https://s3.amazonaws.com/jmathai/github/elodie/{}'.format(name), + final_name + ) + return final_name + except Exception as e: + return False + def get_file(name): + file_path = get_file_path(name) + if not os.path.isfile(file_path): + return False + + return file_path + +def get_file_path(name): current_folder = os.path.dirname(os.path.realpath(__file__)) return os.path.join(current_folder, 'files', name) diff --git a/elodie/tests/media/photo_test.py b/elodie/tests/media/photo_test.py index 6303707..d371477 100644 --- a/elodie/tests/media/photo_test.py +++ b/elodie/tests/media/photo_test.py @@ -235,3 +235,111 @@ def test_set_title_non_ascii(): shutil.rmtree(folder) assert metadata['title'] == utf8_title, metadata['title'] + +def test_get_metadata_from_nef(): + temporary_folder, folder = helper.create_working_folder() + + photo_file = helper.get_file('photo.nef') + origin = '%s/photo.nef' % folder + + if not photo_file: + photo_file = helper.download_file('photo.nef', folder) + if not photo_file or not os.path.isfile(photo_file): + raise SkipTest('nef file not downlaoded') + + # downloading for each test is costly so we save it in the working directory + file_path_save_as = helper.get_file_path('photo.nef') + if os.path.isfile(photo_file): + shutil.copyfile(photo_file, file_path_save_as) + + shutil.copyfile(photo_file, origin) + + photo = Photo(origin) + metadata = photo.get_metadata() + + shutil.rmtree(folder) + + assert metadata['date_taken'] == helper.time_convert((2008, 10, 24, 9, 12, 56, 4, 298, 0)), metadata['date_taken'] + +def test_set_metadata_on_nef(): + temporary_folder, folder = helper.create_working_folder() + + photo_file = helper.get_file('photo.nef') + origin = '%s/photo.nef' % folder + + if not photo_file: + photo_file = helper.download_file('photo.nef', folder) + if not photo_file or not os.path.isfile(photo_file): + raise SkipTest('nef file not downlaoded') + + shutil.copyfile(photo_file, origin) + + photo = Photo(origin) + origin_metadata = photo.get_metadata() + + status = photo.set_location(11.1111111111, 99.9999999999) + + assert status == True, status + + photo_new = Photo(origin) + metadata = photo_new.get_metadata() + + shutil.rmtree(folder) + + assert metadata['date_taken'] == helper.time_convert((2008, 10, 24, 9, 12, 56, 4, 298, 0)), metadata['date_taken'] + assert helper.isclose(metadata['latitude'], 11.1111111111), metadata['latitude'] + assert helper.isclose(metadata['longitude'], 99.9999999999), metadata['longitude'] + +def test_get_metadata_from_dng(): + temporary_folder, folder = helper.create_working_folder() + + photo_file = helper.get_file('photo.dng') + origin = '%s/photo.dng' % folder + + if not photo_file: + photo_file = helper.download_file('photo.dng', folder) + if not photo_file or not os.path.isfile(photo_file): + raise SkipTest('dng file not downlaoded') + + # downloading for each test is costly so we save it in the working directory + file_path_save_as = helper.get_file_path('photo.dng') + if os.path.isfile(photo_file): + shutil.copyfile(photo_file, file_path_save_as) + + shutil.copyfile(photo_file, origin) + + photo = Photo(origin) + metadata = photo.get_metadata() + + shutil.rmtree(folder) + + assert metadata['date_taken'] == helper.time_convert((2009, 10, 20, 9, 10, 46, 1, 293, 0)), metadata['date_taken'] + +def test_set_metadata_on_dng(): + temporary_folder, folder = helper.create_working_folder() + + photo_file = helper.get_file('photo.dng') + origin = '%s/photo.dng' % folder + + if not photo_file: + photo_file = helper.download_file('photo.dng', folder) + if not photo_file or not os.path.isfile(photo_file): + raise SkipTest('dng file not downlaoded') + + shutil.copyfile(photo_file, origin) + + photo = Photo(origin) + origin_metadata = photo.get_metadata() + + status = photo.set_location(11.1111111111, 99.9999999999) + + assert status == True, status + + photo_new = Photo(origin) + metadata = photo_new.get_metadata() + + shutil.rmtree(folder) + + assert metadata['date_taken'] == helper.time_convert((2009, 10, 20, 9, 10, 46, 1, 293, 0)), metadata['date_taken'] + assert helper.isclose(metadata['latitude'], 11.1111111111), metadata['latitude'] + assert helper.isclose(metadata['longitude'], 99.9999999999), metadata['longitude']