Search & replace in tags, bump time for multiple files sequentially

Started by mazeckenrode, June 06, 2020, 10:45:37 PM

Previous topic - Next topic

mazeckenrode

I deal with a fair amount of scanned multi-page documents and publications, or portions thereof. Unless and until I come up with a better way of creating metadata for them that is relevant and useful for my purposes, or someone suggests one to me, I've developed my own standard (though apologies if anyone else started using this same workflow before me):

Let's say I'm adding metadata to individual page images of a 10-page document (though most of these documents have been fewer pages, but a handful have been 20+ pages), which was completed being prepared by 5 PM on May 31st. The image files will have names such as "2020-05-31 17;00;00 - Document - 01.png", "2020-05-31 17;00;00 - Document - 02.png", etc.

1. I set appropriate EXIF/IPTC/XMP metadata fields for any and all Comment, Description, and Subject fields in all files to a suitable, common ("master") text string that includes the substring "p 1/10". I then (up until now) manually modify those fields for pages 2–10 to reflect what page they actually are ("p 2/10", "p 3/10", etc.).

2. Along with other appropriate entries, I set any and all Keywords fields to a master semi-colon-separated string which includes the substring "Page1", then manually modify that substring for pages 2–10.

3. I set EXIF/XMP:DateTimeOriginal and IPTC:DateCreated in all files to "2020:05:31 17:00:00", then manually bump the seconds down successively in pages 1–9, so that their times are 16:59:51 for page 1, through 16:59:59 for page 9.

I'm sure there must be a way for me to do some fancy scripting, probably using regular expressions, have EXIFTool extract the correct page number from each filename, find/replace each "p 1/10" with "p #/10" (without leading 0) in the Comment/Description/Subject fields of pages 2–10, find/replace each "Page1" with "Page#" (also without leading 0) in the Keywords fields, and programmatically bump the seconds down as necessary for pages 1–9 using some kind of loop construct.

I'm currently using the stand-alone Windows executable of EXIFTool v11.95. I have some familiarity with regular expressions, mostly as it's used in Notepad++ and Directory Opus, a little bit with Python (via the Python Script plugin for Notepad++), but none with EXIFTool beyond having visited a few forum threads which deal with it to various degrees. I haven't managed to extract enough useful information from the threads to put me on solid footing for getting started. Any suggestions or pointers to better and/or more specific resources?

mazeckenrode

Ok, so I'm trying to make sense of various examples of ExifTool usage with regular expressions, but much of what I'm seeing doesn't quite correlate with what I'm used to (from Notepad++, Directory Opus, etc.), and I can't find anything in the documentation to explain the things that are eluding me, or even about ExifTool's regex syntax and usage in general. For example:

https://exiftool.org/forum/index.php?topic=10200.msg57361#msg57361

In this post by StarGeek  on 30 Jan 2020), the following code is suggested, which uses regex to extract a substring from a filename and write it to a Comment tag:

-comment<${filename;m/\[([^]]+)\]/;$_=$1}

An informative breakdown is given, but it doesn't explain EVERYTHING, to me, anyway. In particular, I don't know what exactly ;m/ and /;$_=$1 do, and don't see anything like them in the documentation, though maybe I just don't know where to look. Searching the documentation for "regular expressions" or "regex" was fruitless.

Another example:

https://exiftool.org/forum/index.php?topic=10599.msg56159#msg56159

Posted by Phil on 15 Nov 2019, the following code is suggested, which extracts a date string from a filename and uses it to set DateTimeOriginal:

exiftool "-datetimeoriginal<${filename;s/WA.*//}000000" DIR

User xiftheflour then asks what ;s/ and .*// do, to which StarGeek replies that "s/WA.*// is a Regular Expression (RegEx) substitution. It substitutes what is matched between the first and second slashes with what is between the second and third slashes."

So the ;s/ is part of ExifTool's regex syntax for initiating such a substitution? Where can I find documentation which explains that, and other fine points of ExifTool's regex implementation?

StarGeek ends his post: "RegEx is a complex subject all by itself and there are plenty of tutorials on the web if you wish to learn more." But which tutorial(s) are specifically relevant to using it with ExifTool on the command line?

