Different destination depending on media type (photo or video)

Started by astromd, June 20, 2018, 11:33:38 AM

Previous topic - Next topic

astromd

Hi,

I am writing my first exiftool script and need a little bit of help. But first...awesome tool! It's amazing, really, the number of options and capabilities this supports.

Anyway, I have an incron table entry that fires a script when a new file is written to a specific folder. That script will rename the file using exiftool and organize it. The problem is that I need a different destination (-d) for video files than for images since I will upload them to different servers. I know I can probably do something ahead of exiftool in the script to look at the extension, but I wondered if it would be possible to do this in exiftool since it may be aware of what's a video vs image based on internal knowledge of the mime type.

Any ideas? Or can anyone point me in the right direction?

Phil Harvey

There are various ways to handle this, but the most obvious one is to use two separate commands:

exiftool -ext jpg -ext png -ext tif ... <do image stuff> DIR
exiftool -ext mov -ext mp4 -ext avi ... <do video stuff> DIR[/tt]

If you want, these could be combined into a single command line:

exiftool -ext jpg -ext png -ext tif ... <do image stuff> -execute -ext mov -ext mp4 -ext avi ... <do video stuff> -common_args DIR

You would incur a performance penalty if you tried to use a -if condition to test the MIME type of the file, although this is another possible method.

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

astromd

Thanks for the rapid response! The shell script is invoked on an individual file since it's fired when the file finished uploading and the filename is passed to the script. I'll look into the -if condition.

Phil Harvey

OK.  Another possible way would be something like this:

exiftool "-directory<${mimetype;$_=(/video/i ? 'some/video/directory' : 'some/other/directory')}" ... FILE

...which incurs the same performance penalty as the -if condition, but can be done in a single command instead of (likely) 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 ($).

astromd

Ok I will give this way a shot. When I run it combining the statements as you mentioned before, it doesn't work for JPG files but it does for MOV.

exiftool -ext jpg -ext JPG -d "${OUTGOING_DESTINATION_BASE}/photos/%Y/%m-%Y/%Y%m%d-%f.%%e"  -execute -ext mov -ext mp4 -ext m4v -ext MOV -d "${OUTGOING_DESTINATION_BASE}/videos/%Y/%m-%Y/%Y%m%d-%f.%%e" "-filename<DateTimeOriginal" "-filename<FileModifyDate" IMG_2669.JPG

No file with specified extension

astromd

Quote from: Phil Harvey on June 20, 2018, 12:22:04 PM
OK.  Another possible way would be something like this:

exiftool "-directory<${mimetype;$_=(/video/i ? 'some/video/directory' : 'some/other/directory')}" ... FILE

...which incurs the same performance penalty as the -if condition, but can be done in a single command instead of (likely) two.

- Phil

exiftool "-directory<${mimetype;$_=(/video/i ? '${OUTGOING_DESTINATION_BASE}/videos' : '${OUTGOING_DESTINATION_BASE}/photos')}" "-filename<DateTimeOriginal" "-filename<FileModifyDate" MG_2667.JPG

-bash: -directory<${mimetype;$_=(/video/i ? '${OUTGOING_DESTINATION_BASE}/videos' : '${OUTGOING_DESTINATION_BASE}/photos')}: bad substitution


StarGeek

If you want bash to expand a bash variable, it needs to be in double quotes while you want single quotes around the exiftool variables to prevent bash from trying to expand them (see Phil's .sig).

Try this.  I don't use bash, so you may need to play with the quotes a bit to get it right.
exiftool '-directory<${mimetype;$_=(/video/i ? '"'${OUTGOING_DESTINATION_BASE}/videos' : '${OUTGOING_DESTINATION_BASE}/photos')}" '-filename<DateTimeOriginal' '-filename<FileModifyDate' MG_2667.JPG
* 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).