jim-easterbrook / Photini

An easy to use digital photograph metadata (Exif, IPTC, XMP) editing application.
https://photini.readthedocs.io/
GNU General Public License v3.0
163 stars 24 forks source link

Error when Date/Time Original is empty #47

Closed aseques closed 5 years ago

aseques commented 5 years ago

I was tagging some pictures taken a time ago, and found out these errors on a picture, I attached the output of exiftool in case it's interesting for you info.txt The image it's missing the Date/Time Original in exiv information, but it does have a modify time, I don't know if it's something related to this manufacture (other pictures from same camera don't have the same issue strangely)

23:11:21: ERROR: photini.exiv2: P1010061.JPG(date_taken), Exif.Photo.DateTimeOriginal: time data '0000:00:00 00:00:00' does not match format '%Y:%m:%d %H:%M:%S' 23:11:21: ERROR: photini.exiv2: P1010061.JPG(date_taken), Exif.Image.DateTimeOriginal: time data '0000:00:00 00:00:00' does not match format '%Y:%m:%d %H:%M:%S' 23:11:21: ERROR: photini.exiv2: P1010061.JPG(date_digitised), Exif.Photo.DateTimeDigitized: time data '0000:00:00 00:00:00' does not match format '%Y:%m:%d %H:%M:%S' 23:11:21: ERROR: photini.exiv2: P1010144.JPG(date_taken), Exif.Photo.DateTimeOriginal: time data '0000:00:00 00:00:00' does not match format '%Y:%m:%d %H:%M:%S' 23:11:21: ERROR: photini.exiv2: P1010144.JPG(date_taken), Exif.Image.DateTimeOriginal: time data '0000:00:00 00:00:00' does not match format '%Y:%m:%d %H:%M:%S' 23:11:21: ERROR: photini.exiv2: P1010144.JPG(date_digitised), Exif.Photo.DateTimeDigitized: time data '0000:00:00 00:00:00' does not match format '%Y:%m:%d %H:%M:%S'

Feel free to close if it's the expected behaviour.

jim-easterbrook commented 5 years ago

As the exiftool output shows, the original date/time is set to all zeros, which is not a valid value (day and month can't be less than 1). The "does not match format" message is misleading in this case, but I think that's direct from the Python datetime module. Photini reported the error and didn't crash, so I'm not sure there's much more it could do.

aseques commented 5 years ago

Yeah, I just wanted to let you know the behavior in this case, I fixed the image from photini itself easily

jim-easterbrook commented 5 years ago

Thanks. It's surprising how many ways photo metadata can be messed up. I think the best thing to do is leave it to the user to correct, rather than try any guesswork. One of my colleagues, many years ago, often raged against "machines that think they know best". I bear this in mind, along with Postel's law, when I write software.

aseques commented 5 years ago

Totally agree, thanks

jim-easterbrook commented 5 years ago

Interestingly Python gives a different message when only the year is out of range:

>>> datetime.strptime('0001:01:01 00:00:00', '%Y:%m:%d %H:%M:%S')
datetime.datetime(1, 1, 1, 0, 0)
>>> datetime.strptime('0001:01:00 00:00:00', '%Y:%m:%d %H:%M:%S')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib64/python3.6/_strptime.py", line 565, in _strptime_datetime
    tt, fraction = _strptime(data_string, format)
  File "/usr/lib64/python3.6/_strptime.py", line 362, in _strptime
    (data_string, format))
ValueError: time data '0001:01:00 00:00:00' does not match format '%Y:%m:%d %H:%M:%S'
>>> datetime.strptime('0000:01:01 00:00:00', '%Y:%m:%d %H:%M:%S')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib64/python3.6/_strptime.py", line 565, in _strptime_datetime
    tt, fraction = _strptime(data_string, format)
  File "/usr/lib64/python3.6/_strptime.py", line 528, in _strptime
    datetime_date(year, 1, 1).toordinal() + 1
ValueError: year 0 is out of range
jim-easterbrook commented 5 years ago

I've checked the Exif standard (v 2.2) and it doesn't mention all-zero DateTimes. It does allow all the numbers to be replaced by spaces to indicate a missing value. If using all zeros is commonly done then Photini ought to accept it.

jim-easterbrook commented 5 years ago

A bit of web searching suggests this is quite common, so commit 62d98a9 should make Photini accept all-zeros as a None value.