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,18 +111,24 @@ class FileSystem(object):
if(metadata is None):
return None
# If the file has EXIF title we use that in the file name
# (i.e. my-favorite-photo-img_1234.jpg)
# We want to remove the date prefix we add to the name.
# This helps when re-running the program on file which were already
# processed.
base_name = re.sub(
'^\d{4}-\d{2}-\d{2}_\d{2}-\d{2}-\d{2}-',
'',
metadata['base_name']
)
if(len(base_name) == 0):
base_name = metadata['base_name']
# 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
# (i.e. my-favorite-photo-img_1234.jpg)
# We want to remove the date prefix we add to the name.
# This helps when re-running the program on file which were already
# processed.
base_name = re.sub(
'^\d{4}-\d{2}-\d{2}_\d{2}-\d{2}-\d{2}-',
'',
metadata['base_name']
)
if(len(base_name) == 0):
base_name = metadata['base_name']
if(
'title' in metadata and

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
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():
filesystem = FileSystem()
media = Photo(helper.get_file('plain.jpg'))