Use original name from EXIF instead of parsing assumed file name format. #107 (#202)

This commit is contained in:
Jaisen Mathai 2017-03-16 23:43:47 -07:00 committed by GitHub
parent 31db4e661a
commit f7be8f323f
4 changed files with 32 additions and 12 deletions

View File

@ -111,6 +111,12 @@ class FileSystem(object):
if(metadata is None): if(metadata is None):
return None return None
# First we check if we have metadata['original_name'].
# We have to do this for backwards compatibility because
# we original did not store this back into EXIF.
if(metadata['original_name'] is not None):
base_name = os.path.splitext(metadata['original_name'])[0]
else:
# If the file has EXIF title we use that in the file name # If the file has EXIF title we use that in the file name
# (i.e. my-favorite-photo-img_1234.jpg) # (i.e. my-favorite-photo-img_1234.jpg)
# We want to remove the date prefix we add to the name. # We want to remove the date prefix we add to the name.

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

View File

@ -191,6 +191,20 @@ def test_get_file_name_with_title():
assert file_name == helper.path_tz_fix('2015-12-05_00-59-26-with-title-some-title.jpg'), file_name assert file_name == helper.path_tz_fix('2015-12-05_00-59-26-with-title-some-title.jpg'), file_name
def test_get_file_name_with_original_name_exif():
filesystem = FileSystem()
media = Photo(helper.get_file('with-filename-in-exif.jpg'))
file_name = filesystem.get_file_name(media)
assert file_name == helper.path_tz_fix('2015-12-05_00-59-26-foobar.jpg'), file_name
def test_get_file_name_with_original_name_title_exif():
filesystem = FileSystem()
media = Photo(helper.get_file('with-filename-and-title-in-exif.jpg'))
file_name = filesystem.get_file_name(media)
assert file_name == helper.path_tz_fix('2015-12-05_00-59-26-foobar-foobar-title.jpg'), file_name
def test_get_folder_path_plain(): def test_get_folder_path_plain():
filesystem = FileSystem() filesystem = FileSystem()
media = Photo(helper.get_file('plain.jpg')) media = Photo(helper.get_file('plain.jpg'))