Looking at both (and other) examples, I'm thinking that the first and last / mark the boundaries of the regex matching expression code, right?

In Notepad++, I would have used this code to match the same thing:

(.*)WA.*

Anybody?

StarGeek

Quote from: mazeckenrode on June 08, 2020, 12:11:29 PM
Ok, so I'm trying to make sense of various examples of ExifTool usage with regular expressions, but much of what I'm seeing doesn't quite correlate with what I'm used to (from Notepad++, Directory Opus, etc.)

The regex you want to search on would be Perl Regex.  For the most part, it should be the same as with Notepad++.  I can't really think of any differences offhand except Perl's lower/uppercase modifiers.  I often use the same regex in both exiftool and Notepad++.  You can also use sites like RegEx101.com to test things out.

QuoteIn this post by StarGeek  on 30 Jan 2020), the following code is suggested, which uses regex to extract a substring from a filename and write it to a Comment tag:

-comment<${filename;m/\[([^]]+)\]/;$_=$1}

An informative breakdown is given, but it doesn't explain EVERYTHING, to me, anyway. In particular, I don't know what exactly ;m/ and /;$_=$1 do, and don't see anything like them in the documentation, though maybe I just don't know where to look. Searching the documentation for "regular expressions" or "regex" was fruitless.

This is perl code.  The m/<regex>/ is a perl RegEx Match expression.  It just checks for a match, possibly with capture groups.  In that example it captures the text between two brackets.  This gets saved to the $1 variable. The semicolon is what Perl uses to indicate the end of a command.  The next command assigns the capture variable to Perl's default variable.  When used inside the braces of a tag name in exiftool, this default variable will start with the value of the tag.  So, altogether, this command takes the value of the Filename tag, does a RegEx match for the text between two brackets, captures that text, and then assigns it to the Filename tag.

QuotePosted by Phil on 15 Nov 2019, the following code is suggested, which extracts a date string from a filename and uses it to set DateTimeOriginal:

exiftool "-datetimeoriginal<${filename;s/WA.*//}000000" DIR

User xiftheflour then asks what ;s/ and .*// do, to which StarGeek replies that "s/WA.*// is a Regular Expression (RegEx) substitution. It substitutes what is matched between the first and second slashes with what is between the second and third slashes."

So the ;s/ is part of ExifTool's regex syntax for initiating such a substitution? Where can I find documentation which explains that, and other fine points of ExifTool's regex implementation?

Again, this is Perl.  In this case a substitution instead of a simple match.

QuoteStarGeek ends his post: "RegEx is a complex subject all by itself and there are plenty of tutorials on the web if you wish to learn more." But which tutorial(s) are specifically relevant to using it with ExifTool on the command line?

Any Perl tutorial would be relevant.  I learned the basics of RegEx through Regular-Expressions.info which isn't specifically about Perl, but does mention it frequently.  perldoc.perl.org is the documentation for Perl, but I find it is more technically and less of a tutorial.  I learned the most from PerlMaven.com and lots of copy/pasting from various StackExchange questions.

QuoteLooking at both (and other) examples, I'm thinking that the first and last / mark the boundaries of the regex matching expression code, right?
Yes.  If you look at RegEx testing sites like RegEx101 and RegExr.com, they even have the slashes as part of the input fields.  See this tutorial (only just found it).

QuoteIn Notepad++, I would have used this code to match the same thing:
(.*)WA.*

You could use that, but then you have to add $1 in the Replace With box.  The original WA.* could be directly placed in the Notepad++ Find What box and the Replace With box would be left blank.
"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

mazeckenrode

Quote from: StarGeek on June 08, 2020, 01:51:58 PMThe regex you want to search on would be Perl Regex. For the most part, it should be the same as with Notepad++.

Thanks much for all the detailed info. I guess my use of regex is limited enough that once I learned one way of doing things in it, I skipped past any alternate methods. All the regex I've done has been with \1 etc. for capture variables, and I've never had reason to know about or use ;m/ or ;s/. I think I now have enough to actually make some headway — though don't be surprised if I need to check in again for something!

mazeckenrode

Some progress, and not, with this project so far...

Successfully used this to set several date/time tags from part of filename:

