Hello World! Support for moving a renaming on QNAP CLI

Started by mmggtt, April 12, 2023, 04:18:06 AM

Previous topic - Next topic

mmggtt

Ciao all from italy!
Truly amazing piece of code, vital nowadays to manage the outstanding amount of metadata me are fed by our devices...

I've set up exiftool on the background of my QNAP network NAS , running it via SSH terminal.
my idea is to have the qnap carriyng out a CRON to move the pictures to the right folder once they have been synce from the phone every night.

could I ask your precious support to build the CLI line for :

1. moving the file from a folder "A" to a structure of folders (that need to be created in case missing) located inside folder "B" with following structure B/YYYY/YYYYMM/filemane.ext

2. where the filename is : YYYYMMDD-filename.ext

thank you very much for your support!

Marco from italy.

Phil Harvey

Hi Marco,

I only have a minute right now to respond, but you can read here for more information about this feature.

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

mmggtt

thank you Phil, i will try in meanwhile if you would be able to help with the syntax will be great.
I'm currently experiencing and issue with the qnap build that seems not to be able to access to local folder that i'm also trying to solve but that's another story that is keeping me busy.

StarGeek

Try
exiftool -d '/path/to/B/%Y/%Y%m/%Y%m%d-%%f.%%e' '-Filename<DateTimeOriginal' /path/to/A/

This uses the -d (-dateFormat) option to create the target directory path and filename.  It also assumes these are from a camera that correctly embeds the DateTimeOriginal, which should be nearly every camera.  See Common Date Format Codes for the date codes.  The %f and %e codes are listed under the -w (-TextOut) option and need double % signs in the date format string.

This will fail on files that are not directly from the camera.  So things like screen shots, images from social media (Facebook, Instagram), and sent via text or What'sApp will either have such data stripped away or never had it in the first place.
"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

mmggtt

Quote from: StarGeek on April 12, 2023, 12:01:12 PMTry
exiftool -d '/path/to/B/%Y/%Y%m/%Y%m%d-%%f.%%e' '-Filename<DateTimeOriginal' /path/to/A/

This uses the -d (-dateFormat) option to create the target directory path and filename.  It also assumes these are from a camera that correctly embeds the DateTimeOriginal, which should be nearly every camera.  See Common Date Format Codes for the date codes.  The %f and %e codes are listed under the -w (-TextOut) option and need double % signs in the date format string.

This will fail on files that are not directly from the camera.  So things like screen shots, images from social media (Facebook, Instagram), and sent via text or What'sApp will either have such data stripped away or never had it in the first place.

thank you , works brilliantly.
two more thing,
-is there a way to point at the creation date? it is not processing the MOV files ,
-how to have exiftool scanning subfolders to look for file?

Many thanks!

Marco.

StarGeek

Quote from: mmggtt on April 19, 2023, 09:57:47 AM-is there a way to point at the creation date? it is not processing the MOV files

If you can identify the correct tag for the "creation date", then you can add that to the above command.  When there is more than one assignment to the same tag, in this case Filename, then the latter valid assignment will have priority.

Your "creation date" might be the FileCreateDate, the Quicktime:CreationDate, or the Quicktime:CreateDate. I'm guessing that it might be the FileCreateDate.  Adding that into the above command would look like

exiftool -d '/path/to/B/%Y/%Y%m/%Y%m%d-%%f.%%e' 'Filename<FileCreateDate' '-Filename<DateTimeOriginal' /path/to/A/

You would want to put it first because every file has a FileCreateDate and putting it last would mean that it would always be the assignment used.

Also, you should take note of the fact that some video timestamps are supposed to be set to UTC.  See this post starting at the 3rd paragraph for more details.

Quote-how to have exiftool scanning subfolders to look for file?

Use the -r (-recurse) option.
"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

mmggtt

Hello Again, i'm playing with it, these are the file data that exiftool is reading

