Sort by Year, Camera Model and rename filename

Started by fabiosirna, April 28, 2016, 07:17:44 PM

Previous topic - Next topic

fabiosirna

Hi there,
thanks for having created exiftool: is a very powerful tool that saves me a lot of time.

I'm using exiftool on OSX in order to try to put order in my photo library.
I  want to migrate my archive from from Aperture to a hierarchical folder on my filesystem in order to work with referenced images (I'm evaluating Capture One BTW).

I'm usually run exiftool multiple times in order the get things done. But tonight I was wondering if it could be easy to reach my final organization with just one command.

The starting folder is something like:


MESS_DIR
+ Folder A
+ Folder B
+ My_other_messy_folder


My goal is to get my archive sorted by Year and Camera Model:


MESS_DIR
+ 2006
    + Nikon D80
    + iPhone 3G
+ 2007
    + Nikon D80
    + iPhone 4G
    + Finepix X100
...


and rename every image like:


20061221_170129_1920x1285_NIKON D80_000.jpg

date_time_size_model_counter.ext


My final code to run on top the MESS_DIR is:


exiftool -P -d '%Y%m%d_%H%M%S' \
'-filename<${FileModifyDate}_${ImageSize}%+.3c.%le' \
'-filename<${CreateDate}_${ImageSize}%+.3c.%le' \
'-filename<${Model}/${DateTimeOriginal}_${ImageSize}%+.3c.%le' \
'-filename<${Model}/${DateTimeOriginal}_${ImageSize}_${Model}%+.3c.%le' \
-r .


Reading the documentation I understand that is possibile to add a dir in the filename section (as I did) but I cannot understand how to add the YEAR on top of the model folder :(

Please suggest also if my strategy for the fallback is correct: I have mutiple images taken with very old digital camera, that doesn't have the DateTimeOriginal field, so the last chance is to rename the file with the CreateDate and if not available with the FilemodifyDate field.

Given that, I'll run both fdupes/dupeguru PR in order to remove duplicates and try to clean my archive as much as possibile. Sometimes I have the same image with multiple size and I want to keep only the original not the other files created by Aperture or because I've shooted in RAW+JPG.
I would like to get rid off multiple JPG created from the raw files.

So my idea is to sort my archive in this way in order to get something like:

20061221_170129_3872x2592_NIKON D80_000.raf    — the original RAW
20061221_170129_3872x2592_NIKON D80_000.jpg    — this could be a JPG taken from camera o a version generated by Aperture 
20061221_170129_1920x1285_NIKON D80_000.jpg    — a preview or smaller version
20061221_170129_1024x768_NIKON D80_000.jpg     — thumbnail


I this way I can easily spot images that I can remove without no doubt.

If you have suggestions on how to improve this workflow they will be much appreciated.

Fabio

StarGeek

I didn't have time to test this, but maybe something like this to add the year on:
exiftool -P -d '%Y%m%d_%H%M%S' \
   '-filename<${FileModifyDate;s/(^\d{4}).*/\1/}/${FileModifyDate}_${ImageSize}%+.3c.%le' \
   '-filename<${CreateDate;s/(^\d{4}).*/\1/}/${CreateDate}_${ImageSize}%+.3c.%le' \
   '-filename<${DateTimeOriginal;s/(^\d{4}).*/\1/}/${Model}/${DateTimeOriginal}_${ImageSize}%+.3c.%le' \
   '-filename<${DateTimeOriginal;s/(^\d{4}).*/\1/}/${Model}/${DateTimeOriginal}_${ImageSize}_${Model}%+.3c.%le' \
   -r .


That will use the advanced formatting to grab the first 4 digits of the date.
"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

fabiosirna

#2
Wow, that's soooo fast.

I got this error:

Warning: \1 better written as $1 for FileModifyDate

so I've written:


exiftool -P -d '%Y%m%d_%H%M%S' \
   '-filename<${FileModifyDate;s/(^\d{4}).*/$1/}/${FileModifyDate}_${ImageSize}%+.3c.%le' \
   '-filename<${CreateDate;s/(^\d{4}).*/$1/}/${CreateDate}_${ImageSize}%+.3c.%le' \
   '-filename<${DateTimeOriginal;s/(^\d{4}).*/$1/}/${Model}/${DateTimeOriginal}_${ImageSize}%+.3c.%le' \
   '-filename<${DateTimeOriginal;s/(^\d{4}).*/$1/}/${Model}/${DateTimeOriginal}_${ImageSize}_${Model}%+.3c.%le' \
   -r .


and this solve my question :) Thanks!

About my question regarding the strategy, do you think that is better to add also the ModifyDate in the command in order to have a more precise sorting? Something like this:


exiftool -P -d '%Y%m%d_%H%M%S' \
   '-filename<${FileModifyDate;s/(^\d{4}).*/$1/}/${FileModifyDate}_${ImageSize}%+.3c.%le' \
   '-filename<${ModifyDate;s/(^\d{4}).*/$1/}/${ModifyDate}_${ImageSize}%+.3c.%le' \
   '-filename<${CreateDate;s/(^\d{4}).*/$1/}/${CreateDate}_${ImageSize}%+.3c.%le' \
   '-filename<${DateTimeOriginal;s/(^\d{4}).*/$1/}/${Model}/${DateTimeOriginal}_${ImageSize}%+.3c.%le' \
   '-filename<${DateTimeOriginal;s/(^\d{4}).*/$1/}/${Model}/${DateTimeOriginal}_${ImageSize}_${Model}%+.3c.%le' \
   -r .


As far as I know reading the documentation and my knowledge about EXIF the preferred order for the fallback is:

DateTimeOriginal
CreateDate
ModifyDate
FileModifyDate

Thanks.

PS. What does this part of the command do?


${DateTimeOriginal;s/(^\d{4}).*/$1/


I imagine the is taking the Date Time Original and keep only the Year. Is a regular expression? Is Perl? If you can share reference I can learn it for other tips. Thanks.

StarGeek

I could be wrong but I think ModifyDate is supposed to be when the file was last changed.  It's entirely software dependent, so it depends upon how your software acts whether you use it or not.  For example, most of the programs I use ignore it completely, but one program changes it every time I update the metadata.

QuotePS. What does this part of the command do?
${DateTimeOriginal;s/(^\d{4}).*/$1/

You guessed correct on both counts.  It's a perl regex substitution, which is in this format s/PATTERN/REPLACEMENT/OPTIONS.  No options are being used, so there's nothing trailing the last slash. In the PATTERN part, the \d indicates a digit (0-9), the {4} indicates that there should be 4 of the previous item, in this case a digit.  The ^ indicates the start of the line.  So we're looking for 4 digits at the very start.  The parentheses are a capture group, so we're grabbing this data and saving it for later.  The dot (.) matches any character, the asterisk indicates 0 or more occurrences of the previous item.  This grabs the rest of the line, but since it's not in a capture group, it's throwing away that data.  In the REPLACEMENT part, there's only the $1, which is the data in the first caption group. 

Since ExifTool is written in perl, it uses perl in it's advanced formatting (as well as many other places).  I learned regex through Regular-Expressions.info and use Regex101.com to test them out.  There's a lot of Perl sites out there and I don't have any single recommendation.  I really don't know perl very well.  Most of what I do is google for snippets of code I can try to get to do what I want.
"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

fabiosirna

Thanks for the tips. The image attached worth thousand words ;)