How to access -filetype from Python

Started by wzorn, March 19, 2025, 11:06:38 AM

Previous topic - Next topic

wzorn

This should be an easy question, but I'm scratching my head.  I'm using python to process some image files and I've run across the case where the exiftool will not write metadata to the file because the extension is .jpg, but the filetype (in the metadata) is .png.  So, my approach is to read the filetype metadata and validate that the extensions are correct on my files.

I think I keep looking in the right places I just don't see what I'm looking for.  I think what I need is the [GROUP:]TAG name for it.

StarGeek

Are you asking for how to figure out a file type using Python, or how to figure it out running exiftool?

With exiftool, you can check the FileType tag (see the Extra Tags page)
C:\>exiftool -G1 -a -s -filetype Y:\!temp\x\y\Green-Crystal.jpg
[File]          FileType                        : PNG

You can correct the extension with the FileTypeExtension tag
C:\>exiftool -G1 -a -s -FileTypeExtension Y:\!temp\x\y\Green-Crystal.jpg
[File]          FileTypeExtension               : png

C:\>exiftool -progress "-Filename<%f.$FileTypeExtension" Y:\!temp\x\y\Green-Crystal.jpg
======== Y:/!temp/x/y/Green-Crystal.jpg [1/1]
'Y:/!temp/x/y/Green-Crystal.jpg' --> 'Y:/!temp/x/y/Green-Crystal.png'
    1 image files updated

A pure Python way to do so would be outside the scope of this forum.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

wzorn

I figured it out.    Yes, I'm trying to do it through python.  It looks like what I needed is File:FileType or File:FileTypeExtension.

Is a list of possible values for those tags somewhere?

StarGeek

"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

wzorn