Add keywords to a range of filenames (date-time) using CSV file

Started by sjDelaney, August 22, 2015, 01:22:34 PM

Previous topic - Next topic

sjDelaney

It is possible?

I want to add keywords taken from a CSV file to a RANGE of file names that are date-time format (ie. 20150716-121304 to 20150716-121359)?

Currently I add a set of keywords (as I mentioned in another thread they are formatted as such " ~ Owner Name: Dog Name: Breed". I shoot at agility events and often the dogs are running courses in 30-50 seconds. Right now I'm using "running order" sheets and marking the last shot down (in pencil), then setting up and shooting a new set, every minute, for 2-3 days or more, from 8 am to 5 or 6pm.  At the end of the day, throughout the evening, I use LR to manually match each series of shots with the keywords I've already imported.

My current workflow looks like this...

  • Create and import keywords into new event LR catalog
  • Import raw files and rename to date-time
  • raw files and rename to date-time
  • running order pages for dog/owner and last shot
  • a range of pictures ending with the last shot
  • for owner/dog in Keyword list
  • and start over from 3


The match up looks something like this...

KeywordFile Name (Last shot for the run)
~ Carol Rowe: Rhumba: Pomeranian20150716-091901
~ Sally Miller: Raggy: Dachshund20150716-091949
~ Tracy Wilson: Wesley: West Highland White Terrier20150716-091203
~ Nancy Smith: Rudy: Papillon20150716-092115-3

(Sorry, I'm not clear on how insert table work in the editor.

Note the sequence numbers added to the end of some file names, because the camera fires more than one frame per second.  I'm sure this throws another wrench int the mix.

I use the tilde "~" in my keywords to filter the tagged pictures from the rest of the batch (e.g. Keywords Don't Contain "~"), and when no more pictures are found, I export the entire batch (minus rejects) jpegs and load them onto to netbooks for viewing the next day. I remove the tilde using Exif in another workflow (Thanks Phil - I think I got it!).

The tagging alone takes hours, keeps me up all night, and puts a tight squeeze on the export into jpegs that are small enough to be loaded and be viewed on underpowered Netbooks (remember those?).

If I could automate tagging with a CSV file and an algorithm to add keywords to a RANGE of pictures, I might be able to get some sleep.  However, what I've read so far is that for each line in the CSV file must match the file name exactly. If this is true, I'm afraid Im stuck with my old workflow.

A huge Thanks to anyone has experience with this, or is willing to look into it with me.

-sd

Phil Harvey

Quote from: sjDelaney on August 22, 2015, 01:22:34 PM
I want to add keywords taken from a CSV file to a RANGE of file names that are date-time format (ie. 20150716-121304 to 20150716-121359)?

I don't have time right now to read through the rest of your post, but for this you could try something like:

exiftool -if "$filename gt '20150716-121304' and $filename lt '20150716-121359'" -keywords=one -keywords=two ...

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

sjDelaney

Thanks Phil,

I understand (in principle) what the script is doing.  I've been reading and practicing with Perl and trying to put together what I suspect will turn out to be just a few lines of code.

However, my time is limited is limited by photography orders (a good thing to be sure), and I need to get this issue resolved ASAP. No later than mid May to be sure, and I'm losing confidence in being able to accomplish this myself.

Do you know anyone who can take a look at some sample files (10+ jpegs and a cvs) and help me put the framework together, including the necessary Perl declarations, etc... 

I'm using exiftool and the commander line on a weekly basis, using a script you help me with in a previous thread. However, I'm not clear on setting up the library within a Perl program, or even if I have to do that at all given the simplicity of the task.

Thanks,

-sd

Hayo Baan

I'm quite certain that parsing the csv file and then making the described changes with exiftool is doable. But it still sounds like a lot of hassle to me; you still have to create the csv file with the correct data. Instead why don't you make use of a good image browser to help you with adding the metadata?

Bridge or Lightroom for instance should be able to do it, and, if you need even more metadata power, have a look at PhotoMechanic by CameraBits too.
Hayo Baan – Photography
Web: www.hayobaan.nl

sjDelaney

Thanks Halo,

I already own and use LR, BR, PM, and spreadsheets.
I can discuss my workflow and other tools with you offline or in another forum.

I'm trying to automate a very time consuming "text-based" task using exif-tool.
Being a "newbie" with exif-tool (pearl, and OS X/Linux), I'm in this forum because I need help with coding a very specific application that can run unattended without pulling up thousands of thumbnails.

I'm very keen on discussing a one hour tutoring session with anyone who can help with initial setup of Perl and exif-tool lib on an MBP, and writing a small script based in the specs already described.

steve@sjdelaney.com

sjDelaney

Quote from: Phil Harvey on August 24, 2015, 08:22:15 AM

exiftool -if "$filename gt '20150716-121304' and $filename lt '20150716-121359'" -keywords=one -keywords=two ...

- Phil


What is the correct syntax for this using Image::ExifTool in a Perl Script?



Hayo Baan

If you're using Image::ExifTool you'll need to write your own file handling and load the image data for each file yourself too. While this gives you much more control, it is (much) more complex too. Unless you know how to program (Perl) and really need to use this type of additional control, perhaps not the best option.

Anyway to give some indication of answer to your question, the comparisons in the if can be done similar to what you state, $filename should just be replaced with what in your script you use for the filename. Setting the keywords is done with a call to SetNewValue on the exiftool object for your file. For more details, please see the Image::ExifTool documentation.
Hayo Baan – Photography
Web: www.hayobaan.nl

sjDelaney

Thanks Hayo,

I have a programming background, and am I am using Perl. But I am a beginner with Perl and ExifTool, hence I am still in this forum group.
I'm experienced with Assembly (Mainframe and PC), Fortran, COBOL, CICS, VB, C, C+, and various DB languages including SQL.

I chose to use Perl, because it is the native language Phil used to create ExifTool, I'm only interested in coding to support my own photography, and... what the heck, it looks like a cool language - maybe I'll get to meet Larry someday.

Below is what I have so far...  Disclaimer, it's not clean, there's lots of test code commented out, it's not elegant, and there may be libraries and variables I don't need to use.  Everything will get cleaned up in time.  Right now I'm focusing on end results

I am able to open, chomp, and parse the cvs array into variables. And I am able to find files (within range) using Find:File...   I want to use to ExifTool to open and update my files, and I'd prefer to ONLY use ExifTool to open (for read, write, or append) image files. 

Note the variables $previoustime and $currenttime are based on cvs input, and will be compared to exif data e.g. DateTimeOriginal and other fields that contain the same info.  So that while my file names are all based on date-time i.e. 20160215-081427.jpg with potential suffix i.e. 20160215-081427-2.jpg for mutliple shots taken within 1 second, I really want to find and update the right files based on exif data DateTimeOriginal or what ever meta data is appropriate.



---------------------------

#!/usr/bin/perl;
use strict;
use warnings;
use lib '/usr/local/bin/lib';
use File::Find::Rule;
use Image::ExifTool qw(:Public);

my $dh;
my $kw;
my $previoustime = '60000';
my $currenttime;


opendir($dh,"/Users/sjDelaney/Programming/Test Files") || die "Could not open '$dh' $!\n";
open($kw,"<","/Users/sjDelaney/Programming/Test Files/Keywords.csv") || die "Could not open '$kw' $!\n";

while (my $line = <$kw>) {

    chomp $line;
   
    my @fields = split "," , $line;
    print "~ ", $fields[1],": ", $fields[2], ": ", $fields[3],":",$fields[4],"\n";
    #chomp($currenttime);
    $previoustime = $currenttime;
    #chomp($previoustime);
   
    $currenttime = $fields[4];
    #print "$previoustime $currenttime \n";
    #print "$currenttime \n";
    #exiftool -if "$DateTimeOriginal gt $previoustime and $DateTimeOriginal le $currenttime";
    #my $info = $exifTool->ImageInfo('a.jpg')
    #my $info = $exifTool->GetInfo('$DateTimeOriginal');
  }

Phil Harvey

Once you know the names of the files you want to write, and the information you want to write to them, the ExifTool end of it is simple.


foreach $filename (@myFiles) {
    my $info = $exifTool->ImageInfo($filename, 'DateTimeOriginal');
    my $date = $$info{DateTimeOriginal}
    next unless $date and $date gt $startDate and $date lt $endDate;
    $exifTool->SetNewValue();  # clear previously queued values
    $exifTool->SetNewValue($tag1 => $value1);
    $exifTool->SetNewValue($tag2 => $value2);
    ...
    my $result = $exifTool->WriteInfo($filename);
}


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