ExifTool Forum

ExifTool => Newbies => Topic started by: jhimmy dingo on December 13, 2023, 02:14:43 PM

Title: Need to map metadata fields from a JSON file onto absent fields of an MOV
Post by: jhimmy dingo on December 13, 2023, 02:14:43 PM
Hi--I'm very new to ExifTool and coding in Python as well. Let me begin with the description of what I need to do:

I have a folder with multiple JSON files and multiple MOV files. The JSON file I need to map to each corresponding MOV file has a matching file name. I need to batch process the folder and read 2 specific metadata fields from the JSON file and apply them to different fields in the MOV file;

1. From the JSON file I need to read the field "Asset Comment" and apply it to the MOV field "Description"
2. From the JSON file I need to read the field "Asset Custom Field 7" and apply it to the MOV field "Keywords"

I have been using ChatGPT to try to help me write Python code using ExifTool that would batch process a folder and make these changes to the MOV files. (I'll paste my code and errors below--forgive me if Phython discussion isn't allowed in this forum! I'm open to any solutions! Or suggestions to try other forums)

I've worked on this for days--the problem I THINK I've run into is that the MOV files I need to change don't appear to already contain the metadata fields I NEED; "Description" or "Keywords".

HOWEVER, I KNOW it's possible to create an MOV with these fields--I have been able to do this by exporting an MOV from Adobe Premiere and altering the metadata available in Premiere's metadata upon export--If I alter the metadata field in Premiere, "Dublin Core - Description" the exported MOV file contains the metadata field "Description" with the text that I input in Premiere. And if I alter the field, "Adobe PDF - Keywords" in Premiere, the exported MOV contains the field "Keywords" with the text that I input.

I'm able to confirm these fields exist in those exported MOVs from Premiere by using ExifTool to view the metadata. And I've been able to determine those needed fields do NOT exist in the MOV files that I need to batch process, also by using ExifTool to view the metadata.

Here is my latest attempt I've made at a Python script with the help of ChatGPT 3.5. Chat GPT was trying to create a code that would read the specified JSON fields, create "Description" and "Keywords" fields in the MOV and map the JSON field values to the MOV.
(please remember I know very little about coding or ExifTool! Just doing my best!):

import os
import subprocess
import json

def apply_metadata_with_exiftool(video_path, metadata):
    try:
        exiftool_commands = []

        # Map JSON fields to corresponding metadata fields in .mov file
        field_mapping = {
            'Asset Comment': 'Description',
            'Asset Custom Field 7': 'Keywords',
        }

        # Add new metadata values
        for json_field, mov_field in field_mapping.items():
            json_value = metadata.get(json_field, '')
            exiftool_commands.extend([f'-{mov_field}={json_value}'])

        print(f"Running ExifTool commands: {' '.join(exiftool_commands)}")
        subprocess.run(['exiftool'] + exiftool_commands + [video_path], check=True)
        print(f"Metadata applied successfully to {video_path}")

    except subprocess.CalledProcessError as e:
        print(f"Error: {e}")
        print(f"ExifTool returned non-zero exit code {e.returncode}")

# Example usage:
video_path = '/Users/private/Documents/CODING/12-8-23_test/'
json_path = '/Users/private/Documents/CODING/12-8-23_test/'

metadata = {'Asset Comment': 'Test Description', 'Asset Custom Field 7': 'Test Keywords'}

apply_metadata_with_exiftool(video_path, metadata)

I'm sure the paths for the MOV and the JSON files are correct. Here is the output I get after running this Python code:

QuoteRunning ExifTool commands: -Description=Description -Keywords=Keywords
Error: Truncated '\xc4\x88)*' atom - /Users/utvpc/Documents/CODING/12-8-23_test/Test.mov
    1 directories scanned
    0 image files updated
    1 files weren't updated due to errors
Error: Command '['exiftool', '-Description=Description', '-Keywords=Keywords', '/Users/utvpc/Documents/CODING/12-8-23_test/']' returned non-zero exit status 1.
ExifTool returned non-zero exit code 1

I'm using Visual Studio Code to help create my Python code if that matters, but I've also run the python code through terminal and got the same errors. I've confirmed ExifTool and Python is up to date.

Is what I'm trying to do possible? Anyone have any idea what I should do? Help is MUCH appreciated! Thank you!
Title: Re: Need to map metadata fields from a JSON file onto absent fields of an MOV
Post by: Phil Harvey on December 13, 2023, 02:27:39 PM
I don't know about Python, but I think you want a command something like this.  You should write XMP:Subject for keywords in a MOV video:

exiftool -tagsfromfile %d%f.json "-Description<AssetComment" "-Subject<AssetCustomField7"  -ext mov DIR

... but use exiftool -s FILE.json on a JSON file first to be sure I've got the JSON tag names right.

- Phil
Title: Re: Need to map metadata fields from a JSON file onto absent fields of an MOV
Post by: jhimmy dingo on December 13, 2023, 05:24:25 PM
Holy cow, I got it to work! You just saved me SO much time--thanks so much. Can I ask one more question?

The platform where I need to eventually upload these MOV files, PhotoShelter, for some reason only seems to read Keywords from metadata that I enter into "Adobe PDF Keywords" field. I have successfully entered a value in this field through Premiere's Metadata Export Panel that can be successfully read by PhotoShelter.

So, if I didn't want to use XMP:Subject for my keywords, but instead wanted to use "Adobe PDF Keywords," do you know what I should write instead of ""-Subject..." in the command line you wrote?

Again, thank you!
Title: Re: Need to map metadata fields from a JSON file onto absent fields of an MOV
Post by: StarGeek on December 13, 2023, 05:37:46 PM
Probably XMP-pdf:Keywords, but to be sure, find a file that is already set correctly and use the command in FAQ #3 (https://exiftool.org/faq.html#Q3) to verify the names and locations.
Title: Re: Need to map metadata fields from a JSON file onto absent fields of an MOV
Post by: jhimmy dingo on December 13, 2023, 08:03:54 PM
Okay, I've been reading and testing everything I could find.

I used exiftool -a -G1 -s -n "File/Path.mov" to determine for sure, that the metadata field I need to adjust is indeed [XMP-pdf] Keywords.

When I input exiftool -tagsfromfile %d%f.json "-Description<AssetComment" "-Keywords<AssetCustomField_7"  -ext mov "File/Path"
It outputs: 1 directories scanned, 1 image files updated

The "Description" tag moves over perfectly, however, "Keywords" doesn't pull information from the "AssetCustomField_7" tag in the JSON file. The [XMP-pdf] Keywords field isn't there at all when I look at the new metadata with exiftool.

I read a post here (https://exiftool.org/forum/index.php?topic=8079.0) that discusses some difficulties with [XMP-pdf] Keywords that I didn't quite understand. But I did try using the -api NoPDFList command by inputting:
exiftool -tagsfromfile %d%f.json "-Description<AssetComment" "-Keywords<AssetCustomField_7"  -ext mov "/Users/utvpc/Downloads/TEST/TEST 2/TEST 3" -api NoPDFList, but the [XMP-pdf] Keywords field still didn't show up.

I'm sure I'm just missing something obvious. And to clarify, I DO need to keep the [XMP-pdf] Keywords field as a string of keywords separated by commas.

Thanks to anyone who thinks they know what I'm doing wrong!
Title: Re: Need to map metadata fields from a JSON file onto absent fields of an MOV
Post by: Phil Harvey on December 13, 2023, 09:25:49 PM
This should have worked if the AssetCustomField_7 tag existed.

It is difficult to tell where this is going wrong because you are trying to copy 2 tags at the same time.

Try this one step at a time:

1. Extract AssetCustomField_7 from a test JSON file:

exiftool -AssetCustomField_7 test.json

2. If this gives an output, try writing Keywords to a test MOV:

exiftool -keywords=test test.mov

The only thing I can think of is that you might want to write xmp-pdf:keywords instead of just keywords, but I didn't think that should be necessary.

- Phil
Title: Re: Need to map metadata fields from a JSON file onto absent fields of an MOV
Post by: jhimmy dingo on December 14, 2023, 12:45:43 AM
I figured it out and did a ton of tests to make sure. There is something wrong with the mov files being produced in my workflow somehow.

I WAS successful at pulling both Description and Keywords over from the JSON file with any other MOV I produced by other methods. So it has something to do with how the MOV files are being produced by the company who supplies us those MOV files. I'll talk to them or figure out a workaround.

Thanks! Great, helpful community here!

Title: Re: Need to map metadata fields from a JSON file onto absent fields of an MOV
Post by: jhimmy dingo on December 15, 2023, 02:45:52 PM
Hi all--I have a similar request so I'm posting it here. I can create a new thread if that makes more sense.

SO, I successfully used the code below from Phil to read a value from a field in a JSON file and apply that value to a newly created field in an MOV file. Works great:

Quote from: Phil Harvey on December 13, 2023, 02:27:39 PMexiftool -tagsfromfile %d%f.json "-Description<AssetComment" "-Subject<AssetCustomField7"  -ext mov DIR


But NOW I'm trying to figure out a way to take the value from "AssetCustomField7" in the JSON file and create the same custom field "AssetCustomField7" in the MOV file with the same value. (ideally I also want to tell the command to append the value from "AssetCustomField7" to any existing values in that field if it already exists with a comma beforehand--so that I end up with a list of values separated by commas. But I wanted to try the simpler code before I figure out how to append with a comma)

So I tried this code:
exiftool -tagsfromfile %d%f.json "-AssetCustomField7<AssetCustomField7"  -ext mp4 -ext mov DIR
But in the terminal, the only response I get is: dquote>

Is what I'm trying to do possible? Did I screw something up?

Thanks
Title: Re: Need to map metadata fields from a JSON file onto absent fields of an MOV
Post by: Phil Harvey on December 15, 2023, 03:16:11 PM
I don't see the response from your command.

But this will only work if you create a user-defined XMP tag named AssetCustomField7.

See the sample config file (https://www.exiftool.org/config.html) for an example of how to create user-defined XMP tags.

- Phil
Title: Re: Need to map metadata fields from a JSON file onto absent fields of an MOV
Post by: jhimmy dingo on December 15, 2023, 04:37:10 PM
Thanks--I'll read up on that now. Thanks for the guidance!

And just to clarify in case it's important, the response from the command was just
Quote"dquote>"
. At which point if I enter any other simple commands that I know work it just replies with, "dquote>" until I open a new terminal window (on Mac). I also tried running the script in Visual Studio Code's terminal window and got the same result.
Title: Re: Need to map metadata fields from a JSON file onto absent fields of an MOV
Post by: StarGeek on December 15, 2023, 07:42:15 PM
There was something wrong with your command.  The terminal thinks you didn't have a closing quote
How to come out of dquote prompt in Terminal (https://code2care.org/q/come-out-of-dquote-prompt-in-macos-terminal-linux/)

Make sure you're using real double quotes and not fancy/smart/curly quotes.  For example, copy/pasting commands from a word processor will change quotes and dashes.

Also, one thing to understand.  If you create and use your AssetCustomField7 tag, that doesn't change the fact that the tag won't be read by other programs. Programs can only read the tags that they have been coded to read.
Title: Re: Need to map metadata fields from a JSON file onto absent fields of an MOV
Post by: Phil Harvey on December 15, 2023, 09:00:25 PM
Ah.  I had never seen "dquote>" before because I have always used tcsh on Mac.  "dquote>" is a zsh response.  tcsh would say Unmatched ".

- Phil