Author Topic: Rename photos by datetimeoriginal and calculate kids age  (Read 22700 times)

aage

  • Full Member
  • ***
  • Posts: 38
Rename photos by datetimeoriginal and calculate kids age
« on: April 07, 2014, 03:43:04 PM »
Hi

I have for a very long time searched for a way to rename all my digital photos and suddenly I found ExifTool that after 5 days of intensive reading seems to be the only tool that can solve my problem  :) :)

I would like to rename to this format : "Date_that_photo_was_taken"_"Capital_Letter_for_Daughter_Name"_"Daughter_Age"_"Capital_Letter_for_Son_Name"_"Son_Age".

That means that all photos should be named like this: 23052011_L3Y2M_J1Y4M.jpg
(Photo was taken 23.05.2011 and at that time my daughter was 3 years and 2 months old, her name starts with an L and my son was 1 year and 4 month old and his name starts with a J).

The above is only an example showing the format.

I would like to be able to write a few lines of code in the Terminal window on my MAC and put in both kids date of birth.

I have read this question :http://u88.n24.queensu.ca/exiftool/forum/index.php/topic,3176.0.html and I accept that the calculation is based on 30 days a month  :)

This article is VERY close to what I would like but I don´t want to be dependent on the "name-idintifying-thing" in the config-file. Contrary I would like ALL photo to be renamed as described above and if one of the kids were not born on the date the photo was taken I would like to state that in the filename this way: 23052011_L3Y2M_JnotBorn.jpg

I think the calculation should be based on EXIF-field: datetimeoriginal.

I have now tried writing the line of code for the Terminal-window for several days (I am not a programmer) but I cant´t get it to work  :-\

Can somebody help me out - I would really appreciate it !!

Thanks  ;D

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 14425
    • ExifTool Home Page
Re: Rename photos by datetimeoriginal and calculate kids age
« Reply #1 on: April 07, 2014, 07:08:31 PM »
This sounds very do-able, but will require a custom config file containing a little trickery.  I'll come up with the config file for you.  I'll try to have a go at it tonight, but it may be tomorrow before I get a chance to work on this.

I just want to be sure I understand.  It doesn't matter who is in the photo.  The only variable input to the name of the file is DateTimeOriginal.  (The kid's names and birthdays are constants.)  Right?

- 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 ($).

aage

  • Full Member
  • ***
  • Posts: 38
Re: Rename photos by datetimeoriginal and calculate kids age
« Reply #2 on: April 08, 2014, 12:44:50 AM »
Hi Phil

I really appreciate you helping me out - thanks a LOT !!!!!!

You wrote:
"I just want to be sure I understand.  It doesn't matter who is in the photo.  The only variable input to the name of the file is DateTimeOriginal.  (The kid's names and birthdays are constants.)  Right?"

Yes - that is all correct ;-)

Once again - Thanks in advance !

-Aage

aage

  • Full Member
  • ***
  • Posts: 38
Re: Rename photos by datetimeoriginal and calculate kids age
« Reply #3 on: April 08, 2014, 12:48:12 AM »
Just forgot...
 - is it possible to have the mark of the camera in front  - like : Canon_23052011_L3Y2M_J1Y4M.jpg ?

-Aage

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 14425
    • ExifTool Home Page
Re: Rename photos by datetimeoriginal and calculate kids age
« Reply #4 on: April 08, 2014, 07:40:44 AM »
Hi Aage,

Here you go.  Attached is a config file that should do what you want.  All you need to do is change the birthdays to the proper dates in the calls to MakeCode().  The command would look like this:

exiftool -config Aage.config "-filename<myfilename" DIR

where DIR is the name of the directory containing the images.

Here is what the config file looks like:

Code: [Select]
sub MakeCode($$$)
{
    my @date1 = split /[: ]/, shift;
    my @date2 = split /[: ]/, shift;
    my $name = shift;
    my $years = $date1[0] - $date2[0];
    my $months = $date1[1] - $date2[1];
    my $days = $date1[2] - $date2[2];
    if ($days < 0) { --$months; }
    if ($months < 0) { $months += 12; --$years; }
    my $str = '';
    $str .= "${years}Y" if $years > 0;
    $str .= "${months}M" if $months > 0 and $years >= 0;
    $str = "_$name$str" if $str;
    return $str;
}