exiftool "-XMP:DateTimeOriginal<${filename;s/ - Document - *//}" "-EXIF:DateTimeOriginal<${filename;s/ - Document - *//}" "-IPTC:DateCreated<${filename;s/ - Document - *//}" .

Will probably make a shortcut for all three tags in config soon.

Based on examples seen at https://exiftool.org/forum/index.php?topic=11183.0 , tried using the following code to replace 1, in substring p 1/10, with 2:

exiftool -tagsfromfile @ -XMP:UserComment -EXIF:XPComment -api "filter=s/p \d+\/10\..*/2/g" .

...but getting warning: [minor] Fixed incorrect list type for XMP-exif:UserComment.

Note that I am using Directory Opus to initially set any metadata in these files, then intend to use ExifTool to selectively modify them. The reason I do it that way is because I want the metadata to be visible in Directory Opus, but DOpus expects it to be in other than the officially specified location in PNGs, as outlined in https://exiftool.org/forum/index.php?topic=9262.0 , and ExifTool will reportedly update it in the same location. When I place content in DOpus' metadata field named Comment, then use ExifTool to see what went where, it tells me that the same text went to both XMP:UserComment and EXIF:XPComment.

ExifTool's page for XMP tags ( https://exiftool.org/TagNames/XMP.html ) says that XMP:UserComment is a lang-alt field. EXIF tags page ( https://exiftool.org/TagNames/EXIF.html ) states EXIF:XPComment is an int8u field, but don't see an explanation of it there. Unclear how either of those figure into the warning above.

Anyway, I'm trying to cobble together a string of code that will replace the page number in either/all Comment tags (within substring p #/#) with the page number extracted from the filename (using regex). I've found examples of setting a tag's value to something extracted from filename or other tag via regex, and of setting tag's value via -tagsfromfile, but I'm not finding any examples similar enough to what I want to do, and am not looking to get any tag data from a file other than the one being operated on. Not possible?

StarGeek

Quote from: mazeckenrode on June 10, 2020, 02:39:33 PM
exiftool -tagsfromfile @ -XMP:UserComment -EXIF:XPComment -api "filter=s/p \d+\/10\..*/2/g" .

...but getting warning: [minor] Fixed incorrect list type for XMP-exif:UserComment.

Minor warning which you can ignore.  That tag was written incorrectly.  Exiftool fixed.

QuoteExifTool's page for XMP tags ( https://exiftool.org/TagNames/XMP.html ) says that XMP:UserComment is a lang-alt field. EXIF tags page ( https://exiftool.org/TagNames/EXIF.html ) states EXIF:XPComment is an int8u field, but don't see an explanation of it there. Unclear how either of those figure into the warning above.

It should be pointed out that XMP:UserComment is the XMP version of the EXIF:UserCommentXPComment is the Microsoft version of EXIF:UserComment.  It's not common for software to read XPComment, though there is some.

QuoteAnyway, I'm trying to cobble together a string of code that will replace the page number in either/all Comment tags (within substring p #/#) with the page number extracted from the filename (using regex). I've found examples of setting a tag's value to something extracted from filename or other tag via regex, and of setting tag's value via -tagsfromfile, but I'm not finding any examples similar enough to what I want to do, and am not looking to get any tag data from a file other than the one being operated on. Not possible?

I'm not quite following.  Can you give an example?
"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

mazeckenrode

Quote from: StarGeek on June 10, 2020, 05:41:41 PMMinor warning which you can ignore. That tag was written incorrectly. Exiftool fixed.

