More precise testName output

Started by arctgx, February 29, 2016, 09:59:19 AM

Previous topic - Next topic

arctgx

Hi

Usually I use bash script containing the following exiftool usage:

exiftool '-filename<${CreateDate} ${filename;s#^(DSC[_F]?|IMG[P]?|[pP]|image)(\d+[^.]*)\..*$#$2#}.%le' -d '%F_%H.%M.%S%%-c' -overwrite_original -m "$1"

It (after separate checking if CreateDate tag value is not empty) is sufficient to rename the most of my files. But the part of JPEG files comes from RawTherapee. There are separate PP3 files which describe how the given RAW file was processed to obtain its JPG output. For example, making a.jpg in RT involve making a.jpg.out.pp3 file (unless we have disabled this functionality).

I would like rename PP3 files along with its JPEG equivalents.

For now, I can use testName and extract the new JPG file name from its output and use it to both further PP3 file renaming and renaming the same JPG file by mv command (to avoid generating the new fine name once again). The second, primitive but clearer, solution is to simplify the output in exiftool executable.

I cannot even state (in reasonable time) whether ExifTool library allows such extraction in simple way because I am not familiar with Perl.

It will be good to avoid additional extracting this name by external tools.

Regards

Phil Harvey

Before you rename the JPEG files, you could run a command like this to rename the PP3 files:

exiftool '-filename<${CreateDate} ${filename;s#^(DSC[_F]?|IMG[P]?|[pP]|image)(\d+[^.]*)\..*$#$2#}.%le' -d '%F_%H.%M.%S%%-c' -m -ext pp3 -tagsfromfile %d%f.jpg DIR

Note that -overwrite_original should not be necessary in either command if you are just renaming the file.

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

arctgx

It would be useful but I have problem with usage, even on single pair witohut using format to get source file name:

$ ls -1Q
"DSC_8252.JPG"
"DSC_8252.NEF"
"DSC_8252.NEF.pp3"
"DSC_8252-t.jpg"
"DSC_8252-t.jpg.out.pp3"
$ exiftool '-filename<${createDate} ${filename;s#^(DSC[_F]?|IMG[P]?|[pP]|image)(\d+[^.]*)\..*$#$2#}.%le' -d '%F_%H.%M.%S%%-c' -tagsfromfile DSC_8252-t.jpg  DSC_8252-t.jpg.out.pp3
Warning: Unknown file type - DSC_8252-t.jpg.out.pp3
Error: Writing of this type of file is not supported - DSC_8252-t.jpg.out.pp3
    0 image files updated
    1 files weren't updated due to errors


Direct application also does not work as expected, not only because of two different extension formats (pp3, out.pp3):

$ ls -1Q
"DSC_8252.JPG"
"DSC_8252.NEF"
"DSC_8252.NEF.pp3"
"DSC_8252-t.jpg"
"DSC_8252-t.jpg.out.pp3"
$ exiftool '-filename<${CreateDate} ${filename;s#^(DSC[_F]?|IMG[P]?|[pP]|image)(\d+[^.]*)\..*$#$2#}.%le' -d '%F_%H.%M.%S%%-c' -m -ext .pp3 -tagsfromfile %d%f .
Warning: Unknown file type - ./DSC_8252-t.jpg.out.pp3
Warning: Error opening file - ./DSC_8252-t.jpg.out
Warning: Unknown file type - ./DSC_8252.NEF.pp3
Error: Writing of this type of file is not supported - ./DSC_8252.NEF.pp3
    1 directories scanned
    1 image files updated
    1 files weren't updated due to errors
$ ls -1Q
"DSC_8252.JPG"
"DSC_8252.NEF"
"DSC_8252.NEF.pp3"
"DSC_8252-t.jpg"
" 8252-t.pp3"


I tried -ext out.pp3:
$ exiftool -v '-filename<${CreateDate} ${filename;s#^(DSC[_F]?|IMG[P]?|[pP]|image)(\d+[^.]*)\..*$#$2#}.%le' -d '%F_%H.%M.%S%%-c' -m -ext out.pp3 -tagsfromfile %d%f .
    1 directories scanned
    0 image files read



