Updated --exiftool to set dates/times as Photos does, issue #247
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
""" version info """
|
""" version info """
|
||||||
|
|
||||||
__version__ = "0.36.3"
|
__version__ = "0.36.4"
|
||||||
|
|
||||||
|
|||||||
@@ -1137,19 +1137,38 @@ def _exiftool_json_sidecar(
|
|||||||
exif["EXIF:GPSLongitudeRef"] = lon_ref
|
exif["EXIF:GPSLongitudeRef"] = lon_ref
|
||||||
|
|
||||||
# process date/time and timezone offset
|
# process date/time and timezone offset
|
||||||
|
# Photos exports the following fields and sets modify date to creation date
|
||||||
|
# [EXIF] Modify Date : 2020:10:30 00:00:00
|
||||||
|
# [EXIF] Date/Time Original : 2020:10:30 00:00:00
|
||||||
|
# [EXIF] Create Date : 2020:10:30 00:00:00
|
||||||
|
# [IPTC] Digital Creation Date : 2020:10:30
|
||||||
|
# [IPTC] Date Created : 2020:10:30
|
||||||
|
#
|
||||||
|
# This code deviates from Photos in one regard:
|
||||||
|
# if photo has modification date, use it otherwise use creation date
|
||||||
date = self.date
|
date = self.date
|
||||||
|
|
||||||
# exiftool expects format to "2015:01:18 12:00:00"
|
# exiftool expects format to "2015:01:18 12:00:00"
|
||||||
datetimeoriginal = date.strftime("%Y:%m:%d %H:%M:%S")
|
datetimeoriginal = date.strftime("%Y:%m:%d %H:%M:%S")
|
||||||
|
exif["EXIF:DateTimeOriginal"] = datetimeoriginal
|
||||||
|
exif["EXIF:CreateDate"] = datetimeoriginal
|
||||||
|
|
||||||
offsettime = date.strftime("%z")
|
offsettime = date.strftime("%z")
|
||||||
# find timezone offset in format "-04:00"
|
# find timezone offset in format "-04:00"
|
||||||
offset = re.findall(r"([+-]?)([\d]{2})([\d]{2})", offsettime)
|
offset = re.findall(r"([+-]?)([\d]{2})([\d]{2})", offsettime)
|
||||||
offset = offset[0] # findall returns list of tuples
|
offset = offset[0] # findall returns list of tuples
|
||||||
offsettime = f"{offset[0]}{offset[1]}:{offset[2]}"
|
offsettime = f"{offset[0]}{offset[1]}:{offset[2]}"
|
||||||
exif["EXIF:DateTimeOriginal"] = datetimeoriginal
|
|
||||||
exif["EXIF:OffsetTimeOriginal"] = offsettime
|
exif["EXIF:OffsetTimeOriginal"] = offsettime
|
||||||
|
|
||||||
|
dateoriginal = date.strftime("%Y:%m:%d")
|
||||||
|
exif["IPTC:DigitalCreationDate"] = dateoriginal
|
||||||
|
exif["IPTC:DateCreated"] = dateoriginal
|
||||||
|
|
||||||
if self.date_modified is not None:
|
if self.date_modified is not None:
|
||||||
exif["EXIF:ModifyDate"] = self.date_modified.strftime("%Y:%m:%d %H:%M:%S")
|
exif["EXIF:ModifyDate"] = self.date_modified.strftime("%Y:%m:%d %H:%M:%S")
|
||||||
|
else:
|
||||||
|
exif["EXIF:ModifyDate"] = self.date.strftime("%Y:%m:%d %H:%M:%S")
|
||||||
|
|
||||||
|
|
||||||
json_str = json.dumps([exif])
|
json_str = json.dumps([exif])
|
||||||
return json_str
|
return json_str
|
||||||
|
|||||||
@@ -2632,16 +2632,21 @@ def test_export_sidecar_keyword_template():
|
|||||||
|
|
||||||
json_expected = json.loads(
|
json_expected = json.loads(
|
||||||
"""
|
"""
|
||||||
[{"_CreatedBy": "osxphotos, https://github.com/RhetTbull/osxphotos",
|
[{"_CreatedBy": "osxphotos, https://github.com/RhetTbull/osxphotos",
|
||||||
"EXIF:ImageDescription": "Girl holding pumpkin",
|
"EXIF:ImageDescription": "Girl holding pumpkin",
|
||||||
"XMP:Description": "Girl holding pumpkin",
|
"XMP:Description": "Girl holding pumpkin",
|
||||||
"XMP:Title": "I found one!",
|
"XMP:Title": "I found one!",
|
||||||
"XMP:TagsList": ["Kids", "Multi Keyword", "Test Album", "Pumpkin Farm"],
|
"XMP:TagsList": ["Kids", "Multi Keyword", "Pumpkin Farm", "Test Album"],
|
||||||
"IPTC:Keywords": ["Kids", "Multi Keyword", "Test Album", "Pumpkin Farm"],
|
"IPTC:Keywords": ["Kids", "Multi Keyword", "Pumpkin Farm", "Test Album"],
|
||||||
"XMP:PersonInImage": ["Katie"],
|
"XMP:PersonInImage": ["Katie"],
|
||||||
"XMP:Subject": ["Kids", "Katie"],
|
"XMP:Subject": ["Kids", "Katie"],
|
||||||
"EXIF:DateTimeOriginal": "2018:09:28 16:07:07",
|
"EXIF:DateTimeOriginal": "2018:09:28 16:07:07",
|
||||||
"EXIF:OffsetTimeOriginal": "-04:00"}]"""
|
"EXIF:CreateDate": "2018:09:28 16:07:07",
|
||||||
|
"EXIF:OffsetTimeOriginal": "-04:00",
|
||||||
|
"IPTC:DigitalCreationDate": "2018:09:28",
|
||||||
|
"IPTC:DateCreated": "2018:09:28",
|
||||||
|
"EXIF:ModifyDate": "2018:09:28 16:07:07"}]
|
||||||
|
"""
|
||||||
)[0]
|
)[0]
|
||||||
|
|
||||||
with open("Pumkins2.jpg.json", "r") as json_file:
|
with open("Pumkins2.jpg.json", "r") as json_file:
|
||||||
|
|||||||
@@ -67,18 +67,21 @@ XMP_FILENAME = "Pumkins1.jpg.xmp"
|
|||||||
XMP_JPG_FILENAME = "Pumkins1.jpg"
|
XMP_JPG_FILENAME = "Pumkins1.jpg"
|
||||||
|
|
||||||
EXIF_JSON_UUID = UUID_DICT["has_adjustments"]
|
EXIF_JSON_UUID = UUID_DICT["has_adjustments"]
|
||||||
EXIF_JSON_EXPECTED = (
|
EXIF_JSON_EXPECTED = """
|
||||||
'[{"_CreatedBy": "osxphotos, https://github.com/RhetTbull/osxphotos", '
|
[{"_CreatedBy": "osxphotos, https://github.com/RhetTbull/osxphotos",
|
||||||
'"EXIF:ImageDescription": "Bride Wedding day", '
|
"EXIF:ImageDescription": "Bride Wedding day",
|
||||||
'"XMP:Description": "Bride Wedding day", '
|
"XMP:Description": "Bride Wedding day",
|
||||||
'"XMP:TagsList": ["wedding"], '
|
"XMP:TagsList": ["wedding"],
|
||||||
'"IPTC:Keywords": ["wedding"], '
|
"IPTC:Keywords": ["wedding"],
|
||||||
'"XMP:PersonInImage": ["Maria"], '
|
"XMP:PersonInImage": ["Maria"],
|
||||||
'"XMP:Subject": ["wedding", "Maria"], '
|
"XMP:Subject": ["wedding", "Maria"],
|
||||||
'"EXIF:DateTimeOriginal": "2019:04:15 14:40:24", '
|
"EXIF:DateTimeOriginal": "2019:04:15 14:40:24",
|
||||||
'"EXIF:OffsetTimeOriginal": "-04:00", '
|
"EXIF:CreateDate": "2019:04:15 14:40:24",
|
||||||
'"EXIF:ModifyDate": "2019:07:27 17:33:28"}]'
|
"EXIF:OffsetTimeOriginal": "-04:00",
|
||||||
)
|
"IPTC:DigitalCreationDate": "2019:04:15",
|
||||||
|
"IPTC:DateCreated": "2019:04:15",
|
||||||
|
"EXIF:ModifyDate": "2019:07:27 17:33:28"}]
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
def test_export_1():
|
def test_export_1():
|
||||||
@@ -507,7 +510,10 @@ def test_exiftool_json_sidecar_keyword_template_long(caplog):
|
|||||||
"XMP:PersonInImage": ["Maria"],
|
"XMP:PersonInImage": ["Maria"],
|
||||||
"XMP:Subject": ["wedding", "Maria"],
|
"XMP:Subject": ["wedding", "Maria"],
|
||||||
"EXIF:DateTimeOriginal": "2019:04:15 14:40:24",
|
"EXIF:DateTimeOriginal": "2019:04:15 14:40:24",
|
||||||
|
"EXIF:CreateDate": "2019:04:15 14:40:24",
|
||||||
"EXIF:OffsetTimeOriginal": "-04:00",
|
"EXIF:OffsetTimeOriginal": "-04:00",
|
||||||
|
"IPTC:DigitalCreationDate": "2019:04:15",
|
||||||
|
"IPTC:DateCreated": "2019:04:15",
|
||||||
"EXIF:ModifyDate": "2019:07:27 17:33:28"}]
|
"EXIF:ModifyDate": "2019:07:27 17:33:28"}]
|
||||||
"""
|
"""
|
||||||
)[0]
|
)[0]
|
||||||
@@ -554,7 +560,10 @@ def test_exiftool_json_sidecar_keyword_template():
|
|||||||
"XMP:PersonInImage": ["Maria"],
|
"XMP:PersonInImage": ["Maria"],
|
||||||
"XMP:Subject": ["wedding", "Maria"],
|
"XMP:Subject": ["wedding", "Maria"],
|
||||||
"EXIF:DateTimeOriginal": "2019:04:15 14:40:24",
|
"EXIF:DateTimeOriginal": "2019:04:15 14:40:24",
|
||||||
|
"EXIF:CreateDate": "2019:04:15 14:40:24",
|
||||||
"EXIF:OffsetTimeOriginal": "-04:00",
|
"EXIF:OffsetTimeOriginal": "-04:00",
|
||||||
|
"IPTC:DigitalCreationDate": "2019:04:15",
|
||||||
|
"IPTC:DateCreated": "2019:04:15",
|
||||||
"EXIF:ModifyDate": "2019:07:27 17:33:28"}]
|
"EXIF:ModifyDate": "2019:07:27 17:33:28"}]
|
||||||
"""
|
"""
|
||||||
)[0]
|
)[0]
|
||||||
@@ -613,7 +622,11 @@ def test_exiftool_json_sidecar_use_persons_keyword():
|
|||||||
"XMP:PersonInImage": ["Suzy", "Katie"],
|
"XMP:PersonInImage": ["Suzy", "Katie"],
|
||||||
"XMP:Subject": ["Kids", "Suzy", "Katie"],
|
"XMP:Subject": ["Kids", "Suzy", "Katie"],
|
||||||
"EXIF:DateTimeOriginal": "2018:09:28 15:35:49",
|
"EXIF:DateTimeOriginal": "2018:09:28 15:35:49",
|
||||||
"EXIF:OffsetTimeOriginal": "-04:00"}]
|
"EXIF:CreateDate": "2018:09:28 15:35:49",
|
||||||
|
"EXIF:OffsetTimeOriginal": "-04:00",
|
||||||
|
"IPTC:DigitalCreationDate": "2018:09:28",
|
||||||
|
"IPTC:DateCreated": "2018:09:28",
|
||||||
|
"EXIF:ModifyDate": "2018:09:28 15:35:49"}]
|
||||||
"""
|
"""
|
||||||
)[0]
|
)[0]
|
||||||
|
|
||||||
@@ -652,7 +665,11 @@ def test_exiftool_json_sidecar_use_albums_keyword():
|
|||||||
"XMP:PersonInImage": ["Suzy", "Katie"],
|
"XMP:PersonInImage": ["Suzy", "Katie"],
|
||||||
"XMP:Subject": ["Kids", "Suzy", "Katie"],
|
"XMP:Subject": ["Kids", "Suzy", "Katie"],
|
||||||
"EXIF:DateTimeOriginal": "2018:09:28 15:35:49",
|
"EXIF:DateTimeOriginal": "2018:09:28 15:35:49",
|
||||||
"EXIF:OffsetTimeOriginal": "-04:00"}]
|
"EXIF:CreateDate": "2018:09:28 15:35:49",
|
||||||
|
"EXIF:OffsetTimeOriginal": "-04:00",
|
||||||
|
"IPTC:DigitalCreationDate": "2018:09:28",
|
||||||
|
"IPTC:DateCreated": "2018:09:28",
|
||||||
|
"EXIF:ModifyDate": "2018:09:28 15:35:49"}]
|
||||||
"""
|
"""
|
||||||
)[0]
|
)[0]
|
||||||
|
|
||||||
|
|||||||
@@ -45,17 +45,23 @@ UUID_DICT = {
|
|||||||
"xmp": "8SOE9s0XQVGsuq4ONohTng",
|
"xmp": "8SOE9s0XQVGsuq4ONohTng",
|
||||||
}
|
}
|
||||||
|
|
||||||
EXIF_JSON_EXPECTED = (
|
EXIF_JSON_EXPECTED = """
|
||||||
'[{"_CreatedBy": "osxphotos, https://github.com/RhetTbull/osxphotos", '
|
[{"_CreatedBy": "osxphotos, https://github.com/RhetTbull/osxphotos",
|
||||||
'"XMP:Title": "St. James\'s Park", "XMP:TagsList": ["UK", "England", '
|
"XMP:Title": "St. James\'s Park",
|
||||||
'"London", "United Kingdom", "London 2018", "St. James\'s Park"], '
|
"XMP:TagsList": ["UK", "England", "London", "United Kingdom", "London 2018", "St. James\'s Park"],
|
||||||
'"IPTC:Keywords": ["UK", "England", "London", "United Kingdom", "London 2018", '
|
"IPTC:Keywords": ["UK", "England", "London", "United Kingdom", "London 2018", "St. James\'s Park"],
|
||||||
'"St. James\'s Park"], "XMP:Subject": ["UK", "England", "London", "United Kingdom", '
|
"XMP:Subject": ["UK", "England", "London", "United Kingdom", "London 2018", "St. James\'s Park"],
|
||||||
'"London 2018", "St. James\'s Park"], "EXIF:GPSLatitude": 51.50357167, '
|
"EXIF:GPSLatitude": 51.50357167,
|
||||||
'"EXIF:GPSLongitude": -0.1318055, "EXIF:GPSLatitudeRef": "N", '
|
"EXIF:GPSLongitude": -0.1318055,
|
||||||
'"EXIF:GPSLongitudeRef": "W", "EXIF:DateTimeOriginal": "2018:10:13 09:18:12", '
|
"EXIF:GPSLatitudeRef": "N",
|
||||||
'"EXIF:OffsetTimeOriginal": "-04:00", "EXIF:ModifyDate": "2019:12:01 11:43:45"}]'
|
"EXIF:GPSLongitudeRef": "W",
|
||||||
)
|
"EXIF:DateTimeOriginal": "2018:10:13 09:18:12",
|
||||||
|
"EXIF:CreateDate": "2018:10:13 09:18:12",
|
||||||
|
"EXIF:OffsetTimeOriginal": "-04:00",
|
||||||
|
"IPTC:DigitalCreationDate": "2018:10:13",
|
||||||
|
"IPTC:DateCreated": "2018:10:13",
|
||||||
|
"EXIF:ModifyDate": "2019:12:01 11:43:45"}]
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
def test_export_1():
|
def test_export_1():
|
||||||
|
|||||||
Reference in New Issue
Block a user