Fix for long descriptions with exiftool, #393

This commit is contained in:
Rhet Turnbull 2021-03-14 08:38:07 -07:00
parent 595307a003
commit ffb9af1965
45 changed files with 54 additions and 24 deletions

View File

@ -1,3 +1,3 @@
""" version info """ """ version info """
__version__ = "0.41.1" __version__ = "0.41.2"

View File

@ -176,6 +176,10 @@ class ExifTool:
command = [f"-{tag}={value}"] command = [f"-{tag}={value}"]
if self.overwrite and not self._context_mgr: if self.overwrite and not self._context_mgr:
command.append("-overwrite_original") command.append("-overwrite_original")
# avoid "Warning: Some character(s) could not be encoded in Latin" warning
command.append("-iptc:codedcharacterset=utf8")
if self._context_mgr: if self._context_mgr:
self._commands.extend(command) self._commands.extend(command)
return True return True

View File

@ -949,7 +949,7 @@ def export2(
filename=dest.name, filename=dest.name,
persons=persons, persons=persons,
location=location, location=location,
replace_keywords=replace_keywords replace_keywords=replace_keywords,
) )
sidecars.append( sidecars.append(
( (
@ -975,7 +975,7 @@ def export2(
filename=dest.name, filename=dest.name,
persons=persons, persons=persons,
location=location, location=location,
replace_keywords=replace_keywords replace_keywords=replace_keywords,
) )
sidecars.append( sidecars.append(
( (
@ -997,7 +997,7 @@ def export2(
extension=dest.suffix[1:] if dest.suffix else None, extension=dest.suffix[1:] if dest.suffix else None,
persons=persons, persons=persons,
location=location, location=location,
replace_keywords=replace_keywords replace_keywords=replace_keywords,
) )
sidecars.append( sidecars.append(
( (
@ -1067,7 +1067,7 @@ def export2(
merge_exif_persons=merge_exif_persons, merge_exif_persons=merge_exif_persons,
persons=persons, persons=persons,
location=location, location=location,
replace_keywords=replace_keywords replace_keywords=replace_keywords,
) )
)[0] )[0]
if old_data != current_data: if old_data != current_data:
@ -1090,7 +1090,7 @@ def export2(
merge_exif_persons=merge_exif_persons, merge_exif_persons=merge_exif_persons,
persons=persons, persons=persons,
location=location, location=location,
replace_keywords=replace_keywords replace_keywords=replace_keywords,
) )
if warning_: if warning_:
all_results.exiftool_warning.append((exported_file, warning_)) all_results.exiftool_warning.append((exported_file, warning_))
@ -1110,7 +1110,7 @@ def export2(
merge_exif_persons=merge_exif_persons, merge_exif_persons=merge_exif_persons,
persons=persons, persons=persons,
location=location, location=location,
replace_keywords=replace_keywords replace_keywords=replace_keywords,
), ),
) )
export_db.set_stat_exif_for_file( export_db.set_stat_exif_for_file(
@ -1135,7 +1135,7 @@ def export2(
merge_exif_persons=merge_exif_persons, merge_exif_persons=merge_exif_persons,
persons=persons, persons=persons,
location=location, location=location,
replace_keywords=replace_keywords replace_keywords=replace_keywords,
) )
if warning_: if warning_:
all_results.exiftool_warning.append((exported_file, warning_)) all_results.exiftool_warning.append((exported_file, warning_))
@ -1155,7 +1155,7 @@ def export2(
merge_exif_persons=merge_exif_persons, merge_exif_persons=merge_exif_persons,
persons=persons, persons=persons,
location=location, location=location,
replace_keywords=replace_keywords replace_keywords=replace_keywords,
), ),
) )
export_db.set_stat_exif_for_file( export_db.set_stat_exif_for_file(
@ -1646,6 +1646,13 @@ def _exiftool_dict(
exif["QuickTime:ModifyDate"] = datetime_tz_to_utc( exif["QuickTime:ModifyDate"] = datetime_tz_to_utc(
self.date_modified self.date_modified
).strftime("%Y:%m:%d %H:%M:%S") ).strftime("%Y:%m:%d %H:%M:%S")
# remove any new lines in any fields
for field, val in exif.items():
if type(val) == str:
exif[field] = val.replace("\n", " ")
elif type(val) == list:
exif[field] = [v.replace("\n", " ") for v in val]
return exif return exif

Binary file not shown.

Before

Width:  |  Height:  |  Size: 528 KiB

After

Width:  |  Height:  |  Size: 528 KiB

View File

@ -7,7 +7,7 @@
<key>hostuuid</key> <key>hostuuid</key>
<string>9575E48B-8D5F-5654-ABAC-4431B1167324</string> <string>9575E48B-8D5F-5654-ABAC-4431B1167324</string>
<key>pid</key> <key>pid</key>
<integer>55247</integer> <integer>86501</integer>
<key>processname</key> <key>processname</key>
<string>photolibraryd</string> <string>photolibraryd</string>
<key>uid</key> <key>uid</key>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 577 KiB

After

Width:  |  Height:  |  Size: 577 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 MiB

View File

@ -3,24 +3,24 @@
<plist version="1.0"> <plist version="1.0">
<dict> <dict>
<key>BackgroundHighlightCollection</key> <key>BackgroundHighlightCollection</key>
<date>2020-12-16T05:41:43Z</date> <date>2021-03-13T16:38:25Z</date>
<key>BackgroundHighlightEnrichment</key> <key>BackgroundHighlightEnrichment</key>
<date>2020-12-16T05:41:42Z</date> <date>2021-03-13T16:38:24Z</date>
<key>BackgroundJobAssetRevGeocode</key> <key>BackgroundJobAssetRevGeocode</key>
<date>2020-12-16T05:41:43Z</date> <date>2021-03-13T16:38:25Z</date>
<key>BackgroundJobSearch</key> <key>BackgroundJobSearch</key>
<date>2020-12-16T05:41:43Z</date> <date>2021-03-13T16:38:25Z</date>
<key>BackgroundPeopleSuggestion</key> <key>BackgroundPeopleSuggestion</key>
<date>2020-12-16T05:41:41Z</date> <date>2021-03-13T16:38:23Z</date>
<key>BackgroundUserBehaviorProcessor</key> <key>BackgroundUserBehaviorProcessor</key>
<date>2020-12-16T05:41:43Z</date> <date>2021-03-13T16:38:25Z</date>
<key>PhotoAnalysisGraphLastBackgroundGraphConsistencyUpdateJobDateKey</key> <key>PhotoAnalysisGraphLastBackgroundGraphConsistencyUpdateJobDateKey</key>
<date>2020-10-17T23:45:33Z</date> <date>2020-10-17T23:45:33Z</date>
<key>PhotoAnalysisGraphLastBackgroundGraphRebuildJobDate</key> <key>PhotoAnalysisGraphLastBackgroundGraphRebuildJobDate</key>
<date>2020-10-17T23:45:24Z</date> <date>2020-10-17T23:45:24Z</date>
<key>PhotoAnalysisGraphLastBackgroundMemoryGenerationJobDate</key> <key>PhotoAnalysisGraphLastBackgroundMemoryGenerationJobDate</key>
<date>2020-12-16T05:41:44Z</date> <date>2021-03-13T16:38:25Z</date>
<key>SiriPortraitDonation</key> <key>SiriPortraitDonation</key>
<date>2020-12-16T05:41:43Z</date> <date>2021-03-13T16:38:25Z</date>
</dict> </dict>
</plist> </plist>

Binary file not shown.

After

Width:  |  Height:  |  Size: 144 KiB

File diff suppressed because one or more lines are too long

View File

@ -23,10 +23,10 @@ PHOTOS_DB = "tests/Test-10.15.7.photoslibrary/database/photos.db"
PHOTOS_DB_PATH = "/Test-10.15.7.photoslibrary/database/photos.db" PHOTOS_DB_PATH = "/Test-10.15.7.photoslibrary/database/photos.db"
PHOTOS_LIBRARY_PATH = "/Test-10.15.7.photoslibrary" PHOTOS_LIBRARY_PATH = "/Test-10.15.7.photoslibrary"
PHOTOS_DB_LEN = 19 PHOTOS_DB_LEN = 20
PHOTOS_NOT_IN_TRASH_LEN = 17 PHOTOS_NOT_IN_TRASH_LEN = 18
PHOTOS_IN_TRASH_LEN = 2 PHOTOS_IN_TRASH_LEN = 2
PHOTOS_DB_IMPORT_SESSIONS = 14 PHOTOS_DB_IMPORT_SESSIONS = 15
KEYWORDS = [ KEYWORDS = [
"Kids", "Kids",
@ -41,6 +41,10 @@ KEYWORDS = [
"foo/bar", "foo/bar",
"Travel", "Travel",
"Maria", "Maria",
"Drink",
"Val d'Isère",
"Wine",
"Wine Bottle",
] ]
# Photos 5 includes blank person for detected face # Photos 5 includes blank person for detected face
PERSONS = ["Katie", "Suzy", "Maria", _UNKNOWN_PERSON] PERSONS = ["Katie", "Suzy", "Maria", _UNKNOWN_PERSON]
@ -67,6 +71,10 @@ KEYWORDS_DICT = {
"foo/bar": 1, "foo/bar": 1,
"Travel": 2, "Travel": 2,
"Maria": 1, "Maria": 1,
"Drink": 1,
"Val d'Isère": 1,
"Wine": 1,
"Wine Bottle": 1,
} }
PERSONS_DICT = {"Katie": 3, "Suzy": 2, "Maria": 2, _UNKNOWN_PERSON: 1} PERSONS_DICT = {"Katie": 3, "Suzy": 2, "Maria": 2, _UNKNOWN_PERSON: 1}
ALBUM_DICT = { ALBUM_DICT = {
@ -102,6 +110,7 @@ UUID_DICT = {
"intrash_person_keywords": "6FD38366-3BF2-407D-81FE-7153EB6125B6", "intrash_person_keywords": "6FD38366-3BF2-407D-81FE-7153EB6125B6",
"import_session": "8846E3E6-8AC8-4857-8448-E3D025784410", "import_session": "8846E3E6-8AC8-4857-8448-E3D025784410",
"movie": "D1359D09-1373-4F3B-B0E3-1A4DE573E4A3", "movie": "D1359D09-1373-4F3B-B0E3-1A4DE573E4A3",
"description_newlines": "7F74DD34-5920-4DA3-B284-479887A34F66",
} }
UUID_DICT_LOCAL = { UUID_DICT_LOCAL = {
@ -1010,7 +1019,7 @@ def test_from_to_date(photosdb):
time.tzset() time.tzset()
photos = photosdb.photos(from_date=datetime.datetime(2018, 10, 28)) photos = photosdb.photos(from_date=datetime.datetime(2018, 10, 28))
assert len(photos) == 10 assert len(photos) == 11
photos = photosdb.photos(to_date=datetime.datetime(2018, 10, 28)) photos = photosdb.photos(to_date=datetime.datetime(2018, 10, 28))
assert len(photos) == 7 assert len(photos) == 7
@ -1265,4 +1274,13 @@ def test_no_adjustments(photosdb):
""" test adjustments when photo has no adjusments""" """ test adjustments when photo has no adjusments"""
photo = photosdb.get_photo(UUID_DICT["no_adjustments"]) photo = photosdb.get_photo(UUID_DICT["no_adjustments"])
assert photo.adjustments is None assert photo.adjustments is None
def test_exiftool_newlines_in_description(photosdb):
""" Test that exiftool code removes newlines embedded in description, issue #393"""
photo = photosdb.get_photo(UUID_DICT["description_newlines"])
exif = photo._exiftool_dict()
assert photo.description.find("\n") > 0
assert exif["EXIF:ImageDescription"].find("\n") == -1

View File

@ -611,6 +611,7 @@ UUID_NOT_IN_ALBUM = [
"6191423D-8DB8-4D4C-92BE-9BBBA308AAC4", "6191423D-8DB8-4D4C-92BE-9BBBA308AAC4",
"35329C57-B963-48D6-BB75-6AFF9370CBBC", "35329C57-B963-48D6-BB75-6AFF9370CBBC",
"8846E3E6-8AC8-4857-8448-E3D025784410", "8846E3E6-8AC8-4857-8448-E3D025784410",
"7F74DD34-5920-4DA3-B284-479887A34F66",
] ]