%Image::ExifTool::UserDefined = (
    'Image::ExifTool::Composite' => {
        MyFileName => {
            Require => {
                0 => 'DateTimeOriginal',
                1 => 'Make',
            },
            ValueConv => sub {
                my $vals = shift;
                my $date = $$vals[0];
                my $make = $$vals[1];
                my $daughter = MakeCode($date, '1998:03:22', 'L');
                my $son = MakeCode($date, '2003:10:13', 'J');
                $make =~ tr(/\\?*:|"<>\0)()d; # remove illegal characters
                my @parts = split /[: ]/, $date;
                return "${make}_$parts[2]$parts[1]$parts[0]$daughter$son";
            },
        },
    },
);
1;  #end

- 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 ($).

aage

  • Full Member
  • ***
  • Posts: 38
Re: Rename photos by datetimeoriginal and calculate kids age
« Reply #5 on: April 08, 2014, 01:05:47 PM »
Hi Phil

Thank you so much !!!

For activating the config-file I have read this one : http://owl.phy.queensu.ca/~phil/exiftool/config.html
I am a bit unsure if I should rename the config-file as described - my guess is, that I should not. My guess is based on the command-line that you instruct me to write in the Terminal-window. Is that correct ?

My very limited knowledge of the MAC-filesystem makes me unsure where to place the config-file. Should this be in the Application-folder or somewhere in the Usr/bin-thing ? I have tried opening this directory but don´t know where to look - there is so many files and folders in there  :-X I have read the uninstalling description for Exif-tool and it states that you should know what you are doing before exetuting anything in here. I don´t know what I am dooing  :)

Can you guide me before I kill my MAC ;-)

/Lars 

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 14425
    • ExifTool Home Page
Re: Rename photos by datetimeoriginal and calculate kids age
« Reply #6 on: April 08, 2014, 01:20:06 PM »
Hi Lars,

There are 2 ways to activate the config file.  Either use the -config option as I have done, or rename the file and place it in a standard location (preferably your home directory) as per the config.html instructions.

For file/folder names on the command line, it may be easier for you to drag and drop the file/folder rather than typing the name -- then you don't need to worry about what folder it is in.

Also, I suggest trying this on a few test files before letting it loose on your pictures folder.

- 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 ($).

aage

  • Full Member
  • ***
  • Posts: 38
Re: Rename photos by datetimeoriginal and calculate kids age
« Reply #7 on: April 08, 2014, 02:37:48 PM »
Hi Phil

You are fast !!

I will perform test before renaming all files ;-)

Here is what I did:
1) Placed the config-file in my HOME-directery
2) In Terminal-window: exiftool -config Aage.config "-filename<myfilename" /Users/Aagesen/ExifTool_ExportFile/Oprindelig_Mappe

Result:
   1 directories scanned
    4 image files updated
   18 files weren't updated due to errors

4 files were renamed BUT changed to a file without extention (.jpg). I get this errormessage trying to open the file:
--------------------------------------------------------------
Last login: Tue Apr  8 20:59:00 on ttys001
Aagesens-Mac-mini:~ Aagesen$ /Users/Aagesen/ExifTool_ExportFile/Oprindelig_Mappe/Canon_22072013_L15Y4M_J9Y9M ; exit;
-bash: /Users/Aagesen/ExifTool_ExportFile/Oprindelig_Mappe/Canon_22072013_L15Y4M_J9Y9M: cannot execute binary file
logout
---------------------------------------------------------------
I also get a lot of warnings like:
Warning: [minor] Adjusted MakerNotes base by 4038 - /Users/Aagesen/ExifTool_ExportFile/Oprindelig_Mappe/Canon_2013_07_23_101444.JPG

I have read about these warnings but I can´t figure out how to fix it. Tried before you wrote me the script and config-file - but no luck  :-[

Quistions:
Q1) What to do about the warnings ?
Q2) How do I open the config-file for editing the birth of dates?
Q3) Can it run all sub-directories by adding the "-r"-thing and how would the command-line look with this added ?
Q4) Have I dione something wrog since renamed files are changed and without extention ?
Q5) Does the script work for .MOV and other video-files as well? (Think I have read a post somewhere that a command-line preference can make this happen ?)

/Lars
« Last Edit: April 08, 2014, 03:05:40 PM by aage »

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 14425
    • ExifTool Home Page
Re: Rename photos by datetimeoriginal and calculate kids age
« Reply #8 on: April 09, 2014, 07:44:04 AM »
Hi Lars,

4 files were renamed BUT changed to a file without extention (.jpg).

Ooops, sorry.  I should have used "-filename<$myfilename.%e"

Quote
I also get a lot of warnings like:
Warning: [minor] Adjusted MakerNotes base by 4038 - /Users/Aagesen/ExifTool_ExportFile/Oprindelig_Mappe/Canon_2013_07_23_101444.JPG

The lower-case "m" minor warnings are informational only, and ExifTool will fix this particular problem automatically.

Quote
Q2) How do I open the config-file for editing the birth of dates?

With any plain text editor.

Quote
Q3) Can it run all sub-directories by adding the "-r"-thing and how would the command-line look with this added ?

Yes.  Just add -r anywhere on the command line, separated from other arguments by spaces.

Quote
Q5) Does the script work for .MOV and other video-files as well?

It works for any writable type.  MOV is now a writable type.  See FAQ 16 for more information.

- 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 ($).

