diff --git a/elodie/filesystem.py b/elodie/filesystem.py index 9577e38..fcbff06 100644 --- a/elodie/filesystem.py +++ b/elodie/filesystem.py @@ -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 diff --git a/elodie/tests/files/with-filename-and-title-in-exif.jpg b/elodie/tests/files/with-filename-and-title-in-exif.jpg new file mode 100644 index 0000000..75627e0 Binary files /dev/null and b/elodie/tests/files/with-filename-and-title-in-exif.jpg differ diff --git a/elodie/tests/files/with-filename-in-exif.jpg b/elodie/tests/files/with-filename-in-exif.jpg new file mode 100644 index 0000000..fe09b51 Binary files /dev/null and b/elodie/tests/files/with-filename-in-exif.jpg differ diff --git a/elodie/tests/filesystem_test.py b/elodie/tests/filesystem_test.py index 29ed007..93d66fa 100644 --- a/elodie/tests/filesystem_test.py +++ b/elodie/tests/filesystem_test.py @@ -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'))