Closed ghost closed 6 years ago
Can you send me an example file? (The smaller, the better.) Do you know if Lightroom is ignoring the malformed date or interpreting it correctly?
Sample file:
Lightroom shows Jul 1, 2002 as capture date, and 12:00:00AM for time.
Traceback (most recent call last):
File "/Users/boser/Dropbox/Files/Coding/AlbumOrganizer/.direnv/python-3.6.5/lib/python3.6/site-packages/photini/metadata.py", line 1406, in __getattr__
new_value = self._data_type[name].read(handler, tag)
File "/Users/boser/Dropbox/Files/Coding/AlbumOrganizer/.direnv/python-3.6.5/lib/python3.6/site-packages/photini/metadata.py", line 493, in read
return cls.from_exif(file_value)
File "/Users/boser/Dropbox/Files/Coding/AlbumOrganizer/.direnv/python-3.6.5/lib/python3.6/site-packages/photini/metadata.py", line 529, in from_exif
return cls.from_ISO_8601(date_string, time_string, '')
File "/Users/boser/Dropbox/Files/Coding/AlbumOrganizer/.direnv/python-3.6.5/lib/python3.6/site-packages/photini/metadata.py", line 460, in from_ISO_8601
(datetime.strptime(datetime_string, fmt), precision, tz_offset))
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/_strptime.py", line 565, in _strptime_datetime
tt, fraction = _strptime(data_string, format)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/_strptime.py", line 362, in _strptime
(data_string, format))
ValueError: time data '200207 ' does not match format '%Y%m%d%H%M%S'
I cannot make the image smaller: exporting with Lightroom "fixes" the problem: this example produces no error, and shows 2002-07
as date taken.
Perhaps as simple as changing the 7
in this line (did not try):
precision = min((len(datetime_string) - 2) // 2, 7)
Thanks for the example. I see the problem, I think. A load of spaces after the date. I'll investigate further but it should be easy to fix.
exiv2 -pa file_name
shows the error: Exif.Photo.DateTimeOriginal Ascii 20 2002:07: : :
. I'm pretty sure that's not compliant, but (according to Postel's law) Photini ought to accept it. Commit 9c84937 should fix it.
I may be wrong about it being non-compliant. From the Exif spec:
When the date and time are unknown, all the character spaces except colons (":") should be filled with blank characters.
That "all" suggests partial dates aren't allowed though.
An interesting read: http://www.johnrellis.com/psedbtool/photoshop-elements-faq.htm#Unknown_month_day_and_time
Photini writes full precision Exif datetimes, using "0000:01:01 00:00:00" to pad low precision values. On reading, time values of "00:00:00" are assumed to be None - bad luck for photos taken at midnight. XMP values are written with the correct precision and over-rule Exif on reading.
That's probably it: before Lightroom I used PSE, and that's presumably where these invalid values come from. Just IMHO the PSE "non-standard" seems more sensical to me; "00:00:00" is not the same as "unknown", and leads to problems, as you already point out.
Thanks for the fix! Will you push a new version to pypi?
(And at least one version of Lightroom had problems with the partial dates written by PSE.)
I'm planning to do a new release soon, if no more bugs are found. (But don't stop looking for bugs.)
Version 2018.5.0 has now been released and is available from PyPI.
metadata.py from_ISO_8601 raises ValueError for dates not conforming to ISO format. I have several of these, such as the one reported in the above error which only has a year and month.
Not sure these dates are exif conform, but e.g. Lightroom (which I am trying to replace with a more customizable flow) has no issue.