aage

  • Full Member
  • ***
  • Posts: 38
Re: Rename photos by datetimeoriginal and calculate kids age
« Reply #9 on: April 09, 2014, 03:01:43 PM »
Hi Phil

Thanks again for getting back to me on this one ;-)

Just tried this command: exiftool -config Aage.config "-r -filename<myfilename.%e" /Users/Aagesen/ExifTool_ExportFile/Oprindelig_Mappe

I now get this result (minor warnings and Warnings):
----------------------------------------------------------------
Warning: [minor] Adjusted MakerNotes base by 4038 - /Users/Aagesen/ExifTool_ExportFile/Oprindelig_Mappe/013_23_07_2013.JPG
Warning: No writable tags set from /Users/Aagesen/ExifTool_ExportFile/Oprindelig_Mappe/013_23_07_2013.JPG
Warning: No writable tags set from /Users/Aagesen/ExifTool_ExportFile/Oprindelig_Mappe/IMG_1255.MOV
Warning: No writable tags set from /Users/Aagesen/ExifTool_ExportFile/Oprindelig_Mappe/IMG_1981.JPG
Warning: No writable tags set from /Users/Aagesen/ExifTool_ExportFile/Oprindelig_Mappe/IMG_1982.JPG
Warning: No writable tags set from /Users/Aagesen/ExifTool_ExportFile/Oprindelig_Mappe/IMG_1983.JPG
    1 directories scanned
    0 image files updated
   17 image files unchanged
----------------------------------------------------------------

Camera used making .JPG and .MOV are : Canon Ixus, Canon EOS 450, Canon EOS 600, Iphone 3 +4

What do I do wrong ?

/Lars

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 14425
    • ExifTool Home Page
Re: Rename photos by datetimeoriginal and calculate kids age
« Reply #10 on: April 10, 2014, 07:26:32 AM »
Hi Lars,

The -r must be outside the quotation marks, otherwise it becomes part of the -filename argument.

- 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 ($).

Oskar

  • Jr. Member
  • **
  • Posts: 11
Re: Rename photos by datetimeoriginal and calculate kids age
« Reply #11 on: April 10, 2014, 08:24:54 AM »
Also, Totalcommander has a powerful rename tool. Select files, press Ctrl+M and you get a dialog with lots of options: date, custom text, extension etc.

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 14425
    • ExifTool Home Page
Re: Rename photos by datetimeoriginal and calculate kids age
« Reply #12 on: April 10, 2014, 09:02:57 AM »
Totalcommander has a powerful rename tool. Select files, press Ctrl+M and you get a dialog with lots of options: date, custom text, extension etc.

...but will it calculate the age of Lars' children?  I suspect not.

- 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 ($).

aage

  • Full Member
  • ***
  • Posts: 38
Re: Rename photos by datetimeoriginal and calculate kids age
« Reply #13 on: April 10, 2014, 11:39:42 AM »
Hi Oskar and Phil

Exactly as Phil mentioned - no other renameing-tool that I have come across can calculate the age of my kids. ExitTool is the far most flexible tool that I have ever seen - and with Phil on the side - you can´t wish for more ;-)

I tried this command :xiftool -config Aage.config -r "-filename<myfilename.%e" /Users/Aagesen/ExifTool_ExportFile/Oprindelig_Mappe

The result is better than placing the "-r" in front of the "-config" - I tried that as well ;-)

Nevertheless the result of the command above is this:
---------------------------------------------------------------------------------------------------------------------------------------------------
Warning: [minor] Adjusted MakerNotes base by 4038 - /Users/Aagesen/ExifTool_ExportFile/Oprindelig_Mappe/009_23_07_2013.JPG
Warning: No writable tags set from /Users/Aagesen/ExifTool_ExportFile/Oprindelig_Mappe/009_23_07_2013.JPG
Warning: No writable tags set from /Users/Aagesen/ExifTool_ExportFile/Oprindelig_Mappe/Undermappe2/IMG_1254.JPG
Warning: No writable tags set from /Users/Aagesen/ExifTool_ExportFile/Oprindelig_Mappe/Undermappe2/IMG_1257.MOV
    3 directories scanned
    0 image files updated
   25 image files unchanged
---------------------------------------------------------------------------------------------------------------------------------------------------

Do you think my pictures and videos are corrupt in some way since no renaming is done ?

/Lars

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 14425
    • ExifTool Home Page
Re: Rename photos by datetimeoriginal and calculate kids age
« Reply #14 on: April 10, 2014, 11:43:32 AM »
Hi Lars,

For the command to function, the MyFileName tag must exist.  For this to exist, the config file must be working and the DateTimeOriginal and Make tags must exist.  What is the output of this command?:

exiftool -config Aage.config -datetimeoriginal -make -myfilename /Users/Aagesen/ExifTool_ExportFile/Oprindelig_Mappe

- 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 ($).