Actually, it did not update the tags, that I recall (not at that computer just now, but I'll verify later), according to new JSONs I vaguely remember exporting following the operation. At least, the previous values were still being displayed by Directory Opus.

QuoteIt should be pointed out that XMP:UserComment is the XMP version of the EXIF:UserComment. XPComment is the Microsoft version of EXIF:UserComment.

This is a rhetorical question unless you happen to know the answer, but why have a Microsoft version that is also an EXIF tag?

Also, can you tell me what int8u means? I'm guessing it's something to do with Unicode. Any idea why I got the warning for exiftool -tagsfromfile @ -XMP:UserComment -EXIF:XPComment -api "filter=s/p \d+\/10\..*/2/g" .?

QuoteI'm not quite following. Can you give an example?

In my first post in this thread, I gave an example of 10 document page scans named "2020-05-31 17;00;00 - Document - 01.png", "2020-05-31 17;00;00 - Document - 02.png", etc. I would first set the relevant Comment, Description, and Subject tags to something like Document XYZ, prepared by John Q Public, 31 May 2020, 17:00:00, p 1/10, using Directory Opus. I would like to then be able to run an ExifTool command line/batch/script which replaces p 1/10 in pages 2–10 with p 2/10...p 10/10.

I'd also like to have my procedure shift the seconds for EXIF/XMP:DateTimeOriginal and IPTC:DateCreated in pages 1–9 so that each page is tagged as one second later than the previous page, with the final result as below:

Page 1: 16:59:01
Page 2: 16:59:02
...
Page 10: 17:00:00

The correct number of seconds to shift down for each page could be calculated from <numberofpages> - <pagenumber>, and I assume I'd need some kind of script to accomplish it in a loop. I just started playing with Python, but all my effort with it so far has been limited to regex in Notepad++. Any reason I couldn't do what I need with Python? I'm aware that ExifTool itself is Perl (I'm using the Windows executable version). I'm open to recommendations, but wish to minimize how many different script languages I need to familiarize myself with. Ultimately, I want to be able to launch it from within Directory Opus.

Phil Harvey

Quote from: mazeckenrode on June 10, 2020, 08:49:14 PM
Also, can you tell me what int8u means?

Unsigned 8-bit integer.

QuoteAny idea why I got the warning for exiftool -tagsfromfile @ -XMP:UserComment -EXIF:XPComment -api "filter=s/p \d+\/10\..*/2/g" .?

The UserComment tag should be a lang-alt list in XMP.  If ExifTool warns about an incorrect list type, then it wasn't a lang-alt list as it should have been in the original file.

- 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

Quote from: mazeckenrode on June 10, 2020, 08:49:14 PM
This is a rhetorical question unless you happen to know the answer, but why have a Microsoft version that is also an EXIF tag?

Back in the XP days (I think), Microsoft made a few tags, XPAuthor, XPComment, XPKeywords, XPSubject, and XPTitle, even though there were already comparable tags in other official specs. I don't know why and your question got me curious.  But I couldn't find any information in my google searches.  In fact, most search results on these tags ended up mentioning exiftool in some way.

QuoteI would like to then be able to run an ExifTool command line/batch/script which replaces p 1/10 in pages 2–10 with p 2/10...p 10/10.

Ah, ok, a bit long and messy because you have to split each tag and insert the results of Filename in between, but something like
"-UserComment<${Usercomment;s/\d+\/\d+$//}${Filename;m/0*(\d+)\./;$_=$1}/${UserComment;m/(\d+$)/;$_=$1}"
or
"-UserComment<${Usercomment;my $temp=$1 if $self->GetValue('FileName')=~m/0*(\d+)\./;s/\d+(\/\d+$)/$temp$1/}"
Repeat for each tag, replacing UserComment with the other tag names.  Test carefully, any variation from the format you listed (extra spaces for example) may end up with unexpected results.

QuoteI'd also like to have my procedure shift the seconds for EXIF/XMP:DateTimeOriginal and IPTC:DateCreated in pages 1–9 so that each page is tagged as one second later than the previous page, with the final result as below:

IPTC:DateCreated doesn't have a time component, so I assume you mean IPTC:TimeCreated, unless you mean XMP:DateCreated, which is part of the IPTC Core schema and does have a time component.  That could be done with
"-DateTimeOriginal+<+<0:0:${Filename;m/0*(\d+)\./;$_=$1}"

QuotePage 1: 16:59:01
Page 2: 16:59:02
...
Page 10: 17:00:00

Don't you mean "Page 10: 16:59:10" ?  Because otherwise I don't understand your math here.  Plus one second except for the last page where it's +1 minute?  What if there is more than 60 pages?

"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

mazeckenrode

Quote from: Phil Harvey on June 10, 2020, 09:09:57 PMUnsigned 8-bit integer.

