sylikc / pyexiftool

PyExifTool (active PyPI project) - A Python library to communicate with an instance of Phil Harvey's ExifTool command-line application. Runs one process with special -stay_open flag, and pipes data to/from. Much more efficient than running a subprocess for each command!
Other
159 stars 20 forks source link

Allow returning results without group name (a way to disable `-G`) #94

Open ninas opened 3 months ago

ninas commented 3 months ago

Hi there! First off, thanks for this library, it has made my life infinitely easier!

I'm not sure if this is already possible, but I wasn't able to figure it out from the docs/playing with params myself.

Is there a way to use the library so that results are returned without the groupname prefix? i.e. ExposureTime instead of EXIF:ExposureTime

When using exiftool directly, if the group name is not specified, it returns a value using the default group for that tag (at least that's what I understand from here).

I get the same result running exiftool directly:

$> exiftool -s -G -j -ExposureTime file.jpg
[{
  "SourceFile": "file.jpg",
  "EXIF:ExposureTime": "1/500",
  "MakerNotes:ExposureTime": "1/523"
}]

Or using the python library:

with exiftool.ExifToolHelper() as et:
    res = et.get_tags(["file.jpgl"], {"tags": ["ExposureTime"]})
print(res)

However, running:

$> exiftool -s -j -ExposureTime file.jpg
[{
  "SourceFile": "file.jpg",
  "ExposureTime": "1/500"
}]

returns what I'm looking for (i.e. only the default value for the specified tag). Is there a way to get the same behaviour in pyexiftool?

ninas commented 3 months ago

I've attached the image I was using in case that's helpful: Canon_PowerShot_S40

sylikc commented 1 month ago

I'm not sure if this is already possible, but I wasn't able to figure it out from the docs/playing with params myself.

Is there a way to use the library so that results are returned without the groupname prefix? i.e. ExposureTime instead of EXIF:ExposureTime

@ninas the answer is yes, it's already provided. As per the docs https://sylikc.github.io/pyexiftool/reference/1-exiftool.html#exiftool.ExifTool.__init__ , you can initialize with the parameter common_args. The default is ['-G', '-n'], so you can just instantiate a pyexiftool object with common_args=['-n'] and that's it!

ninas commented 1 month ago

Ah, missed that, thanks for responding!