exiftool / exiftool

ExifTool meta information reader/writer
https://exiftool.org/
GNU General Public License v3.0
3.31k stars 329 forks source link

CLI vs API mismatch behaviour #293

Closed luipir closed 1 day ago

luipir commented 4 days ago

Describe the bug API behaviour (e.g. accepted parameter format) do not follow the same rule as CLI

To Reproduce probably my lack of knowledge of the use of the API. I'm updating tags in a Tiff (COG formatted) and most of tags are updated correctly but some are ignored: I did manually a test and this is the mismatch

In [10]: with ExifTool() as et:
    ...:     et.execute('-Exif:GPSLatitude="41 55 24"', "./notag_cog.tif")    <--- try to update the value via API
    ...: 

In [11]: !exiv2 -pt  notag_cog.tif| grep -i GPSLatitude
Warning: Directory Image3 has an unexpected next pointer; ignored.
Exif.GPSInfo.GPSLatitudeRef                  Ascii       2  North
Exif.GPSInfo.GPSLatitude                     Rational    3  40deg 54' 23"    <--- remain the old value

In [12]: !exiftool -Exif:GPSLatitude="41 55 24"  notag_cog.tif                <--- update it via CLI with same parameter as API
    1 image files updated

In [13]: !exiv2 -pt  notag_cog.tif| grep -i GPSLatitude
    ...: 
Warning: Directory Image3 has an unexpected next pointer; ignored.
Exif.GPSInfo.GPSLatitudeRef                  Ascii       2  North
Exif.GPSInfo.GPSLatitude                     Rational    3  41deg 55' 24"        <--- and via CLI it works

any hint? I tried to change from "41 55 24"" to "41deg 55min 24sec" but behaviour does not change.

p.s. sorry to use exiv2, just because allow me to write less parameters ;)

Expected behavior API and CLI would be fine to have the same syntax management

Desktop (please complete the following information): Ubuntu 24.04.1 LTS 0.27.6 (installed via apt)

luipir commented 4 days ago

ok, more debug

In [20]: with ExifTool() as et:
    ...:     et.execute(*['-Exif:GPSLatitude="41 55 23"', "./notag_cog.tif"])
    ...:     print(et.last_stderr)
    ...: 
Warning: Argument ""41 55 23"" isn't numeric in abs in GPS:GPSLatitude (ValueConvInv)
Nothing to do.
luipir commented 4 days ago

e.g. in this case I've to convert value in a float number! in fact this works

In [25]: with ExifTool() as et:
    ...:     et.execute('-Exif:GPSLatitude=41.555', "./notag_cog.tif")
    ...:     print(et.last_stderr)
    ...: 

In [26]: !exiv2 -pt  notag_cog.tif| grep -i GPSLatitude
Warning: Directory Image3 has an unexpected next pointer; ignored.
Exif.GPSInfo.GPSLatitudeRef                  Ascii       2  North
Exif.GPSInfo.GPSLatitude                     Rational    3  41deg 33' 18"

is there a reason to have this different behaviour respect CLI use? or better question, is there a way to align use of API to CLI adding some more parameter?

luipir commented 4 days ago

Adapted the code to the behaviour and overridden this "issue" (if any). BTW I leave open the ticket as a form to add documentation.

luipir commented 4 days ago

is the # modifier that allow to disable print convertion? as explained into: A # may be appended to the tag name to disable the print conversion on a per-tag basis (see the -n option). This may also be used when writing or copying tags.

StarGeekSpaceNerd commented 4 days ago

Copy/Paste from my response on the exiftool forums

et.execute isn't an exiftool API command. See the Image::ExifTool Perl Library Module.

It sounds like you're using PyExifTool. This was created by a 3rd party and isn't supported by the author of exiftool.

I did find this StackOverflow answer which seems like it might apply to your problem.

boardhead commented 1 day ago

This is the wrong place for this report, but I suspect the problem is that you shouldn't be using quotes inside arguments passed to et.execute

StarGeekSpaceNerd commented 1 day ago

Ah, good catch Phil.

From the PyExiftool docs

Parameters which need to be quoted on the command line generally do not need to be quoted in the parameters to PyExifTool. In fact, quoting may have unintended behavior.

luipir commented 23 hours ago

Houch! so sorry @StarGeekSpaceNerd @boardhead , I didn't realised that pyexiftool was not belonging to the project!