Move sidecar based on its source

Started by ejm554, September 24, 2018, 02:06:05 PM

Previous topic - Next topic

ejm554

I have a few thousand image and video files in a single directory that need to be separated into one of two subdirectories, e.g., either "pictures" or "movies."

Complicating this task is existence of sidecar files in this directory. Some are associated with the images, others with the videos. All use the same file extension (AAE).

And, as is standard convention, each sidecar's basename is identical to the basename of its source file. For example: IMG_0001.AAE <--> IMG_0001.JPG.

I'm trying to figure out how use ExifTool to move each sidecar into their appropriate subdirectory, "pictures" or "movies," and end up "beside" their source file.

One idea I had: Use ExifTool with piping to identify files with identical basenames and then write some temporary metadata to them, such as "JPG+AAE" or "MOV+AAE" in the macOS Finder Comments. I could then use temporary metadata to quickly determine a file's proper subdirectory.

However, I didn't get very far.For example, this group of commands will provide me with the basename of the first AAE file in my main directory ("IMG_0656"), but I couldn't figure out how to correctly use that value. I suspect that I started wading into the Common Mistake, "over-scripting!"

$ exiftool -csv -basename -extension AAE . | awk -F, '{print $2}' | awk 'NR==2'

Is there a way to do what I want to do?

Regards,
EJ

StarGeek

Hmmm...  this could be complicated.  Can you give an example of how your directory tree is going to be set up?

With an xmp sidecar file, it would normally be a two step process.  Use the -TagsFromFile option to get the necessary data from the xmp file and use the -ext option to limit the command to not process the sidecar files.  Then run a second command to move the sidecar files.

This is more complicated by the fact you want to separate pictures and movies.  An xmp sidecar file may not have a tag that would let you differentiate between the two.

Phil was planning on adding AAE read support but I don't think he's gotten around to it yet.

I think your best bet would be to use exiftool to create a temp file, based upon example four from the -if option.

exiftool -fast3 -ext mp4 -ext mov -p '$directory/$filename$/$directory/${filename;s/\.[^.]*$/.AAE/}' DIR >temp.txt
exiftool -@ temp.txt '-Directory</movies/$TAG' DIR

Breakdown:
The first command is used to create a temp file that holds a list of all the files to be processed, in this case, MOV, MP4, and AAE files.  The -fast option is used to prevent extraction of tags as all the first command cares about is the filenames.  The -ext option is used to limit the scope to the movie files.  Add/remove -ext to fit your files.  Then, the -p option to create a temporary text file which will have a list of all the files to be processed.  It prints the Directory/Filename of the movie, then a new line (the $/), then the Directory/Filename again, but removing the old extension and adding .AAE instead. 

The second command would use the -@ option to read the file list and then you set up the directory move to suit your needs.

You could then run a similar set of commands for the image files, using -ext JPG instead of -ext mp4 -ext mov.
"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

ejm554

#2
Thanks, StarGeek. I haven't had a chance to study your detailed reply, but did want to answer your first question.

Here is a screenshot that should illustrate the desired directory tree. Just imagine them with a lot more files. Assume that the two folders herein are the "subdirectories" mentioned in my original message and that the files originated in the containing directory.

One thing that you may have noticed: The last three "picture" files with the same basename (IMG_4537) includes a video file. The JPEG and MOV together make up an Apple Live Photo, where there's both a still image and a brief video. I already came up with a way to associate these JPEGs with their respective MOV files.


Phil Harvey

One way would be to do it as StarGeek suggested, and use the MimeType to separate the videos from the pictures:

1. exiftool '-directory<${mimetype;$_= /video/i ? "MoviesAndSidecars" : "PicturesAndSidecars"}' --ext aae -srcfile %d%f.AAE DIR

2. exiftool '-directory<${mimetype;$_= /video/i ? "MoviesAndSidecars" : "PicturesAndSidecars"}' --ext aae DIR

The first command moves the .AAE files if they exist for each video/picture file, then the second command moves the video/picture files.  These may be combined into one compound command:

exiftool -srcfile %d%f.AAE -execute -common_args '-directory<${mimetype;$_= /video/i ? "MoviesAndSidecars" : "PicturesAndSidecars"}' --ext aae DIR

I think this should do what you want, although I don't have time to test it right now.

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

StarGeek

The big problem on this is the case of img_4537, where there is a jpg, a mov, and an aae file, which I assume need to be kept together.

Maybe one pass with -ext jpg and use -srcfile %d%f.Mov to move the matching video files first, then your command Phil?
"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

ejm554

Hello. An update for you.

I tried StarGeek's code yesterday, and I was only able to get so far before I got stuck without time to troubleshoot.

I then tried Phil's code today, and it worked *great*. I don't understand Perl expressions, so I'm just left wondering *how* the code works. :-)

I came up with a workaround to the problem with the Apple Live Photos.

I did so by running the following command. It adds a custom macOS Finder tag, "AVType:AppleLivePhoto," to any JPG+MOV pair that makes up a Live Photo. Then, in the Finder, I dragged the tagged MOV files into the "PicturesAndSidecars" folder. With these MOV "picture" files out of the way, I could then run Phil's code without issue.

exiftool -r -MDItemUserTags+='AVType:AppleLivePhoto' -if '$ContentIdentifier' DIR

I'd love any thoughts on how to avoid this workaround in the future, perhaps by exploiting this custom macOS Finder tag, which I designed for a separate need. But I can live with the options thus far.

Thanks for the excellent support!

Kind Regards,
EJ




P.S. In case you are wondering, the Content Identifier tag is an Apple metadata element which indicates that a file is part of an individual Apple Live Photo. If a value exists, the file is (probably) part of a Live Photo; if it doesn't exist, it's (probably) not. Each JPEG shares an identical Content Identifier value with its MOV counterpart.

Example:

$ exiftool -G -ContentIdentifier IMG_9682*

======== IMG_9682.JPG
[MakerNotes]    Content Identifier              : C6BFB551-424D-41EA-B4F3-969EC5F79E3B
======== IMG_9682.MOV
[QuickTime]     Content Identifier              : C6BFB551-424D-41EA-B4F3-969EC5F79E3B
    2 image files read

Phil Harvey

StarGeek's idea of first moving the LivePhoto MOV files to the pictures directory should work.  So the process becomes:

1. exiftool '-directory=PicturesAndSidecars' -ext jpg -srcfile %d%f.MOV DIR

2. exiftool '-directory<${mimetype;$_= /video/i ? "MoviesAndSidecars" : "PicturesAndSidecars"}' --ext aae -srcfile %d%f.AAE DIR

3. exiftool '-directory<${mimetype;$_= /video/i ? "MoviesAndSidecars" : "PicturesAndSidecars"}' --ext aae DIR

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