EXIF:XPComment is supposed to be an unsigned 8-bit integer, but is the Microsoft version of EXIF:UserComment, which is undefined (presumably a string)? What would an integer placed in EXIF:XPComment represent?

QuoteThe UserComment tag should be a lang-alt list in XMP.

It seems that some tags' names are hardly descriptive of their intended purposes. Anyway, if Directory Opus is inserting the same value into both XMP:UserComment and EXIF:XPComment, but leaving EXIF:UserComment alone, is that an example of DOpus' metadata library not keeping up with current specs, or abusing its privileges?

I don't suppose it's possible to force ExifTool to write XMP:UserComment as a string instead of a lang-alt list? Reason being, I want to keep DOpus' mouse-hover displaying of metadata consistent, and I'm not sure having XMP:UserComment different from EXIF:XPComment won't affect it. I'll test that. Stay tuned.

mazeckenrode

Quote from: StarGeek on June 11, 2020, 11:45:31 AM
a bit long and messy because you have to split each tag and insert the results of Filename in between, but something like

Ok, thanks much. These both worked for me, with EXIF:XPComment substituted for UserComment, as far as updating that one tag. I'm going to need to tweak the code for some cases where I have additional text after p #/#, as it did not work for that.

I did not try using similar code to update XMP:UserComment due to it being intended as a lang-alt list, and thankfully found that Directory Opus successfully displayed the new value for EXIF:XPComment. So far, so good.

Curiously, I found that both command lines resulted in some additional EXIF and IPTC tags being created in all files:


EXIF:XResolution
EXIF:YResolution
EXIF:ResolutionUnit
EXIF:YCbCrPositioning
IPTC:Caption-Abstract


Is this supposed to happen? If so, Why?

Another curious thing had happened when I was creating the PNG files to be experimented upon with these ExifTool instructions. I started by using DOpus to create metadata, in the form of <dopus field name>, in all fields that I would typically use for these scans. For example, in the field that DOpus calls Author, I put <author> (including the angle brackets as shown). I then used ExifTool to export all tags to JSON, so I could see which actual tag names were used for what data. The JSON files showed a handful of the EXIF tag values preceded by a question mark:


"EXIF:Artist": "?<author>",
"EXIF:Copyright": "?<copyright>",
"EXIF:Artist": "?<author>",
"EXIF:Copyright": "?<copyright>",
"EXIF:ImageDescription": "?<description>",
"EXIF:Make": "?<camera make>",
"EXIF:Model": "?<camera model>",
"EXIF:Software": "?<creation software>",


The corresponding XMP tags, also created by DOpus, did NOT have a question mark.

I then used DOpus again, to set the tags values I wanted to be operated on by my ExifTool code experiments (Document Test, prepared by MAZE, 31 May 2020, 17:00:00, p 1/10; Digitization by MAZE, 11 Jun 2020, later truncated to Document Test, prepared by MAZE, 31 May 2020, 17:00:00, p 1/10, in applicable comment tags). No question marks appeared in any tags exported from these updated PNGs, not even in the tags I hadn't changed since the earlier JSON exports. Anybody have an explanation?

QuoteIPTC:DateCreated doesn't have a time component, so I assume you mean IPTC:TimeCreated

I did see, in the page for IPTC tags ( https://exiftool.org/TagNames/IPTC.html ), that there are separate tags for time and date, but DOpus apparently sets both (as well as EXIF:DateTimeOriginal and XMP:DateTimeOriginal) with the same stroke, and ExifTool reports IPTC:DateCreated with both date and time values in the exported JSONs. If I can't set them both together using that one tag name, why are they exported together like that? Aren't I supposed to be able to import all writeable tags from these JSON files?

QuoteThat could be done with "-DateTimeOriginal+<+<0:0:${Filename;m/0*(\d+)\./;$_=$1}"

I tried:

exiftool "-EXIF:DateTimeOriginal+<+<0:0:${Filename;m/0*(\d+)\./;$_=$1}" "-XMP:DateTimeOriginal+<+<0:0:${Filename;m/0*(\d+)\./;$_=$1}" "-IPTC:TimeCreated+<+<0:0:${Filename;m/0*(\d+)\./;$_=$1}" .

...but that gave me:

Warning: No writable tags set from...

QuoteDon't you mean "Page 10: 16:59:10"?

Brain fart, my bad. :-)  Should have been:

