How to force the 'auto-discovery' columns

Started by Martin Z, May 13, 2023, 11:54:28 AM

Previous topic - Next topic

Martin Z

When not specifying any column names, EXIFTool will automatically build the column list as it goes by what is populated in the files it processes (👍🏼)... However, is there an option to force this behaviour?

i.e. when including a parameter to adjust the formatting of a specific column, but not wanting EXIFtool to then only include that column in the output (and wanting it to include all the columns it normally would, just with additional formatting on that one).

[NB: I don't mean the -common option]



Hope the above is clear,
Thanks in advance!
- Martin

StarGeek

Nothing specific.  Though maybe try -TAG -TAG -All:All  My quick test looks like it will put the specified tag names first and then everything else.  I didn't examine it in depth, though.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

Martin Z

#2
Hi @StarGeek,

Thanks, think this works (I applied this as part of the wider scenario I was working on and after a bit of back-and-forth, think I have this cracked now -- but if the below explanation + code is wrong, please let me know!

For context (and any future other readers)...
• AIM #1: To be able to have EXIFtool produce a CSV with all the auto-detected tags as it normally would
• AIM #2: To be able to additionally specify formatting for one/more columns (e.g. -Duration#)
• AIM #3: To (optionally) explicitly add/remove column from the auto-detected set of tags if needed

The following combination of parameters seems to meet all 3 objectives...
> EXIFtool -csv -TAG -TAG -all:all -f
  (optional) -columnFormats
  (optional) -NonDetectedColumnsToAdd
  (optional) --DetectedColumnsToRemove

Examples...
> DIR
video.mp4     [1 video/mp4 file, no specific metadata added to it]

> EXIFtool -csv
1 image read  [66 columns as standard: SourceFile, Directory, AudioChannels, ImageWidth, Duration, etc]

> EXIFtool -csv -TAG -TAG -all:all
1 image read  [same 66 columns exported]

> EXIFtool -csv -Duration#
1 image read  [only 2 columns exported: ❌ SourceFile, Duration]

> EXIFtool -csv -TAG -TAG -all:all -Duration#
1 image read  [same 66 columns exported, ❓ however could not verify -Duration# was processed]

> EXIFtool -csv -TAG -TAG -all:all --Duration
1 image read  [65 columns exported, ✅ excluding Duration]

> EXIFtool -csv -TAG -TAG -all:all -ContentDistributor
1 image read  [same 66 columns exported,  ⚠️ however the 'ContentDistributor' column was not included (because it is not populated)]

> EXIFtool -csv -TAG -TAG -all:all -ContentDistributor -f
1 image read  [67 columns exported, ✅ including the -f option forces the non-present tag to be included]

> EXIFtool -csv -TAG -TAG -all:all -f -ContentDistributor --Duration
1 image read  [66 columns exported, ✅ including 'ContentDistributor', excluding Duration]

NB: What prompted this question, was a tip you (StarGeek) kindly gave me to format a specific column (rather than using -n which affects all columns) by suffixing # (e.g. -Duration#)

Ironically, everything worked fine in my extended tests however I could not see any difference in the outputs when -Duration# was included vs. without -- which I'm thinking means maybe it wasn't processed, or was overridden by another parameter(?) -- To Recap: I was trying to get all durations to have the same format when exported, regardless whether the video was 1 second long or 1 hour, as currently it changes depending if the video is longer/shorter than 30 seconds.



PS -- Just to check it was not a typo, I included the tags as you had them [ -TAG -TAG -All:All ]... i.e. the [ -TAG ] is specified twice(?)

Phil Harvey

Quote from: Martin Z on May 16, 2023, 01:49:27 PMI could not see any difference in the outputs when -Duration# was included vs. without

> exiftool a.mov -duration -duration# -all -csv
SourceFile,Duration,Duration#,ExifToolVersion,FileName,Directory,FileSize [...]

... but if the first processed file doesn't contain a Duration tag, then the output will be different because the columns are ordered based on the first time the tag is encountered.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Martin Z

Hi Phil, thanks for the quick follow-up and clarification!

Quote from: Phil Harvey on May 16, 2023, 02:31:24 PMthe columns are ordered based on the first time the tag is encountered
My bad, I should have been more specific and/or explained that in this case I was testing for column presence (only), i.e. checking which tags made it into the CSV or not (I had actually thought to test column order as for me that wasn't important) - but you're definitely right to point it out as it may be more relevant to others!

Just to clarify then, is column order the only thing that would change or (relating back to the -Duration#) would you expect there to be other differences too?



Side note: I noticed that you (and StarGeek originally) have both written the command as -duration -duration#, i.e. from a newbie perspective with the -duration column specified twice -- is this needed?... In my case, I knew that the Duration column would be there (because I am explicitly running EXIFtool on a set of .mp4 files). I therefore just included -Duration# (to apply the formatting), I didn't think to explicitly state the duration column itself... Is this valid? (or for example does the '#' syntax only work if you explictly include the column name as a separate parameter)?

Phil Harvey

Quote from: Martin Z on May 16, 2023, 02:46:52 PMJust to clarify then, is column order the only thing that would change or (relating back to the -Duration#) would you expect there to be other differences too?

If the tag isn't found, then the column name will be in the same case as entered in the command, otherwise the case is changed to correspond with the pre-defined tag name.

QuoteSide note: I noticed that you (and StarGeek originally) have both written the command as -duration -duration#, i.e. from a newbie perspective with the -duration column specified twice -- is this needed?

No, I just did this to illustrate the difference.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Martin Z

Lol, in the process of replying I've had to scrap the part-written message and start over twice due to my incremental learning on the fly! 🙈 TLDR; thanks all good!

Additional info -- The combination of -duration and  -all did throw me a little (especially in context of my question a minute ago) but to check my understanding (and for the benefit of any future readers) -- you did this specifically to control the column order(?), as in assuming context of a video file...
• -all includes the ~60 columns or so (incl. duration)
• -duration includes only that column (and SourceFile)
• -duration -all (at first thought was redundant as it duration is already included by using -all) but this is to order duration before the rest of the other columns(?)

Thanks 👍🏼

Phil Harvey

Yes.  Exactly.  And to make it appear if the files don't contain Duration.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).