To ensure that source files can be itself properly renamed:
$ exiftool '-filename<${CreateDate} ${filename;s#^(DSC[_F]?|IMG[P]?|[pP]|image)(\d+[^.]*)\..*$#$2#}.%le' -d '%F_%H.%M.%S%%-c' -m DSC_8252-t.jpg DSC_8252.NEF
    2 image files updated
$ ls -1Q  *.{jpg,nef}
"2016-01-16_02.16.23 8252.nef"
"2016-01-16_02.16.23 8252-t.jpg"


Assuming that even this hint would work, it still have one drawback: it requires reading original EXIF data twice which is significant for renaming hundreds of images on slow SD card.

Phil Harvey

Quote from: arctgx on February 29, 2016, 02:03:31 PM
$ exiftool '-filename<${createDate} ${filename;s#^(DSC[_F]?|IMG[P]?|[pP]|image)(\d+[^.]*)\..*$#$2#}.%le' -d '%F_%H.%M.%S%%-c' -tagsfromfile DSC_8252-t.jpg  DSC_8252-t.jpg.out.pp3
Warning: Unknown file type - DSC_8252-t.jpg.out.pp3
Error: Writing of this type of file is not supported - DSC_8252-t.jpg.out.pp3
    0 image files updated
    1 files weren't updated due to errors[/code]

Sorry, my mistake.  The -tagsFromFile option must come before the tag you are copying.  So the above command should be:

exiftool -tagsfromfile DSC_8252-t.jpg '-filename<${createDate} ${filename;s#^(DSC[_F]?|IMG[P]?|[pP]|image)(\d+[^.]*)\..*$#$2#}.%le' -d '%F_%H.%M.%S%%-c' DSC_8252-t.jpg.out.pp3

I should have known better.  The way I had it, the command was trying to copy FileName from the pp3 itself, plus all of the tags from the jpg file, which of course won't work.

But you're right.  This will read a file from the SD card for each file that is renamed, whereas in a perfect world you could rename them both in parallel after reading a single jpg.

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

arctgx

It is one step ahead but I still cannot physically rename PP3 file:

$ exiftool -v5 -tagsfromfile DSC_8252-t.jpg -createDate '-filename<${createDate} ${filename;s#^(DSC[_F]?|IMG[P]?|[pP]|image)(\d+[^.]*)\..*$#$2#}.%le' -d '%F_%H.%M.%S%%-c' DSC_8252-t.jpg.out.pp3
Setting new values from DSC_8252-t.jpg
Writing MIE-Doc:CreateDate
Writing PostScript:CreateDate
Writing PDF:CreateDate if tag exists
Writing QuickTime:CreateDate if tag exists
Writing PNG:CreateDate
Writing XMP-xmp:CreateDate if tag exists
Writing ExifIFD:CreateDate
Writing File:FileName
======== DSC_8252-t.jpg.out.pp3
'DSC_8252-t.jpg.out.pp3' --> '2016-01-16_02.16.23 8252-t.pp3'
Rewriting DSC_8252-t.jpg.out.pp3...
  Error = Writing of this type of file is not supported
Error: Writing of this type of file is not supported - DSC_8252-t.jpg.out.pp3
    0 image files updated
    1 files weren't updated due to errors
$ exiftool -listwf | grep PP3; echo $?
1


I do not know how file type is recognized by exiftool. What does it matter if we want to change only its name, not the content? Btw,

$ file *.pp3
DSC_8252.NEF.pp3:       Windows setup INFormation, ASCII text, with very long lines
DSC_8252-t.jpg.out.pp3: Windows setup INFormation, ASCII text, with very long lines

Phil Harvey

But you are trying to also copy CreateDate.  If you are just writing FileName, this should work.

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

arctgx

Indeed, it works after removing redundant parameter.  :)  It follows that I have to practice more examples to better understand the significance of the order of parameters when -tagsfromfile is used.