Page 1: 16:59:51
Page 2: 16:59:52
...
Page 10: 17:00:00

Phil Harvey

Quote from: mazeckenrode on June 11, 2020, 09:29:08 PM
EXIF:XPComment is supposed to be an unsigned 8-bit integer, but is the Microsoft version of EXIF:UserComment, which is undefined (presumably a string)? What would an integer placed in EXIF:XPComment represent?

The format for this tag is completely meaningless.  It is actually stored as UCS2-LE, which has 16-bit characters.  But of course, everything can be represented as a string of bytes.  Don't ask me why Microsoft uses an int8u format code.  In my opinion their programmers must have been on drugs when they made this decision.

QuoteI don't suppose it's possible to force ExifTool to write XMP:UserComment as a string instead of a lang-alt list?

You could do this by overriding the tag with a user-defined tag.  But then this would violate the XMP specification, which could cause problems down the line.

- 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

Quote from: mazeckenrode on June 10, 2020, 08:49:14 PM
Quote from: StarGeek on June 10, 2020, 05:41:41 PMMinor warning which you can ignore. That tag was written incorrectly. Exiftool fixed.

Actually, it did not update the tags, that I recall (not at that computer just now, but I'll verify later), according to new JSONs I vaguely remember exporting following the operation. At least, the previous values were still being displayed by Directory Opus.

It wouldn't be something you would see unless you viewed the raw XMP.  Whatever originally wrote the tag did so incorrectly and Exiftool fixed it.  As an example there is this thread about Microsoft XMP.  At some point they decided to change the URI.  The difference is xmlns:MicrosoftPhoto="http://ns.microsoft.com/photo/1.0/" vs. xmlns:MicrosoftPhoto="http://ns.microsoft.com/photo/1.0".  Just a single trailing slash.

Quote
QuoteThe UserComment tag should be a lang-alt list in XMP.

It seems that some tags' names are hardly descriptive of their intended purposes. Anyway, if Directory Opus is inserting the same value into both XMP:UserComment and EXIF:XPComment, but leaving EXIF:UserComment alone, is that an example of DOpus' metadata library not keeping up with current specs, or abusing its privileges?

They're not abusing anything, it's just what they decided to program.  Understand, UserComment isn't really part of any modern standard to begin with.  It's sort of a weird outlier tag, IMO.  The entirety of its description in the EXIF spec is just "Comments from user".  XMP:Description/IPTC:Caption-Abstract are the more commonly used tags and part of the IPTC Photo Metadata Spec.

QuoteI don't suppose it's possible to force ExifTool to write XMP:UserComment as a string instead of a lang-alt list? Reason being, I want to keep DOpus' mouse-hover displaying of metadata consistent, and I'm not sure having XMP:UserComment different from EXIF:XPComment won't affect it. I'll test that. Stay tuned.
...
QuoteI did not try using similar code to update XMP:UserComment due to it being intended as a lang-alt list,

It's really not something you need to worry about.  A lot of the XMP tags are "lang-alt".  But unless you are actually adding alternate language text, it's basically just a string that gets returned.

As an example, if you set Description to say "Picture of a cow", then that is what most software will return.  But if you knew that someone in Italy would need to read it in Italian, you could add (runs to google translate) -Description-it="Immagine di una mucca". "Picture of a cow" is the default and is what will be returned unless the Italian version was asked for.

Quote from: mazeckenrode on June 11, 2020, 09:31:41 PMCuriously, I found that both command lines resulted in some additional EXIF and IPTC tags being created in all files:
EXIF:XResolution
EXIF:YResolution
EXIF:ResolutionUnit
EXIF:YCbCrPositioning
IPTC:Caption-Abstract

Is this supposed to happen? If so, Why?

The EXIF tags are mandatory according to the EXIF spec (see the EXIF tag page).  Caption-Abstract should not be written unless it is specifically called for or MWG tags are used.

QuoteThe JSON files showed a handful of the EXIF tag values preceded by a question mark:
...
No question marks appeared in any tags exported from these updated PNGs, not even in the tags I hadn't changed since the earlier JSON exports. Anybody have an explanation?

No idea without actually seeing a file and figuring out what the actual character was (might not have been a ASCII question mark), but it sounds like Opus is writing something weird.

QuoteI did see, in the page for IPTC tags ( https://exiftool.org/TagNames/IPTC.html ), that there are separate tags for time and date, but DOpus apparently sets both (as well as EXIF:DateTimeOriginal and XMP:DateTimeOriginal) with the same stroke, and ExifTool reports IPTC:DateCreated with both date and time values in the exported JSONs. If I can't set them both together using that one tag name, why are they exported together like that? Aren't I supposed to be able to import all writeable tags from these JSON files?

Again, I'd have to see a file to correctly figure it out, but off hand it sounds like Opus is incorrectly writing the data. 

QuoteThat could be done with "-DateTimeOriginal+<+<0:0:${Filename;m/0*(\d+)\./;$_=$1}"

Oops, my mistake.  doubled up on the +< due to copy/paste error.  This should work
"-DateTimeOriginal+<0:0:${Filename;m/0*(\d+)\./;$_=$1}"
"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

mazeckenrode

Quote from: Phil Harvey on June 11, 2020, 09:57:44 PM
Quote from: mazeckenrode on June 11, 2020, 09:29:08 PM
I don't suppose it's possible to force ExifTool to write XMP:UserComment as a string instead of a lang-alt list?

You could do this by overriding the tag with a user-defined tag. But then this would violate the XMP specification, which could cause problems down the line.

Noted, thanks. I'll give it a whirl some time, at least to see if I can make it work.

mazeckenrode

Quote from: StarGeek on June 12, 2020, 12:04:55 AM
The EXIF tags are mandatory according to the EXIF spec (see the EXIF tag page). Caption-Abstract should not be written unless it is specifically called for or MWG tags are used.

I don't really care that much that they got added, but remain curious as to why IPTC:Caption-Abstract appeared when my command line code didn't call for it.

Quote
QuoteThe JSON files showed a handful of the EXIF tag values preceded by a question mark:

No idea without actually seeing a file and figuring out what the actual character was (might not have been a ASCII question mark), but it sounds like Opus is writing something weird.

Well, I haven't been able to reproduce it. One of life's mysteries, I guess.

Quote
QuoteThat could be done with "-DateTimeOriginal+<+<0:0:${Filename;m/0*(\d+)\./;$_=$1}"

Oops, my mistake.  doubled up on the +< due to copy/paste error. This should work
"-DateTimeOriginal+<0:0:${Filename;m/0*(\d+)\./;$_=$1}"

Didn't notice until I tried it, but that adds seconds instead of subtracting the total of <numberofpages>-<pagenumber>. Tag-operations says:

"When shifting a value, the shift is applied to the original value of the tag, overriding any other values previously assigned to the tag on the same command line."

...so it sounds like I can't do something like
exiftool "-EXIF:DateTimeOriginal+<0:0:${Filename;m/0*(\d+)\./;$_=$1}" "-EXIF:DateTimeOriginal-=0:0:10"
and expect both halves of that to have an effect. Is there a way to perform the necessary calculation within the single command line code, or am I going to have to issue two command lines for each tag I want to shift? (Until I manage to get a script together which performs the calculation, then feeds the correct number for subtraction to ExifTool.) I'm guessing I can't do the former, and haven't found any examples of that sort of thing so far, anyway.

Also, trying but failing to adequately reverse engineer your previously suggested code, modified by me as follows:

exiftool "-EXIF:XPComment<${EXIF:XPComment;my $temp=$1 if $self->GetValue('FileName')=~m/0*(\d+)\./;s/\d+(\/\d+$)/$temp$1/}" .

...in order to make it match even when there is additional text after p #/#. I don't understand everything going on in your code, such as the \.. In the regex I know, that's an escaped period after the capture group, otherwise known as a literal period. But there is no period in my example comment field Document Test, prepared by MAZE, 31 May 2020, 17:00:00, p 1/10; Digitization by MAZE, 11 Jun 2020, so what does that do, and how to match with or without additional text? Sorry to be so dense, I even tried consulting the regex web pages you suggested in a previous post, but probably not seeing the forest for the trees.