ExifTool Version Number         : 12.51
File Name                       : IMG_4736.MOV
Directory                       : /share/homes/provaexif
File Size                       : 3.3 MB
File Modification Date/Time     : 2023:02:27 01:38:59+00:00
File Access Date/Time           : 2023:04:21 14:03:23+01:00
File Inode Change Date/Time     : 2023:04:21 14:03:15+01:00
File Permissions                : -rw-rw-rw-
File Type                       : MOV
File Type Extension             : mov
MIME Type                       : video/quicktime
Major Brand                     : Apple QuickTime (.MOV/QT)
Minor Version                   : 0.0.0
Compatible Brands               : qt
Media Data Size                 : 3318457
Media Data Offset               : 36
Movie Header Version            : 0
Create Date                     : 2023:02:26 12:12:12
Modify Date                     : 2023:02:26 12:12:13
Time Scale                      : 600
Duration                        : 1.55 s
Preferred Rate                  : 1
Preferred Volume                : 100.00%
Preview Time                    : 0 s
Preview Duration                : 0 s
Poster Time                     : 0 s
Selection Time                  : 0 s
Selection Duration              : 0 s
Current Time                    : 0 s
Next Track ID                   : 6
Track Header Version            : 0
Track Create Date               : 2023:02:26 12:12:12
Track Modify Date               : 2023:02:26 12:12:13
Track ID                        : 1
Track Duration                  : 1.55 s
Track Layer                     : 0
Track Volume                    : 0.00%
Image Width                     : 1920
Image Height                    : 1440
Clean Aperture Dimensions       : 1744x1308
Production Aperture Dimensions  : 1920x1440
Encoded Pixels Dimensions       : 1920x1440
Graphics Mode                   : ditherCopy
Op Color                        : 32768 32768 32768
Compressor ID                   : avc1
Source Image Width              : 1920
Source Image Height             : 1440
X Resolution                    : 72
Y Resolution                    : 72
Compressor Name                 : H.264
Bit Depth                       : 24
Video Frame Rate                : 19.251
Balance                         : 0
Audio Format                    : lpcm
Audio Channels                  : 3
Audio Bits Per Sample           : 16
Audio Sample Rate               : 1
Warning                         : [minor] The ExtractEmbedded option may find mo                                                                          re tags in the media data
Matrix Structure                : 1 0 0 0 1 0 0 0 1
Content Describes               : Track 1
Media Header Version            : 0
Media Create Date               : 2023:02:26 12:12:12
Media Modify Date               : 2023:02:26 12:12:13
Media Time Scale                : 600
Media Duration                  : 0.00 s
Media Language Code             : und
Gen Media Version               : 0
Gen Flags                       : 0 0 0
Gen Graphics Mode               : ditherCopy
Gen Op Color                    : 32768 32768 32768
Gen Balance                     : 0
Handler Class                   : Data Handler
Handler Vendor ID               : Apple
Handler Description             : Core Media Data Handler
Meta Format                     : mebx
Handler Type                    : Metadata Tags
Content Identifier              : C1C0C757-22A8-43BA-BBD8-687C01E9D8CA
Make                            : Apple
Model                           : iPhone XR
Software                        : 16.3.1
Creation Date                   : 2023:02:26 13:12:12+01:00
Image Size                      : 1920x1440
Megapixels                      : 2.8
Avg Bitrate                     : 17.1 Mbps
Rotation                        : 0

But when i launch the command pointing at the Create Date

exiftool -d '/share/homes/provaexif1/%Y/%Y%m/%Y%m%d-%%f.%%e' 'Filename<FileCreateDate' '-Filename<DateTimeOriginal' /share/homes/provaexif/
Warning: Error opening file - Filename<FileCreateDate
Error: File not found - Filename<FileCreateDate
Warning: [minor] The ExtractEmbedded option may find more tags in the media data - /share/homes/provaexif/IMG_4736.MOV
Warning: No writable tags set from /share/homes/provaexif/IMG_4736.MOV
    1 directories scanned
    0 image files updated
    1 image files unchanged
    1 files weren't updated due to errors

Phil Harvey

QuoteWarning: Error opening file - Filename<FileCreateDate

You forgot the hyphen before this argument.

QuoteWarning: No writable tags set from /share/homes/provaexif/IMG_4736.MOV

Apparently your filesystem doesn't store a creation date, try using FileModifyDate instead of FileCreateDate.

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

mmggtt

QuoteYou forgot the hyphen before this argument.
Thank you that worked it out


QuoteApparently your filesystem doesn't store a creation date, try using FileModifyDate instead of FileCreateDate.
With FileModifyDate works.

But then why its not using the DateTimeOriginal as apparently is capable to read it from the file (see code box in the above post)

Also what does this mean ?
Warning: [minor] The ExtractEmbedded option may find more tags in the media data

I'm trying to be selective on those file that comes from screenshots or whatsapp that i would not want exiftool to process, however if i use a FileModifyDate it will simply process it....how can i get round this ?

many thanks guys!





StarGeek

Quote from: mmggtt on April 21, 2023, 07:44:16 AMBut then why its not using the DateTimeOriginal as apparently is capable to read it from the file (see code box in the above post)

The DateTimeOriginal does not appear in the output listed above.  Use the command in FAQ #3 so you can see any tags with duplicate names, the groups they belong to, and the actual name of the tag,  not the description (FAQ #2).  You can list only the date/time tags with
exiftool -time:all -G -a -s /path/to/files/

QuoteAlso what does this mean ?
Warning: [minor] The ExtractEmbedded option may find more tags in the media data

This warning is the let you know that exiftool may not have listed all the metadata in the file. There might be additional data in the streams and the -ee (-extractEmbedded) option needs to be used to see if there is any additional data. In most cases, there might be a GPS track in the file.  This warning can be ignored unless you want to see any additional data.

QuoteI'm trying to be selective on those file that comes from screenshots or whatsapp that i would not want exiftool to process, however if i use a FileModifyDate it will simply process it....how can i get round this ?

If these files are of a specific filetype such as PNG files, then you can exclude processing of those file types with the -ext (-extension) option, e.g. --ext PNG.

If there are some PNGs you want to process or the files can't be distinguished by the type, then you will have to use the -if option to process only the files you want.  Unless you do something like moving all the screenshots/What's App files to a different directory.

IIRC, Whatsapp files have a WA followed by some numbers in the filename.  You could exclude those by adding this to the command
-if 'not $filename=~/WA\d+/'
This uses a Regular Expression (RegEx) to check if the filename has WA followed by some numbers \d+.  If that is true, the "not" flips it to false and that file would be skipped.

You'd have to tell us how to distinguish the screenshots if you don't know enough about regex to add that option.
"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