This additional parameter comes from debugging the first proposed solution. In that case selection of fields taken place on the left side of -tagsfromfile so exiftool tried (by default) to copy all tags from the source. In your recent hint the filename tag is (by explicit selection) the only "tag" used to write. I was wrongly convinced that I restrict tags to read by selecting it as parameters.

There remains the problem of file name extensions containing period. Extension out.pp3 given as a parameter value is ignored:

$ exiftool -v5 -tagsfromfile %d%f '-filename<${createDate} ${filename;s#^(DSC[_F]?|IMG[P]?|[pP]|image)(\d+[^.]*)\..*$#$2#}.%le' -d '%F_%H.%M.%S%%-c' -m -ext out.pp3 .
    1 directories scanned
    0 image files read
$ ls -1Q
"DSC_8252.JPG"
"DSC_8252.NEF"
"DSC_8252.NEF.pp3"
"DSC_8252-t.jpg"
"DSC_8252-t.jpg.out.pp3"


$ exiftool -v5 -tagsfromfile %d%f '-filename<${createDate} ${filename;s#^(DSC[_F]?|IMG[P]?|[pP]|image)(\d+[^.]*)\..*$#$2#}.%le' -d '%F_%H.%M.%S%%-c' -m -ext pp3 .
======== ./DSC_8252-t.jpg.out.pp3
Setting new values from ./DSC_8252-t.jpg.out
Warning: Error opening file - ./DSC_8252-t.jpg.out
Nothing changed in ./DSC_8252-t.jpg.out.pp3
======== ./DSC_8252.NEF.pp3
Setting new values from ./DSC_8252.NEF
Writing File:FileName
'./DSC_8252.NEF.pp3' --> './2016-01-16_02.16.23 8252.pp3'
    + FileName = './2016-01-16_02.16.23 8252.pp3'
    1 directories scanned
    1 image files updated
    1 image files unchanged
$ ls -1Q
"2016-01-16_02.16.23 8252.pp3"
"DSC_8252.JPG"
"DSC_8252.NEF"
"DSC_8252-t.jpg"
"DSC_8252-t.jpg.out.pp3"


Before giving up I read a chapter about formatting for -w option. This example for both tested PP3 files works only by accident:
exiftool -v5 -tagsfromfile %d%14f '-testname<${createDate} ${filename;s#^(DSC[_F]?|IMG[P]?|[pP]|image)(\d+[^.]*)\..*$#$2#}.%le' -d '%F_%H.%M.%S%%-c' -m -ext pp3 .
The number of characters in DSC_8252-t.jpg string but it is individual for file and the fact that DSC_8252.NEF has no more characters is an accident.

Phil Harvey

Quote from: arctgx on March 01, 2016, 11:48:50 AM
I was wrongly convinced that I restrict tags to read by selecting it as parameters.

When copying without specifying any tags, ExifTool reads everything and tries to write each tag to the same-named tag.  So you may restrict the tags read by specifying them after the -tagsFromFile option, but it still tries to write each of the tags read, so you are restricting the writing as well.  I hope this helps.  I don't know if I understand the source of confusion.

QuoteThere remains the problem of file name extensions containing period. Extension out.pp3 given as a parameter value is ignored:

Right.  I didn't pay attention to this problem before.  Extensions with a period are problematic.  File names may contain a dot, but file extensions may not.  So the extension of "DSC_8252-t.jpg.out.pp3" is "pp3".

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

arctgx

Thank you for help. It will be sufficient for me to renaming separate image files with associated (by adding a suffix specific to extension) PP3 file if that exists.

Yet about the last example from my previous post: I overlooked the filename format that allows get this name without specified number of last characters:
exiftool -v5 -tagsfromfile %d%-.4f '-testname<${createDate} ${filename;s#^(DSC[_F]?|IMG[P]?|[pP]|image)(\d+[^.]*)\..*$#$2#}.out.%le' -d '%F_%H.%M.%S%%-c' -m -ext pp3 *.out.pp3

The above working example has only educational value for me because wildcard "*.pp3" that would be used to process the rest of PP3 files contains "*.out.pp3" (unless I will use find or something else to their exclusion).