ExifTool Forum

ExifTool => The "exiftool" Application => Topic started by: Kugelblitz on October 24, 2018, 05:40:46 AM

Title: One to rule them all - Big Photo Metadata Tag and Date cleanup
Post by: Kugelblitz on October 24, 2018, 05:40:46 AM
Hello,
Thank you for the exiftool. And the amazing support here! You guys are awesome!

I have about 200.000+ Images that I like to clean up the Tags / Keywords and the Date.
wonder if I can create a "if this to that" kind of exif command to cleanup all images.

Have uploaded a folder with sample images to my dropbox https://www.dropbox.com/sh/7o8n9zc2ajizn64/AAB_P-iS-65Y8cpuJ3GmnR3Aa?dl=0 (https://www.dropbox.com/sh/7o8n9zc2ajizn64/AAB_P-iS-65Y8cpuJ3GmnR3Aa?dl=0)

(https://exiftool.org/forum/index.php?action=dlattach;topic=9614.0;attach=2791)
- Fix encoding (red circels)
- get rid of to many keywords (blue crossed through)
- remove tags geo:lat= and geo:lon= (yellow highlight)
- equalise keyword separators (yellow highlighted "," and ";")
- change Filedate to Takendate (yellow highlight)

1st - MAKE THEM EQUAL

ENCODING
Some of the Metadata is encoded in different styles. Like "IPTC Encoding - Lation I (ANSI) (SP1252)"
I like to get them all to be converted to UTF-8

KEYWORD-SEPERATORS
I noticed the Tags (xmp-Subject / IPTC:Keywords) are seperated by differnet Seperators
sometimes comma "," is used sometimes semicolon ";" and sometimes even asterisk "*" 
I hope there is a defined standard for Separators that most programs understand and I love to set them to this "standard separator".
So Keywords shop up like "AUS,Australia,Sydney,AUS;Australia,Sydney"

I have tried to set it to a semicolon with this command but it did not always work.
-Sep ", " "-XPKeywords<${XPKeywords;s/\;/\,/g}" "-XMP:Subject<${XMP:Subject;s/\;/\,/g}" "-XMP:LastKeywordXMP<${XMP:LastKeywordXMP;s/\;/\,/g}"
I end up having all keywords separated with semicolons and then one block of the same keywords separated by comma too.
Wonder if that is the case cause it would create duplicate keywords?

(https://exiftool.org/forum/index.php?action=dlattach;topic=9614.0;attach=2793)

2nd - REMOVE DUPLICATE KEYWORDS
I like to remove all duplicate keywords too.
Have found this command
-sep "##" "-keywords<${keywords;NoDups}"



3rd - GEOSETTER - LOCATION DATA
In the past I had checked to add the Location Data to the Keywords in Geosetter. Which was not a good idea.
For that I had already opend a Topic here "The "exiftool" Application / In need of help to fix some Errors I got processing all files on my Photo drive. https://exiftool.org/forum/index.php/topic,9288.msg47994.html#msg47994 (https://exiftool.org/forum/index.php/topic,9288.msg47994.html#msg47994)"
You helped me already with removing "geo:lat=******" und "geo:lon=******" Keywords added by geosetter with this command
-sep xxx "-subject<${subject@;$_=undef if /^(geo:lat=|geo:lon=|ffffffffffffffff)/}" "-Keywords<${Keywords@;$_=undef if /^(geo:lat=|geo:lon=|ffffffffffffffff)/}"

That cleaned up the Tags quite a bit.
I love to take it a step further.

Geosetter has also added the Country Code, Country Name, Region/State, Location and City to the Tags/Keywords.
I think the County and City as Keywords is enough and I like to get rid of the keywords for the Country Code and Location
Because this data is also stored in the IPTC and XMP
iptc:Country-PrimaryLocationCode / Xmp:Country Code (AUS)
iptc:Country-PrimaryLocationName / Xmp:Country (Australia)
iptc:Province-State / xmp:State (New South Wales)
iptc:Sub-location / Xmp:Location (Newtown)
iptc:City / xmp:City (Sydney)

Is there any way to remove the Location Names from the Tags/keywords if the information is already in the right place in the Metadata. 

read the value of iptc:Country-PrimaryLocationCode and remove it from the keywords
read the value of iptc:Province-State and remove it from the keywords
read the value of iptc:Sub-location and remove it from the keywords
read the value of xmp:Country Code and remove it from the keywords
read the value of xmp:State and remove it from the keywords
read the value of xmp:Location and remove it from the keywords

EDIT ONLY IMAGES NO VIDEOS
I use this command to edit only the Image files and not the video Files.
-ext jpg -ext png -ext cr2 -ext dng -ext nef -ext nrw   --ext mov --ext avi --ext m4v --ext mp4

4th - FIX DATE
Picasa wrote the Filedate from the last edited date. I use this command to fix that.
"-DateTimeOriginal<CreateDate" "-DateTimeOriginal<CreateDate" "-FileCreateDate<CreateDate" "-FileModifyDate<CreateDate"

But some files like Scaned Images, Screenshots and so on do not have a Taken date.
Most of my Folders have this sceme "YYYY-MM-DD Location Event" 2018-10-24 Sydney beachday
I use this command to get the date from the folder and set the time to 12:00:00 o'clock so I know it is modified "by hand"

-if 'not $CreateDate' '-CreateDate<${directory;$_ = /(\d{4}-\d{2}-\d{2})/ ? "$1 12:00:00" : undef}'

5th some ADDITIONAL COMMANDS THAT I USE

do not create duplicates by overwriting the original file.
-overwrite_original

FORCE WRITE
-forcewrite=exif -m

WORK IN THIS FOLDER AND ALL SUBFOLDERS
-r

WRITE STATISTIC AS A TXT FILE
1>processed_files_list-2018-10-23.txt

WRITE A ERROR LOG AS A TXT FILE
2>error_log_2018-10-23.txt


Thank you very much
Title: Re: One to rule them all - Big Photo Metadata Tag and Date cleanup
Post by: Phil Harvey on October 24, 2018, 07:46:59 AM
Quote from: Kugelblitz on October 24, 2018, 05:40:46 AM
ENCODING
Some of the Metadata is encoded in different styles. Like "IPTC Encoding - Lation I (ANSI) (SP1252)"
I like to get them all to be converted to UTF-8

This would likely have to be done by hand since it is difficult programmatically to tell what the encoding should be.

QuoteKEYWORD-SEPERATORS
I noticed the Tags (xmp-Subject / IPTC:Keywords) are seperated by differnet Seperators
sometimes comma "," is used sometimes semicolon ";" and sometimes even asterisk "*" 

This is a problem.  XMP:Subject and IPTC:Keywords should not contain ANY separators.  If they do, they were written incorrectly.  The should be stored as individual items.  See FAQ 17 (https://exiftool.org/faq.html#Q17).

QuoteGeosetter has also added the Country Code, Country Name, Region/State, Location and City to the Tags/Keywords.
I think the County and City as Keywords is enough and I like to get rid of the keywords for the Country Code and Location
Because this data is also stored in the IPTC and XMP

Try this command:

Quoteread the value of iptc:Country-PrimaryLocationCode and remove it from the keywords
read the value of iptc:Province-State and remove it from the keywords
[...]

exiftool "-keywords-<iptc:Country-PrimaryLocationCode" "-keywords-<iptc:Province-State" ...

- Phil
Title: Re: One to rule them all - Big Photo Metadata Tag and Date cleanup
Post by: Kugelblitz on October 24, 2018, 03:35:40 PM
Hello Phil,
thank you for your time and helpful reply.

Think the best way is to break it down and tackle one task at a time.

I have tried to search and remove the CountryCode, Province-State, and Sublocation with this command.

"-keywords-<iptc:Country-PrimaryLocationCode"
"-keywords-<iptc:Province-State"
"-keywords-<iptc:Sub-location"
"-keywords-<xmp:CountryCode"
"-keywords-<xmp:State"
"-keywords-<xmp:Location"
"-subject-<iptc:Country-PrimaryLocationCode"
"-subject-<iptc:Province-State"
"-subject-<iptc:Sub-location"
"-subject-<xmp:CountryCode"
"-subject-<xmp:State"
"-subject-<xmp:Location"

exiftool "-keywords-<iptc:Country-PrimaryLocationCode" "-keywords-<iptc:Province-State" "-keywords-<iptc:Sub-location" "-keywords-<xmp:CountryCode" "-keywords-<xmp:State" "-keywords-<xmp:Location" "-subject-<iptc:Country-PrimaryLocationCode" "-subject-<iptc:Province-State" "-subject-<iptc:Sub-location" "-subject-<xmp:CountryCode" "-subject-<xmp:State" "-subject-<xmp:Location"  -overwrite_original -r E:\Tests\2018-10-23\test 1>processed_files_list-2018-10-23.txt 2>error_log_2018-10-23.txt

But it did not remove anything from the Tags.
Not with the Files that have the Tags listed correctly (one by one) and not with the Files that have the Tags not split correctly.

What have I missed?
Title: Re: One to rule them all - Big Photo Metadata Tag and Date cleanup
Post by: Kugelblitz on October 24, 2018, 03:43:09 PM
The Keyword separator sort of works.

exiftool -Sep ", " "-XPKeywords<${XPKeywords;s/\;/\,/g}" "-XMP:Subject<${XMP:Subject;s/\;/\,/g}" "-XMP:LastKeywordXMP<${XMP:LastKeywordXMP;s/\;/\,/g}" -overwrite_original -forcewrite=exif -m -r E:\Tests\2018-10-23\test 1>processed_files_list-2018-10-23.txt 2>error_log_2018-10-23.txt

BEFORE
(https://exiftool.org/forum/index.php?action=dlattach;topic=9614.0;attach=2796)

AFTER
(https://exiftool.org/forum/index.php?action=dlattach;topic=9614.0;attach=2798)

The Keywords are now correctly separated and listed underneath each other but one line with all the Keywords still exists (BEL, Belgien, Oostende, Turkijen, Vlaanderen).
How can I remove this "original" one before they have been separated ?
Title: Re: One to rule them all - Big Photo Metadata Tag and Date cleanup
Post by: Phil Harvey on October 24, 2018, 04:10:46 PM
This would be less confusing if you used ExifTool to read the metadata.  I don't know what the other software is showing, which makes it hard to help.

Quote from: Kugelblitz on October 24, 2018, 03:35:40 PM
But it did not remove anything from the Tags.
Not with the Files that have the Tags listed correctly (one by one) and not with the Files that have the Tags not split correctly.

What have I missed?

For this to work, the list items must be written separately and match exactly the value you are trying to remove.  To check if they are written separately, try extracting with exiftool -sep "XX" and see if they are separated by "XX".

Quote from: Kugelblitz on October 24, 2018, 03:43:09 PM
How can I remove this "original" one before they have been separated ?

Use ExifTool to see where the "original" value is stored, and write that tag.

- Phil
Title: Re: One to rule them all - Big Photo Metadata Tag and Date cleanup
Post by: Kugelblitz on October 25, 2018, 03:42:47 AM
Hello Phil,
thank you for your reply.

I had used geosetter to make the screenshots - Did not know how to extract the metadata with exiftool but I have looked it up.

exiftool shows this:

E:\Tests\2018-10-23\test>exiftool IMG_0800.JPG

ExifTool Version Number         : 10.96
File Name                       : IMG_0800.JPG
Directory                       : .
File Size                       : 2.1 MB
File Modification Date/Time     : 2016:07:13 13:20:40+02:00
File Access Date/Time           : 2018:10:25 09:07:44+02:00
File Creation Date/Time         : 2016:07:13 13:20:40+02:00
File Permissions                : rw-rw-rw-
File Type                       : JPEG
File Type Extension             : jpg
MIME Type                       : image/jpeg
Exif Byte Order                 : Big-endian (Motorola, MM)
Make                            : Apple
Camera Model Name               : iPhone 6s
Orientation                     : Horizontal (normal)
X Resolution                    : 72
Y Resolution                    : 72
Resolution Unit                 : inches
Software                        : 9.3.2
Modify Date                     : 2016:07:13 13:20:40
Y Cb Cr Positioning             : Centered
Exposure Time                   : 1/2137
F Number                        : 2.2
Exposure Program                : Program AE
ISO                             : 25
Time Zone Offset                : 2
Exif Version                    : 0221
Date/Time Original              : 2016:07:13 13:20:40
Create Date                     : 2016:07:13 13:20:40
Components Configuration        : Y, Cb, Cr, -
Shutter Speed Value             : 1/2137
Aperture Value                  : 2.2
Metering Mode                   : Average
Flash                           : Auto, Did not fire
Focal Length                    : 4.2 mm
Subject Area                    : 839 1292 1009 1013
Sub Sec Time Original           : 364
Sub Sec Time Digitized          : 364
Flashpix Version                : 0100
Color Space                     : sRGB
Exif Image Width                : 4032
Exif Image Height               : 3024
Sensing Method                  : One-chip color area
Scene Type                      : Directly photographed
Exposure Mode                   : Auto
White Balance                   : Auto
Digital Zoom Ratio              : 1.340425532
Focal Length In 35mm Format     : 39 mm
Scene Capture Type              : Standard
Lens Info                       : 4.15mm f/2.2
Lens Make                       : Apple
Lens Model                      : iPhone 6s back camera 4.15mm f/2.2
GPS Version ID                  : 2.2.0.0
GPS Altitude Ref                : Above Sea Level
GPS Time Stamp                  : 11:20:40
GPS Speed Ref                   : km/h
GPS Speed                       : 0
GPS Img Direction Ref           : True North
GPS Img Direction               : 317.3
GPS Map Datum                   : WGS-84
GPS Dest Bearing Ref            : True North
GPS Dest Bearing                : 317.3037975
GPS Date Stamp                  : 2016:07:13
GPS Horizontal Positioning Error: 5 m
Compression                     : JPEG (old-style)
Thumbnail Offset                : 1200
Thumbnail Length                : 9616
XMP Toolkit                     : Image::ExifTool 10.96
Country Code                    : BEL
Location                        : Turkijen
Subject                         : BEL, Belgien, Oostende, Turkijen, Vlaanderen
Date/Time Digitized             : 2016:07:13 13:20:40+02:00
Country                         : Belgien
State                           : Vlaanderen
Current IPTC Digest             : 8fbb56800a89dc3d627f9fc609659179
Application Record Version      : 4
Date Created                    : 2016:07:13
Time Created                    : 13:20:40+02:00
Keywords                        : BEL, Belgien, Oostende, Turkijen, Vlaanderen
City                            : Oostende
Sub-location                    : Turkijen
Province-State                  : Vlaanderen
Country-Primary Location Code   : BEL
Country-Primary Location Name   : Belgien
IPTC Digest                     : b443520a10119da99c2550175e6d0efb
Image Width                     : 4032
Image Height                    : 3024
Encoding Process                : Baseline DCT, Huffman coding
Bits Per Sample                 : 8
Color Components                : 3
Y Cb Cr Sub Sampling            : YCbCr4:2:0 (2 2)
Aperture                        : 2.2
Date/Time Created               : 2016:07:13 13:20:40+02:00
GPS Altitude                    : 11.9 m Above Sea Level
GPS Date/Time                   : 2016:07:13 11:20:40Z
GPS Latitude                    : 51 deg 14' 8.16" N
GPS Latitude Ref                : North
GPS Longitude                   : 2 deg 55' 1.25" E
GPS Longitude Ref               : East
GPS Position                    : 51 deg 14' 8.16" N, 2 deg 55' 1.25" E
Image Size                      : 4032x3024
Megapixels                      : 12.2
Scale Factor To 35 mm Equivalent: 9.4
Shutter Speed                   : 1/2137
Create Date                     : 2016:07:13 13:20:40.364
Date/Time Original              : 2016:07:13 13:20:40.364
Thumbnail Image                 : (Binary data 9616 bytes, use -b option to extract)
Circle Of Confusion             : 0.003 mm
Field Of View                   : 49.6 deg
Focal Length                    : 4.2 mm (35 mm equivalent: 39.0 mm)
Hyperfocal Distance             : 2.45 m
Light Value                     : 15.3


E:\Tests\2018-10-23\test>exiftool -sep "XX" E:\Tests\2018-10-23\test\IMG_0800.JPG

ExifTool Version Number         : 10.96
File Name                       : IMG_0800.JPG
Directory                       : E:/Tests/2018-10-23/test
File Size                       : 2.1 MB
File Modification Date/Time     : 2018:10:25 09:14:58+02:00
File Access Date/Time           : 2018:10:25 09:14:58+02:00
File Creation Date/Time         : 2016:07:13 13:20:40+02:00
File Permissions                : rw-rw-rw-
File Type                       : JPEG
File Type Extension             : jpg
MIME Type                       : image/jpeg
Exif Byte Order                 : Big-endian (Motorola, MM)
Make                            : Apple
Camera Model Name               : iPhone 6s
Orientation                     : Horizontal (normal)
X Resolution                    : 72
Y Resolution                    : 72
Resolution Unit                 : inches
Software                        : 9.3.2
Modify Date                     : 2016:07:13 13:20:40
Y Cb Cr Positioning             : Centered
Exposure Time                   : 1/2137
F Number                        : 2.2
Exposure Program                : Program AE
ISO                             : 25
Time Zone Offset                : 2
Exif Version                    : 0221
Date/Time Original              : 2016:07:13 13:20:40
Create Date                     : 2016:07:13 13:20:40
Components Configuration        : Y, Cb, Cr, -
Shutter Speed Value             : 1/2137
Aperture Value                  : 2.2
Metering Mode                   : Average
Flash                           : Auto, Did not fire
Focal Length                    : 4.2 mm
Subject Area                    : 839 1292 1009 1013
Sub Sec Time Original           : 364
Sub Sec Time Digitized          : 364
Flashpix Version                : 0100
Color Space                     : sRGB
Exif Image Width                : 4032
Exif Image Height               : 3024
Sensing Method                  : One-chip color area
Scene Type                      : Directly photographed
Exposure Mode                   : Auto
White Balance                   : Auto
Digital Zoom Ratio              : 1.340425532
Focal Length In 35mm Format     : 39 mm
Scene Capture Type              : Standard
Lens Info                       : 4.15mm f/2.2
Lens Make                       : Apple
Lens Model                      : iPhone 6s back camera 4.15mm f/2.2
GPS Version ID                  : 2.2.0.0
GPS Altitude Ref                : Above Sea Level
GPS Time Stamp                  : 11:20:40
GPS Speed Ref                   : km/h
GPS Speed                       : 0
GPS Img Direction Ref           : True North
GPS Img Direction               : 317.3
GPS Map Datum                   : WGS-84
GPS Dest Bearing Ref            : True North
GPS Dest Bearing                : 317.3037975
GPS Date Stamp                  : 2016:07:13
GPS Horizontal Positioning Error: 5 m
XP Keywords                     :
Compression                     : JPEG (old-style)
Thumbnail Offset                : 1212
Thumbnail Length                : 9616
XMP Toolkit                     : Image::ExifTool 10.96
Country Code                    : BEL
Location                        : Turkijen
Last Keyword XMP                :
Subject                         : BELXXBelgienXXOostendeXXTurkijenXXVlaanderen
Date/Time Digitized             : 2016:07:13 13:20:40+02:00
Country                         : Belgien
State                           : Vlaanderen
Current IPTC Digest             : 8fbb56800a89dc3d627f9fc609659179
Application Record Version      : 4
Date Created                    : 2016:07:13
Time Created                    : 13:20:40+02:00
Keywords                        : BEL, Belgien, Oostende, Turkijen, Vlaanderen
City                            : Oostende
Sub-location                    : Turkijen
Province-State                  : Vlaanderen
Country-Primary Location Code   : BEL
Country-Primary Location Name   : Belgien
IPTC Digest                     : b443520a10119da99c2550175e6d0efb
Image Width                     : 4032
Image Height                    : 3024
Encoding Process                : Baseline DCT, Huffman coding
Bits Per Sample                 : 8
Color Components                : 3
Y Cb Cr Sub Sampling            : YCbCr4:2:0 (2 2)
Aperture                        : 2.2
Date/Time Created               : 2016:07:13 13:20:40+02:00
GPS Altitude                    : 11.9 m Above Sea Level
GPS Date/Time                   : 2016:07:13 11:20:40Z
GPS Latitude                    : 51 deg 14' 8.16" N
GPS Latitude Ref                : North
GPS Longitude                   : 2 deg 55' 1.25" E
GPS Longitude Ref               : East
GPS Position                    : 51 deg 14' 8.16" N, 2 deg 55' 1.25" E
Image Size                      : 4032x3024
Megapixels                      : 12.2
Scale Factor To 35 mm Equivalent: 9.4
Shutter Speed                   : 1/2137
Create Date                     : 2016:07:13 13:20:40.364
Date/Time Original              : 2016:07:13 13:20:40.364
Thumbnail Image                 : (Binary data 9616 bytes, use -b option to extract)
Circle Of Confusion             : 0.003 mm
Field Of View                   : 49.6 deg
Focal Length                    : 4.2 mm (35 mm equivalent: 39.0 mm)
Hyperfocal Distance             : 2.45 m
Light Value                     : 15.3


Looks like it separates the items in the Subject line but not in the Keyword line.

Title: Re: One to rule them all - Big Photo Metadata Tag and Date cleanup
Post by: Phil Harvey on October 25, 2018, 07:18:57 AM
OK.  So you need to add Keywords to the command where you were separating the keywords.  You were just doing XPKeywords and Subject.

- Phil
Title: Re: One to rule them all - Big Photo Metadata Tag and Date cleanup
Post by: Kugelblitz on October 25, 2018, 08:37:45 AM
Hello Phil,
thank you for the Hint. As helpful as always.

I used the following command and now the Keywords are written separately.

exiftool -Sep ", " "-Keywords<${Keywords;s/\;/\,/g}" "-XPKeywords<${XPKeywords;s/\;/\,/g}" "-XMP:Subject<${XMP:Subject;s/\;/\,/g}" "-XMP:LastKeywordXMP<${XMP:LastKeywordXMP;s/\;/\,/g}" -overwrite_original E:\Tests\2018-10-23\test\IMG_0800.JPG

I have checked if they are written separately with the exiftool -sep "XX" command and they are separated by "XX".

E:\Tests\2018-10-23\test>exiftool -sep "XX" E:\Tests\2018-10-23\test\IMG_0800.JPG
ExifTool Version Number         : 10.96
File Name                       : IMG_0800.JPG
Directory                       : E:/Tests/2018-10-23/test
File Size                       : 2.1 MB
File Modification Date/Time     : 2018:10:25 14:17:48+02:00
File Access Date/Time           : 2018:10:25 14:17:48+02:00
File Creation Date/Time         : 2016:07:13 13:20:40+02:00
File Permissions                : rw-rw-rw-
File Type                       : JPEG
File Type Extension             : jpg
MIME Type                       : image/jpeg
Exif Byte Order                 : Big-endian (Motorola, MM)
Make                            : Apple
Camera Model Name               : iPhone 6s
Orientation                     : Horizontal (normal)
X Resolution                    : 72
Y Resolution                    : 72
Resolution Unit                 : inches
Software                        : 9.3.2
Modify Date                     : 2016:07:13 13:20:40
Y Cb Cr Positioning             : Centered
Exposure Time                   : 1/2137
F Number                        : 2.2
Exposure Program                : Program AE
ISO                             : 25
Time Zone Offset                : 2
Exif Version                    : 0221
Date/Time Original              : 2016:07:13 13:20:40
Create Date                     : 2016:07:13 13:20:40
Components Configuration        : Y, Cb, Cr, -
Shutter Speed Value             : 1/2137
Aperture Value                  : 2.2
Metering Mode                   : Average
Flash                           : Auto, Did not fire
Focal Length                    : 4.2 mm
Subject Area                    : 839 1292 1009 1013
Sub Sec Time Original           : 364
Sub Sec Time Digitized          : 364
Flashpix Version                : 0100
Color Space                     : sRGB
Exif Image Width                : 4032
Exif Image Height               : 3024
Sensing Method                  : One-chip color area
Scene Type                      : Directly photographed
Exposure Mode                   : Auto
White Balance                   : Auto
Digital Zoom Ratio              : 1.340425532
Focal Length In 35mm Format     : 39 mm
Scene Capture Type              : Standard
Lens Info                       : 4.15mm f/2.2
Lens Make                       : Apple
Lens Model                      : iPhone 6s back camera 4.15mm f/2.2
GPS Version ID                  : 2.2.0.0
GPS Altitude Ref                : Above Sea Level
GPS Time Stamp                  : 11:20:40
GPS Speed Ref                   : km/h
GPS Speed                       : 0
GPS Img Direction Ref           : True North
GPS Img Direction               : 317.3
GPS Map Datum                   : WGS-84
GPS Dest Bearing Ref            : True North
GPS Dest Bearing                : 317.3037975
GPS Date Stamp                  : 2016:07:13
GPS Horizontal Positioning Error: 5 m
Compression                     : JPEG (old-style)
Thumbnail Offset                : 1200
Thumbnail Length                : 9616
XMP Toolkit                     : Image::ExifTool 10.96
Country Code                    : BEL
Location                        : Turkijen
Subject                         : BELXXBelgienXXOostendeXXTurkijenXXVlaanderen
Date/Time Digitized             : 2016:07:13 13:20:40+02:00
Country                         : Belgien
State                           : Vlaanderen
Current IPTC Digest             : 072a5008353712a9b28715e3fff5fc36
Application Record Version      : 4
Date Created                    : 2016:07:13
Time Created                    : 13:20:40+02:00
Keywords                        : BELXXBelgienXXOostendeXXTurkijenXXVlaanderen
City                            : Oostende
Sub-location                    : Turkijen
Province-State                  : Vlaanderen
Country-Primary Location Code   : BEL
Country-Primary Location Name   : Belgien
IPTC Digest                     : b443520a10119da99c2550175e6d0efb
Image Width                     : 4032
Image Height                    : 3024
Encoding Process                : Baseline DCT, Huffman coding
Bits Per Sample                 : 8
Color Components                : 3
Y Cb Cr Sub Sampling            : YCbCr4:2:0 (2 2)
Aperture                        : 2.2
Date/Time Created               : 2016:07:13 13:20:40+02:00
GPS Altitude                    : 11.9 m Above Sea Level
GPS Date/Time                   : 2016:07:13 11:20:40Z
GPS Latitude                    : 51 deg 14' 8.16" N
GPS Latitude Ref                : North
GPS Longitude                   : 2 deg 55' 1.25" E
GPS Longitude Ref               : East
GPS Position                    : 51 deg 14' 8.16" N, 2 deg 55' 1.25" E
Image Size                      : 4032x3024
Megapixels                      : 12.2
Scale Factor To 35 mm Equivalent: 9.4
Shutter Speed                   : 1/2137
Create Date                     : 2016:07:13 13:20:40.364
Date/Time Original              : 2016:07:13 13:20:40.364
Thumbnail Image                 : (Binary data 9616 bytes, use -b option to extract)
Circle Of Confusion             : 0.003 mm
Field Of View                   : 49.6 deg
Focal Length                    : 4.2 mm (35 mm equivalent: 39.0 mm)
Hyperfocal Distance             : 2.45 m
Light Value                     : 15.3


so what is "the best" character to separate Keywords?
I personal do not like that comma "," semicolons ";" or tabs are used to split information in a database or cvs txt document - for the reason that these are very common punctuation marks that are easily used in the content as well. Unfortunately I do not know if there is a dedicated character or combination of charters to split Data in a file txt document. 


So now that the Keywords/Tags are correctly separated I have tried to remove them from "Subject" and "Keywords / XPKeywords" with the following command.
exiftool "-keywords-<iptc:Country-PrimaryLocationCode" "-keywords-<iptc:Province-State" "-keywords-<iptc:Sub-location" "-keywords-<xmp:CountryCode" "-keywords-<xmp:State" "-keywords-<xmp:Location" "-XPKeywords-<xmp:CountryCode" "-XPKeywords-<xmp:State" "-XPKeywords-<xmp:Location" "-XMP:Subject-<xmp:CountryCode" "-XMP:Subject-<xmp:State"  "-XMP:Subject-<xmp:Location" "-XMP:LastKeywordXMP-<xmp:CountryCode" "-XMP:LastKeywordXMP-<xmp:State" "-XMP:LastKeywordXMP-<xmp:Location" -overwrite_original E:\Tests\2018-10-23\test\IMG_0800.JPG

But that did not work. The Tags are still there.
E:\Tests\2018-10-23\test>exiftool E:\Tests\2018-10-23\test\IMG_0800.JPG
ExifTool Version Number         : 10.96
File Name                       : IMG_0800.JPG
Directory                       : E:/Tests/2018-10-23/test
File Size                       : 2.1 MB
File Modification Date/Time     : 2018:10:25 14:31:22+02:00
File Access Date/Time           : 2018:10:25 14:31:22+02:00
File Creation Date/Time         : 2016:07:13 13:20:40+02:00
File Permissions                : rw-rw-rw-
File Type                       : JPEG
File Type Extension             : jpg
MIME Type                       : image/jpeg
Exif Byte Order                 : Big-endian (Motorola, MM)
Make                            : Apple
Camera Model Name               : iPhone 6s
Orientation                     : Horizontal (normal)
X Resolution                    : 72
Y Resolution                    : 72
Resolution Unit                 : inches
Software                        : 9.3.2
Modify Date                     : 2016:07:13 13:20:40
Y Cb Cr Positioning             : Centered
Exposure Time                   : 1/2137
F Number                        : 2.2
Exposure Program                : Program AE
ISO                             : 25
Time Zone Offset                : 2
Exif Version                    : 0221
Date/Time Original              : 2016:07:13 13:20:40
Create Date                     : 2016:07:13 13:20:40
Components Configuration        : Y, Cb, Cr, -
Shutter Speed Value             : 1/2137
Aperture Value                  : 2.2
Metering Mode                   : Average
Flash                           : Auto, Did not fire
Focal Length                    : 4.2 mm
Subject Area                    : 839 1292 1009 1013
Sub Sec Time Original           : 364
Sub Sec Time Digitized          : 364
Flashpix Version                : 0100
Color Space                     : sRGB
Exif Image Width                : 4032
Exif Image Height               : 3024
Sensing Method                  : One-chip color area
Scene Type                      : Directly photographed
Exposure Mode                   : Auto
White Balance                   : Auto
Digital Zoom Ratio              : 1.340425532
Focal Length In 35mm Format     : 39 mm
Scene Capture Type              : Standard
Lens Info                       : 4.15mm f/2.2
Lens Make                       : Apple
Lens Model                      : iPhone 6s back camera 4.15mm f/2.2
GPS Version ID                  : 2.2.0.0
GPS Altitude Ref                : Above Sea Level
GPS Time Stamp                  : 11:20:40
GPS Speed Ref                   : km/h
GPS Speed                       : 0
GPS Img Direction Ref           : True North
GPS Img Direction               : 317.3
GPS Map Datum                   : WGS-84
GPS Dest Bearing Ref            : True North
GPS Dest Bearing                : 317.3037975
GPS Date Stamp                  : 2016:07:13
GPS Horizontal Positioning Error: 5 m
Compression                     : JPEG (old-style)
Thumbnail Offset                : 1200
Thumbnail Length                : 9616
XMP Toolkit                     : Image::ExifTool 10.96
Country Code                    : BEL
Location                        : Turkijen
Subject                         : BEL, Belgien, Oostende, Vlaanderen
Date/Time Digitized             : 2016:07:13 13:20:40+02:00
Country                         : Belgien
State                           : Vlaanderen
Current IPTC Digest             : eac8ac5b2471b03bf77f2f32cca4af0b
Application Record Version      : 4
Date Created                    : 2016:07:13
Time Created                    : 13:20:40+02:00
Keywords                        : BEL, Belgien, Oostende, Vlaanderen
City                            : Oostende
Sub-location                    : Turkijen
Province-State                  : Vlaanderen
Country-Primary Location Code   : BEL
Country-Primary Location Name   : Belgien
IPTC Digest                     : b443520a10119da99c2550175e6d0efb
Image Width                     : 4032
Image Height                    : 3024
Encoding Process                : Baseline DCT, Huffman coding
Bits Per Sample                 : 8
Color Components                : 3
Y Cb Cr Sub Sampling            : YCbCr4:2:0 (2 2)
Aperture                        : 2.2
Date/Time Created               : 2016:07:13 13:20:40+02:00
GPS Altitude                    : 11.9 m Above Sea Level
GPS Date/Time                   : 2016:07:13 11:20:40Z
GPS Latitude                    : 51 deg 14' 8.16" N
GPS Latitude Ref                : North
GPS Longitude                   : 2 deg 55' 1.25" E
GPS Longitude Ref               : East
GPS Position                    : 51 deg 14' 8.16" N, 2 deg 55' 1.25" E
Image Size                      : 4032x3024
Megapixels                      : 12.2
Scale Factor To 35 mm Equivalent: 9.4
Shutter Speed                   : 1/2137
Create Date                     : 2016:07:13 13:20:40.364
Date/Time Original              : 2016:07:13 13:20:40.364
Thumbnail Image                 : (Binary data 9616 bytes, use -b option to extract)
Circle Of Confusion             : 0.003 mm
Field Of View                   : 49.6 deg
Focal Length                    : 4.2 mm (35 mm equivalent: 39.0 mm)
Hyperfocal Distance             : 2.45 m
Light Value                     : 15.3



Title: Re: One to rule them all - Big Photo Metadata Tag and Date cleanup
Post by: Phil Harvey on October 25, 2018, 08:58:55 AM
Here is a test I ran here.  This should work for you too (although I might recommend updating to the most recent version of ExifTool):

> exiftool a.jpg -keywords="BEL, Belgien, Oostende, Vlaanderen" -sep ", "
    1 image files updated
> exiftool a.jpg -Country-PrimaryLocationCode=BEL
    1 image files updated
> exiftool a.jpg -keywords
Keywords                        : BEL, Belgien, Oostende, Vlaanderen
> exiftool a.jpg "-keywords-<iptc:Country-PrimaryLocationCode"
    1 image files updated
> exiftool a.jpg -keywords
Keywords                        : Belgien, Oostende, Vlaanderen


- Phil
Title: Re: One to rule them all - Big Photo Metadata Tag and Date cleanup
Post by: Kugelblitz on October 25, 2018, 10:02:16 AM
Hello Phil,
thanks again!

Have updated to the latest version of exiftool from today.

These lines worked individually! Thank you.


exiftool IMG_0800.JPG "-keywords-<iptc:Country-PrimaryLocationCode"
exiftool IMG_0800.JPG "-keywords-<iptc:Province-State"
exiftool IMG_0800.JPG "-keywords-<iptc:Sub-location"
exiftool IMG_0800.JPG "-XMP:Subject-<xmp:CountryCode"
exiftool IMG_0800.JPG "-XMP:Subject-<xmp:State"
exiftool IMG_0800.JPG "-XMP:Subject-<xmp:Location"


How can I combine all Commands in one big task?
Or build a batch that runs all the following commands on all Image Files in a folder and all subfolders?

-ext jpg -ext png -ext cr2 -ext dng -ext nef -ext nrw   --ext mov --ext avi --ext m4v --ext mp4
-Sep ", " "-XPKeywords<${XPKeywords;s/\;/\,/g}" "-XMP:Subject<${XMP:Subject;s/\;/\,/g}" "-XMP:LastKeywordXMP<${XMP:LastKeywordXMP;s/\;/\,/g
"-keywords-<iptc:Country-PrimaryLocationCode"
"-keywords-<iptc:Province-State"
"-keywords-<iptc:Sub-location"
"-XMP:Subject-<xmp:CountryCode"
"-XMP:Subject-<xmp:State"
"-XMP:Subject-<xmp:Location"
"-XMP:LastKeywordXMP-<xmp:CountryCode"
"-XMP:LastKeywordXMP-<xmp:State"
"-XMP:LastKeywordXMP-<xmp:Location"
"-keywords-<xmp:CountryCode"
"-keywords-<xmp:State"
"-keywords-<xmp:Location"
"-XPKeywords-<xmp:CountryCode"
"-XPKeywords-<xmp:State"
"-XPKeywords-<xmp:Location"
-sep "##" "-keywords<${keywords;NoDups}"
-sep xxx "-subject<${subject@;$_=undef if /^(geo:lat=|geo:lon=|ffffffffffffffff)/}" "-Keywords<${Keywords@;$_=undef if /^(geo:lat=|geo:lon=|ffffffffffffffff)/}" 
"-DateTimeOriginal<CreateDate" "-DateTimeOriginal<CreateDate" "-FileCreateDate<CreateDate" "-FileModifyDate<CreateDate"
-if 'not $CreateDate' '-CreateDate<${directory;$_ = /(\d{4}-\d{2}-\d{2})/ ? "$1 12:00:00" : undef}'
-forcewrite=exif -m
-overwrite_original
-r
1>processed_files_list-2018-10-23.txt
2>error_log_2018-10-23.txt
Title: Re: One to rule them all - Big Photo Metadata Tag and Date cleanup
Post by: Phil Harvey on October 25, 2018, 10:21:53 AM
Quote from: Kugelblitz on October 25, 2018, 10:02:16 AM
These lines worked individually!

You should be able do do these all in one command.

QuoteHow can I combine all Commands in one big task?

This would one way, but before doing something like this you need to get the constituent commands working properly:

exiftool -if "not $CreateDate" "-CreateDate<${directory;$_ = /(\d{4}-\d{2}-\d{2})/ ? qq($1 12:00:00) : undef}" -execute -Sep ", " "-XPKeywords<${XPKeywords;s/\;/\,/g}" "-XMP:Subject<${XMP:Subject;s/\;/\,/g}" "-XMP:LastKeywordXMP<${XMP:LastKeywordXMP;s/\;/\,/g}" -execute -sep "##" "-keywords<${keywords;NoDups}" -execute "-subject<${subject@;$_=undef if /^(geo:lat=|geo:lon=|ffffffffffffffff)/}" "-Keywords<${Keywords@;$_=undef if /^(geo:lat=|geo:lon=|ffffffffffffffff)/}" "-DateTimeOriginal<CreateDate" "-DateTimeOriginal<CreateDate" "-FileCreateDate<CreateDate" "-FileModifyDate<CreateDate" -execute "-keywords-<iptc:Country-PrimaryLocationCode" "-keywords-<iptc:Province-State" "-keywords-<iptc:Sub-location" "-XMP:Subject-<xmp:CountryCode" "-XMP:Subject-<xmp:State" "-XMP:Subject-<xmp:Location" "-XMP:LastKeywordXMP-<xmp:CountryCode" "-XMP:LastKeywordXMP-<xmp:State" "-XMP:LastKeywordXMP-<xmp:Location" "-keywords-<xmp:CountryCode" "-keywords-<xmp:State" "-keywords-<xmp:Location" "-XPKeywords-<xmp:CountryCode" "-XPKeywords-<xmp:State" "-XPKeywords-<xmp:Location" -common_args -r -overwrite_original -m -P -ext jpg -ext png -ext cr2 -ext dng -ext nef -ext nrw DIR

For such a long command, it may be easier to put the arguments in an argfile and use the -@ option:

exiftool -@ a.args -common_args -r -overwrite_original -m -P -ext jpg -ext png -ext cr2 -ext dng -ext nef -ext nrw DIR

with this a.args file:

-if
not $CreateDate
-CreateDate<${directory;$_ = /(\d{4}-\d{2}-\d{2})/ ? qq($1 12:00:00) : undef}
-execute
-Sep
,
-XPKeywords<${XPKeywords;s/\;/\,/g}
-XMP:Subject<${XMP:Subject;s/\;/\,/g}
-XMP:LastKeywordXMP<${XMP:LastKeywordXMP;s/\;/\,/g}
-execute
-sep
##
-keywords<${keywords;NoDups}
-execute
-subject<${subject@;$_=undef if /^(geo:lat=|geo:lon=|ffffffffffffffff)/}
-Keywords<${Keywords@;$_=undef if /^(geo:lat=|geo:lon=|ffffffffffffffff)/}
-DateTimeOriginal<CreateDate
-DateTimeOriginal<CreateDate
-FileCreateDate<CreateDate
-FileModifyDate<CreateDate
-execute
-keywords-<iptc:Country-PrimaryLocationCode
-keywords-<iptc:Province-State
-keywords-<iptc:Sub-location
-XMP:Subject-<xmp:CountryCode
-XMP:Subject-<xmp:State
-XMP:Subject-<xmp:Location
-XMP:LastKeywordXMP-<xmp:CountryCode
-XMP:LastKeywordXMP-<xmp:State
-XMP:LastKeywordXMP-<xmp:Location
-keywords-<xmp:CountryCode
-keywords-<xmp:State
-keywords-<xmp:Location
-XPKeywords-<xmp:CountryCode
-XPKeywords-<xmp:State
-XPKeywords-<xmp:Location


- Phil
Title: Re: One to rule them all - Big Photo Metadata Tag and Date cleanup
Post by: Kugelblitz on October 25, 2018, 12:03:15 PM
Thank God Phil..

I had created a slow batch "FOR /R %A IN (*.jpg *.png *.cr2 *.dng *.nef *.nrw ) DO (exiftool this "%A" & exiftool that "%A" & exiftool thatalso "%A") monster that worked but ran forever in my test directory.
exiftool -Sep ", " "-Keywords<${Keywords;s/\;/\,/g}" "-XPKeywords<${XPKeywords;s/\;/\,/g}" "-XMP:Subject<${XMP:Subject;s/\;/\,/g}" "-XMP:LastKeywordXMP<${XMP:LastKeywordXMP;s/\;/\,/g}" -overwrite_original E:\Tests\2018-10-23\test\

FOR /R %A IN (*.jpg *.png *.cr2 *.dng *.nef *.nrw ) DO (exiftool.exe "%A" "-keywords-<iptc:Country-PrimaryLocationCode" -overwrite_original & exiftool.exe "%A" "-keywords-<iptc:Province-State" -overwrite_original & exiftool.exe "%A" "-keywords-<iptc:Sub-location" -overwrite_original & exiftool.exe "%A" "-XMP:Subject-<xmp:CountryCode" -overwrite_original & exiftool.exe "%A" "-XMP:Subject-<xmp:State" -overwrite_original & exiftool.exe "%A" "-XMP:Subject-<xmp:Location" -overwrite_original & exiftool.exe "%A" "-XMP:LastKeywordXMP-<xmp:CountryCode" -overwrite_original & exiftool.exe "%A" "-XMP:LastKeywordXMP-<xmp:State" -overwrite_original & exiftool.exe "%A" "-XMP:LastKeywordXMP-<xmp:Location" -overwrite_original & exiftool.exe "%A" "-keywords-<xmp:CountryCode" -overwrite_original & exiftool.exe "%A" "-keywords-<xmp:State" -overwrite_original & exiftool.exe "%A" "-keywords-<xmp:Location" -overwrite_original & exiftool.exe "%A" "-XPKeywords-<xmp:CountryCode"  & exiftool.exe "%A" "-XPKeywords-<xmp:State" -overwrite_original & exiftool.exe "%A" "-XPKeywords-<xmp:Location" -overwrite_original & exiftool "%A" -sep "##" "-keywords<${keywords;NoDups}" -overwrite_original & exiftool "%A" -sep xxx "-subject<${subject@;$_=undef if /^(geo:lat=|geo:lon=|ffffffffffffffff)/}" "-Keywords<${Keywords@;$_=undef if /^(geo:lat=|geo:lon=|ffffffffffffffff)/}"  -overwrite_original & exiftool "%A" "-DateTimeOriginal<CreateDate" "-DateTimeOriginal<CreateDate" "-FileCreateDate<CreateDate" "-FileModifyDate<CreateDate" -overwrite_original)


I tried your code but it did not work right at first. The line with the "geo:lat" messed up the separators so I have put it before they are sorted in the a.args File. 
Filling in the missing taken date did not work.

-if
not $CreateDate
-CreateDate<${directory;$_ = /(\d{4}-\d{2}-\d{2})/ ? qq($1 12:00:00) : undef}
-execute
-subject<${subject@;$_=undef if /^(geo:lat=|geo:lon=|ffffffffffffffff)/}
-Keywords<${Keywords@;$_=undef if /^(geo:lat=|geo:lon=|ffffffffffffffff)/}
-execute
-sep
##
-keywords<${keywords;NoDups}
-execute
-Sep
,
-Keywords<${Keywords;s/\;/\,/g}
-XPKeywords<${XPKeywords;s/\;/\,/g}
-XMP:Subject<${XMP:Subject;s/\;/\,/g}
-XMP:LastKeywordXMP<${XMP:LastKeywordXMP;s/\;/\,/g}
-execute
-keywords-<iptc:Country-PrimaryLocationCode
-keywords-<iptc:Province-State
-keywords-<iptc:Sub-location
-XMP:Subject-<xmp:CountryCode
-XMP:Subject-<xmp:State
-XMP:Subject-<xmp:Location
-XMP:LastKeywordXMP-<xmp:CountryCode
-XMP:LastKeywordXMP-<xmp:State
-XMP:LastKeywordXMP-<xmp:Location
-keywords-<xmp:CountryCode
-keywords-<xmp:State
-keywords-<xmp:Location
-XPKeywords-<xmp:CountryCode
-XPKeywords-<xmp:State
-XPKeywords-<xmp:Location
-execute
-DateTimeOriginal<CreateDate
-DateTimeOriginal<CreateDate
-FileCreateDate<CreateDate
-FileModifyDate<CreateDate


Your code ran in a fraction of the time and is for sure the way better solution!
Thank You very very very very much Phil
Title: Re: One to rule them all - Big Photo Metadata Tag and Date cleanup
Post by: StarGeek on October 25, 2018, 12:13:18 PM
I hate to point this out after all that work, but XPKeywords is a semicolon separated string, not a list type tag as is Keywords and Subject.  But it is also a pretty useless tag, as only Windows reads it (as far as I've been able to tell) and I'd suggest just removing it altogether.
Title: Re: One to rule them all - Big Photo Metadata Tag and Date cleanup
Post by: Kugelblitz on October 26, 2018, 06:02:28 PM
Hello Phil,
Hello StarGeek,

thanks for your helpful replies.

Have tested the commands over and over again. For better "debugging" I have spitted the argfile into several files. "w-remove-tags-geolat-geolon.args", "w-separate-tags.args" and "time.args" work.
The args in "remove-geo-name-tags.args" work "individually" as single commands but not together in the args file.

To start it all I run the Command
exiftool -@ w-remove-tags-geolat-geolon.args -@ w-separate-tags.args -@ remove-geo-name-tags.args -common_args -r -overwrite_original -forcewrite=exif -m -P -ext jpg -ext png -ext cr2 -ext dng -ext nef -ext nrw "E:\Tests\2018-10-23\2018-10-23 test" 1>processed_files_list-2018-10-23.txt 2>error_log_2018-10-23.txt

With the content of these args Files.

w-remove-tags-geolat-geolon.args - works - removes the geolat and geolong and other unnecessary tags
-execute
-subject<${subject@;$_=undef if /^(geo:lat=|geo:lon=|ffffffffffffffff|iPhone|iphone)/}
-Keywords<${Keywords@;$_=undef if /^(geo:lat=|geo:lon=|ffffffffffffffff|iPhone|iphone)/}


w-separate-tags.args- works - Splits the line of Tags into individually separated tags.
-execute
-Sep
,
-Keywords<${Keywords;s/\;/\,/g}
-XMP:Subject<${XMP:Subject;s/\;/\,/g}
-XMP:LastKeywordXMP<${XMP:LastKeywordXMP;s/\;/\,/g}


remove-geo-name-tags.args - does not work right - shall remove the Geoname "CountryCode, State, Location" from the Tags but they still exist after the process.
I checked the Subject Tags and Keywords are correctly separated.

-execute
-XMP:Subject-<xmp:CountryCode
-XMP:Subject-<xmp:State
-XMP:Subject-<xmp:Location
-keywords-<iptc:Country-PrimaryLocationCode
-keywords-<iptc:Province-State
-keywords-<iptc:Sub-location
-keywords-<xmp:CountryCode
-keywords-<xmp:State
-keywords-<xmp:Location
-XMP:LastKeywordXMP-<xmp:CountryCode
-XMP:LastKeywordXMP-<xmp:State
-XMP:LastKeywordXMP-<xmp:Location


It does not work all together in the args file but each line works if I use them separately as a single command like here.

exiftool.exe "E:\Tests\2018-10-23\2018-10-23 test\" "-keywords-<xmp:CountryCode" -overwrite_original
exiftool.exe "E:\Tests\2018-10-23\2018-10-23 test\" "-XMP:Subject-<xmp:State" -overwrite_original
exiftool.exe "E:\Tests\2018-10-23\2018-10-23 test\" "-XMP:Subject-<xmp:Location" -overwrite_original

and so on..
Would be great if you give me a hint how that can work in the args file too.

time.args - is not in the command yet cause it is work in progress - the lines work but I am not sure yet what the best order will be. There are so many possible "Date" fields.
Create Date, Date/Time Original, GPS Date/Time , Date/Time Digitized, Modify Date, File Modification Date/Time, File Creation Date/Time
I want to preserve the oldest (original) Time of the File or if not possible get the Date from the Foldername.

So it will be a "if this is empty then use that. And if that is empty too then use this" Solution.
Also need to check if a time equal 12:00:00 because then I have set it manual and put in the "correct estimated date" of the picture.

-if
not $gpstimestamp
-gpstimestamp<datetimeoriginal"
-execute
-if
not $FileModifyDate
-FileModifyDate<${directory;$_ = /(\d{4}-\d{2}-\d{2})/ ? qq($1 12:00:00) : undef}
-execute
-if
not $FileCreateDate
-FileCreateDate<${directory;$_ = /(\d{4}-\d{2}-\d{2})/ ? qq($1 12:00:00) : undef}
-execute
-if
not $CreateDate
-CreateDate<FileModifyDate
-execute
-if
not $DateTimeOriginal
-DateTimeOriginal<FileModifyDate
-execute
-DateTimeOriginal<CreateDate
-DateTimeOriginal<CreateDate
-FileCreateDate<CreateDate
-FileModifyDate<CreateDate


This tool is so powerful!
Thank you guys.


Title: Re: One to rule them all - Big Photo Metadata Tag and Date cleanup
Post by: Phil Harvey on October 27, 2018, 08:10:33 AM
Sorry, I don't have time to read this right now.

I was hoping that you would have all the tools you needed to venture out on your own by now.  But if you still need help I'll be back tomorrow and check in on how things are going.  If you could keep your posts a bit shorter it would help.

- Phil
Title: Re: One to rule them all - Big Photo Metadata Tag and Date cleanup
Post by: Kugelblitz on October 29, 2018, 02:38:39 PM
Hey Phil,

yes you are absolutely right.
I appreciate the time and effort you take to help me.

Long Story Short. It all works except the "remove-geo-name-tags.args"
It shall remove the Geoname "CountryCode, State, Location" from the Tags but they still exist after the process.

-execute
-XMP:Subject-<xmp:CountryCode
-XMP:Subject-<xmp:State
-XMP:Subject-<xmp:Location
-keywords-<iptc:Country-PrimaryLocationCode
-keywords-<iptc:Province-State
-keywords-<iptc:Sub-location
-keywords-<xmp:CountryCode
-keywords-<xmp:State
-keywords-<xmp:Location
-XMP:LastKeywordXMP-<xmp:CountryCode
-XMP:LastKeywordXMP-<xmp:State
-XMP:LastKeywordXMP-<xmp:Location


I checked the Subject Tags and Keywords are correctly separated.
It does not work all together in the args file but each line works if I use them separately as a single command like here.


exiftool.exe "E:\Tests\2018-10-23\2018-10-23 test\" "-keywords-<xmp:CountryCode" -overwrite_original
exiftool.exe "E:\Tests\2018-10-23\2018-10-23 test\" "-XMP:Subject-<xmp:State" -overwrite_original
exiftool.exe "E:\Tests\2018-10-23\2018-10-23 test\" "-XMP:Subject-<xmp:Location" -overwrite_original
...


And I do not have a clue why it works as single commands but not in the args file.
Title: Re: One to rule them all - Big Photo Metadata Tag and Date cleanup
Post by: Phil Harvey on October 31, 2018, 06:30:03 AM
Your argfile works for me if I remove the leading -execute.

- Phil
Title: Re: One to rule them all - Big Photo Metadata Tag and Date cleanup
Post by: Kugelblitz on November 01, 2018, 09:20:29 AM
Hello Phil,

awesome that it works for you - so it is possible.

It just does not work here for me.

I made a 3min Video to show you all my process and hope you spot where I am wrong.
https://kisd.de/~martinb/foren/exiftool/debugging.mp4 (https://kisd.de/~martinb/foren/exiftool/debugging.mp4)

I have also attached all used files to this post.
The Image I tested with is this here
https://kisd.de/~martinb/foren/exiftool/IMG_0800.JPG (https://kisd.de/~martinb/foren/exiftool/IMG_0800.JPG)

Thank you for your patience, time and effort with me. Have donated a little tip for you.
Title: Re: One to rule them all - Big Photo Metadata Tag and Date cleanup
Post by: Phil Harvey on November 01, 2018, 09:43:00 AM
Hi Martin,

I need the image you used at the start of your test to be able to reproduce this.  The final image doesn't help.

- Phil
Title: Re: One to rule them all - Big Photo Metadata Tag and Date cleanup
Post by: Kugelblitz on November 01, 2018, 11:13:06 AM
Hello Phil,

sorry my fault.

have replaced the image in the link with the "before" image.
https://kisd.de/~martinb/foren/exiftool/IMG_0800.JPG (https://kisd.de/~martinb/foren/exiftool/IMG_0800.JPG)
Thank You
Title: Re: One to rule them all - Big Photo Metadata Tag and Date cleanup
Post by: Phil Harvey on November 01, 2018, 01:36:17 PM
Ah, OK.   Here we go:

> exiftool -@ w-separate-tags.args -overwrite_original "IMG_0800.JPG"
Warning: [minor] Tag 'XMP:LastKeywordXMP' not defined - IMG_0800.JPG
    1 image files updated
> exiftool -sep "xx" IMG_0800.JPG -subject -keywords
Subject                         : BELxxBelgienxxOostendexxTurkijenxxVlaanderen
Keywords                        : BELxxBelgienxxOostendexxTurkijenxxVlaanderen
> exiftool -@ remove-geo-name-tags.args -overwrite_original "IMG_0800.JPG"
    1 image files updated
> exiftool -sep "xx" IMG_0800.JPG -subject -keywords
Subject                         : BELxxBelgienxxOostendexxVlaanderen
Keywords                        : BELxxBelgienxxOostendexxVlaanderen
> exiftool -addtagsfromfile @ -@ remove-geo-name-tags.args -overwrite_original "IMG_0800.JPG"
    1 image files updated
> exiftool -sep "xx" IMG_0800.JPG -subject -keywords
Subject                         : BelgienxxOostende
Keywords                        : BelgienxxOostende


I should have thought of this (Note 5 from the -tagsFromFile documentation):

            5) The normal behaviour of copied tags differs from that of
            assigned tags for list-type tags and conditional replacements
            because each copy operation on a tag overrides any previous
            operations.  While this avoids duplicate list items when copying
            groups of tags from a file containing redundant information, it
            also prevents values of different tags from being copied into the
            same list when this is the intent.  So a -addTagsFromFile option
            is provided which allows copying of multiple tags into the same
            list.  eg)

                exiftool -addtagsfromfile @ '-subject<make' '-subject<model' ...

            Similarly, -addTagsFromFile must be used when conditionally
            replacing a tag to prevent overriding earlier conditions.

            Other than these differences, the -tagsFromFile and
            -addTagsFromFile options are equivalent.

The only reason it worked for me earlier is because I happened to test with only XMP:Location, which was the last item removed in your argfile.  Earlier items wouldn't have been removed.

- Phil
Title: Re: One to rule them all - Big Photo Metadata Tag and Date cleanup
Post by: Kugelblitz on November 03, 2018, 08:22:38 AM
Thank you Phil, it works
you can skip reading this post and continue with the next post where I write about 4th - FIX DATE that does not work yet.

Everyone else - this is the first part of the Documentation showing what and how it works.

Long Story Short - this is the Command
exiftool -@ w-remove-tags-geolat-geolon.args -@ w-separate-tags.args -execute -addtagsfromfile @ -@ w-remove-geo-name-tags.args -common_args -r -overwrite_original -forcewrite=exif -m -P -L "E:\Tests\2018-10-23\2018-10-23 test"  1>processed_files_list-2018-10-23.txt 2>error_log_2018-10-23.txt

the Command combines two Commands

exiftool -@ w-remove-tags-geolat-geolon.args -@ w-separate-tags.args and exiftool -addtagsfromfile @ -@ w-remove-geo-name-tags.args
one is infront of the execute and one is after the execute.

Both Commands run args files.
The first one "w-remove-tags-geolat-geolon.args" removes Tags in the Subject and Keyword Areas.
The second one "w-separate-tags.args" fixes the Keyword separation.
The third one "w-remove-geo-name-tags.args" removes Keywords that are already present in the Location Area.
I have attached the args files to this Post.

and the "-common_args" shows that everything after it belongs to both commands.
5th some ADDITIONAL COMMANDS THAT I USE
-common_args -r -overwrite_original -forcewrite=exif -m -P -L "E:\Tests\2018-10-23\2018-10-23 test"  1>processed_files_list-2018-10-23.txt 2>error_log_2018-10-23.txt

The Args Files fix the following issues from my first post.

3rd - GEOSETTER - LOCATION DATA
w-remove-tags-geolat-geolon.args
-execute
-subject<${subject@;$_=undef if /^(geo:lat=|geo:lon=|ffffffffffffffff|iPhone|iphone)/}
-Keywords<${Keywords@;$_=undef if /^(geo:lat=|geo:lon=|ffffffffffffffff|iPhone|iphone)/}
-XMP:regionpersondisplayname<${XMP:regionpersondisplayname@;$_=undef if /^(ffffffffffffffff)/}


and

w-remove-geo-name-tags.args
-XMP:Subject-<xmp:CountryCode
-XMP:Subject-<xmp:State
-XMP:Subject-<xmp:Location
-keywords-<iptc:Country-PrimaryLocationCode
-keywords-<iptc:Province-State
-keywords-<iptc:Sub-location
-keywords-<xmp:CountryCode
-keywords-<xmp:State
-keywords-<xmp:Location
-XMP:LastKeywordXMP-<xmp:CountryCode
-XMP:LastKeywordXMP-<xmp:State
-XMP:LastKeywordXMP-<xmp:Location


1st - MAKE THEM EQUAL
separate-tags.args
-execute
-Sep
,
-Keywords<${Keywords;s/\;/\,/g}
-XMP:Subject<${XMP:Subject;s/\;/\,/g}
-XMP:LastKeywordXMP<${XMP:LastKeywordXMP;s/\;/\,/g}


2nd - REMOVE DUPLICATE KEYWORDS
I have no Duplicate Keywords
Title: Re: One to rule them all - Big Photo Metadata Tag and Date cleanup
Post by: Kugelblitz on November 03, 2018, 08:49:22 AM
4th - FIX DATE

Most of this is not working yet and I have no clue how to do it right.
Basically I want nested "if this then that" Conditions that run different args depending on the outcome.

Long Story Short

Case A. Check if File has a Takendate
if the file has a Takendate - skip it.
-if
not $DateTimeOriginal


if it has no Takendate Check Case B

Case B.
Check if the time of the FilemodifyDate is equal to 12:00:00
-if
Time of the File eq 12:00:00
-CreateDate<FileModifyDate
-ModifyDate<FileModifyDate

if not Check Case C

Case C.
Check if the Folder name contains the same Date as the FilemodifyDate
-d "%Y-%m-%d"
-if
"$directory !~/^$FileModifyDate/"
-exif:CreateDate<${directory;$_ = /(\d{4}-\d{2}-\d{2})/ ? "$1 12:00:00" : undef}


Case C1
if Yes 
-CreateDate<FileModifyDate
-ModifyDate<FileModifyDate

Case C2
if not
-exif:CreateDate<${directory;$_ = /(\d{4}-\d{2}-\d{2})/ ? "$1 12:00:00" : undef} 

Long Story

Case A. Some of the Dates of the files are messed up by programs that overwrite the Filedate with the current date once they changed the file.
Like Picasa that is excellent in detecting faces and writing them into the metadata of the file.
That is not a big issue if the Files have a Takendate or Created Date - but some Pictures do not have that like Screenshots, Scanned Pictures and such.
So I like to check if the File has no Takendate and no Createdate
If that is the case go to the next condition

Case B.
In some files I have added the "estimated" date manually. For example of Scanned Photos. If that is the case I have put in the Time to noon. 12:00:00
So the second Condition is the Time shall not be equal to 12:00:00

Case C.
Some Files were not edited/Changed by any program and the Filedate is qual to the exact Date and Time they were taken.
To check if that is true I like to compare the Date of the Folder with the Date of the File.
The Foldername is in the sceme "YYYY-MM-DD Location Event" like (2017-12-31 Koblenz New Year)
So if the Filedate is equal to the date in the Folder then the Date and Time is correct so it shall be set as Creatdeate (maybe put it plus minus one day, cause sometimes Pictures that are taken after midnight are in the same folder - and they surley have not the same day. Guess that is difficult with the New year as a picture taken after midnight would have the date 2018-01-01.
Case C1.
So if the Filedate matches the Folderdate take the Filedate as the Takendate and Createdate.
Case C2.
If the Filedate does not match the Folderdate take the Date from the folder and write it to the file with the time 12:00:00 noon. So I know that has been set "manually" to this date.
-exif:CreateDate<${directory;$_ = /(\d{4}-\d{2}-\d{2})/ ? "$1 12:00:00" : undef} 

Title: Re: One to rule them all - Big Photo Metadata Tag and Date cleanup
Post by: Phil Harvey on November 03, 2018, 09:07:26 AM
Try this command:

exiftool -@ my.args -common_args -d %Y-%m-%d DIR

and this argfile:

-if
not $datetimeoriginal and $filemodifydate# !~ /12:00:00/ and $directory =~ /$FileModifyDate/
-CreateDate#<FileModifyDate#
-ModifyDate#<FileModifyDate#
-execute
-if
not $datetimeoriginal and $filemodifydate# !~ /12:00:00/ and $directory !~ /$FileModifyDate/
-exif:CreateDate#<${directory;$_ = /(\d{4}-\d{2}-\d{2})/ ? "$1 12:00:00" : undef}


- Phil
Title: Re: One to rule them all - Big Photo Metadata Tag and Date cleanup
Post by: Kugelblitz on November 04, 2018, 07:19:03 AM
Hello Phil,

thanks for your reply. It is a start but not the solution yet.
There are so many Date and Time Fields that makes it quite complicated.

Taken Date = ModifyDate = DateTimeOriginal = Create Date =  DateTimeDigitized = XMP ModifyDate
and
DateTimeCreated = XMP:DateCreated= CreateD Date = IPTC (DateCreated + TimeCreated)

how can I make sure that if I take the Values from one Filed to write to another field are not empty.
So That I do not loose any Data by running

"Field with information"<"Field with no Information"
Title: Re: One to rule them all - Big Photo Metadata Tag and Date cleanup
Post by: Phil Harvey on November 04, 2018, 07:53:59 AM
Quote from: Kugelblitz on November 04, 2018, 07:19:03 AM
So That I do not loose any Data by running

"Field with information"<"Field with no Information"

This won't happen.  If the tag on the right doesn't exist, then the argument has no effect.

- Phil
Title: Re: One to rule them all - Big Photo Metadata Tag and Date cleanup
Post by: Kugelblitz on November 04, 2018, 07:55:01 AM
or maybe there is a more intelligent approach by comparing all date and time Fields to each other and look for the "oldest" and take that as CreateDate and so on.
Title: Re: One to rule them all - Big Photo Metadata Tag and Date cleanup
Post by: Phil Harvey on November 04, 2018, 08:10:18 AM
The best way to do this would be a user-defined Composite tag.

- Phil
Title: Re: One to rule them all - Big Photo Metadata Tag and Date cleanup
Post by: Kugelblitz on November 04, 2018, 08:17:26 PM
Hello Phil,
thank you for the hint with the user-defined Composite tag.

Getting the Dates and times right with the conditions (if not defined / or / and) in several args files was sort of working but not always and got quite messy and time consuming. 
So I do not share the mess here.

Looking for the "user-defined Composite tags" here I found the solution in this post
set all to oldest known date https://exiftool.org/forum/index.php/topic,7986.msg40751.html#msg40751 (https://exiftool.org/forum/index.php/topic,7986.msg40751.html#msg40751)

oldest_datetime_config
%Image::ExifTool::UserDefined = (
    'Image::ExifTool::Composite' => {
        # Select oldest date from a number of date tags
        OldestDateTime => {
            Desire => {
                0 => 'FileModifyDate',
                1 => 'MDItemFSContentChangeDate',
                2 => 'FileCreateDate',
                3 => 'MDItemFSCreationDate',
                4 => 'ModifyDate',
                5 => 'CreateDate',
                6 => 'DateTimeCreated',
                7 => 'DateTimeOriginal',
8 => 'XMP:DateCreated',
9 => 'XMP:DateAcquired',
            },
            ValueConv => q{
                my $oldest = undef;
                for my $date (@val) {
                    next if not defined $date or $date lt '1970:01:02';
                    $date =~ s/[+-]\d{2}:\d{2}$//; # Strip TimeZone
                    if ($date && (!$oldest || $date lt $oldest)) {
                        $oldest = $date;
                    }
                }
                return $oldest;
            },
        },
    },
);

1;


exiftool Command
exiftool -config oldest_datetime_config -filename "-FileModifyDate<OldestDateTime" "-CreateDate<OldestDateTime" "-ModifyDate<OldestDateTime" -@ w-remove-tags-geolat-geolon.args -@ w-separate-tags.args -execute -addtagsfromfile @ -@ w-remove-geo-name-tags.args -common_args -r -overwrite_original -forcewrite=exif -m -P -L -v2 "E:\Tests\2018-10-23\2018-10-23 test"  1>processed_files_list-2018-10-23.txt 2>error_log_2018-10-23.txt

And that works well.
In the Post "set all to oldest known date" the dates "1.1.1970" shall be ignored.
I like to add something "similar" that all dates that have a time set to 12:00:00 noon are the "oldest date". So my manually edited dates are used. 

Guess when that works this Command is ready to run.
Title: Re: One to rule them all - Big Photo Metadata Tag and Date cleanup
Post by: Phil Harvey on November 06, 2018, 07:04:18 PM
Sorry for the delay.  Try this:

%Image::ExifTool::UserDefined = (
    'Image::ExifTool::Composite' => {
        # Select oldest date from a number of date tags
        OldestDateTime => {
            Desire => {
                0 => 'FileModifyDate',
                1 => 'MDItemFSContentChangeDate',
                2 => 'FileCreateDate',
                3 => 'MDItemFSCreationDate',
                4 => 'ModifyDate',
                5 => 'CreateDate',
                6 => 'DateTimeCreated',
                7 => 'DateTimeOriginal',
                8 => 'XMP:DateCreated',
                9 => 'XMP:DateAcquired',
            },
            ValueConv => q{
                my $oldest = undef;
                for my $date (@val) {
                    next if not defined $date or $date lt '1970:01:02';
                    $date =~ s/[+-]\d{2}:\d{2}$//; # Strip TimeZone
                    return $date if $date =~ / 12:00:00$/;
                    if ($date && (!$oldest || $date lt $oldest)) {
                        $oldest = $date;
                    }
                }
                return $oldest;
            },
        },
    },
);

1;


- Phil
Title: Re: One to rule them all - Big Photo Metadata Tag and Date cleanup
Post by: Kugelblitz on November 08, 2018, 11:35:59 AM
Hello Phil,

no worries - it is not urgent.
Thank you for your reply, looks like that code works great!

Will do a bigger test now coping about 10000 Pictures on Drive and running the command there to see that errors may occur.
Title: Re: One to rule them all - Big Photo Metadata Tag and Date cleanup
Post by: Kugelblitz on November 09, 2018, 03:41:59 AM
Ok the big test was a success so far.

I have copied my Picture Folder from the years 1978 till 2006 (13000 Images) cause they are most likely to have the wrong date as I did not have a Digital Camera back then.

Before the command ran I had 1027 Images with obviously the wrong date - that was newer than 2007 up till 2018.
After the command ran only 457 Images were left with the wrong date. Guess I just make a list out of these files and run the command to gather the Date from the Foldername just on these files.

Here are the most common Errors and Warnings in the log:
- Warning: Some character(s) could not be encoded in Latin -
I searched the forum for the error and found this.
If you drop the -L when copying Comment to FileName, you will avoid this warning.

I did not find a solution to thees errors/warnings yet

- Ignored superfluous tag name or invalid option: -filename
- Warning: Win32::API::SetFileTime returned 87
- Warning: Malformed UTF-8 character(s) -
- Warning: Invalid CanonCameraSettings data -


"Warning: JPEG format error" and "Error: JPEG EOI marker not found" and "Error: File is empty" are showing corrupted files. Guess these Images are broken.
Title: Re: One to rule them all - Big Photo Metadata Tag and Date cleanup
Post by: Phil Harvey on November 09, 2018, 07:18:01 AM
[quote author=Kugelblitz link=topic=9614.msg50137#msg50137 date=1541752919]
[b]- Ignored superfluous tag name or invalid option: -filename [/b]


There is a meaningless -filename argument somewhere in your command.

Quote- Warning: Win32::API::SetFileTime returned 87

I haven't seen this before, but Googling, it seems to indicate an invalid date.

Quote- Warning: Malformed UTF-8 character(s) -

Character encodings are often a problem in Windows.

Quote- Warning: Invalid CanonCameraSettings data -

This is an indication that the Canon makernotes were corrupted by editing with some other software.

Quote"Warning: JPEG format error" and "Error: JPEG EOI marker not found" and "Error: File is empty" are showing corrupted files. Guess these Images are broken.

Yup.

- Phil
Title: Re: One to rule them all - Big Photo Metadata Tag and Date cleanup
Post by: Kugelblitz on November 17, 2018, 05:02:26 PM
Hello Phil,

to save you some time - you can skip reading this - it is just for documentation.

I have decided to use my Mac to run the command to fix the "win32" and Character encoding issues.

The Command I used did not work in MacOS exactly as they worked in Windows.

So here is the update to use it with MacOS

exiftool -config oldest_datetime_config '-FileModifyDate<OldestDateTime' '-MDItemFSCreationDate<OldestDateTime' '-DateTimeOriginal<OldestDateTime' '-CreateDate<OldestDateTime' '-ModifyDate<OldestDateTime' '-IPTC:DateCreated<OldestDateTime' '-IPTC:DateCreated<OldestDateTime' '-IPTC:TimeCreated<OldestDateTime' -@ w-remove-tags-geolat-geolon.args -@ w-separate-tags.args -execute -addtagsfromfile @ -@ w-remove-geo-name-tags.args -common_args -ext jpg -ext png -ext tif -ext cr2 -ext dng -ext nef -ext nrw --ext mov --ext avi --ext m4v --ext mp4 --ext gif -r -overwrite_original -forcewrite=exif -m -P -v2 -iptc:codedcharacterset=utf8 '/Volumes/Stuff/Tests/Fotos/'  1>processed_files_list-2018-11-16.txt 2>error_log_2018-11-16.txt

I have attached the args to this post.