News:

2023-03-15 Major improvements to the new Geolocation feature

Main Menu

Batch import .JSON into corresponding .JPG file possible?

Started by umdaman, December 20, 2018, 11:50:57 AM

Previous topic - Next topic

umdaman

I have downloaded my collections from FlickR with some software that created .JSON files for each image.  I would like to batch process each directory to add the Description and Tags and Title to my .JPG files.

Example of files
100_2440.jpg
100_2440.jpg.json

100_2441.jpg
100_2441.jpg.json

Is there anyway to process the entire directory and match up the .JSON with correct .JPG ?

Also I manually did 1 file, and it only seems to import the Description and Title.
XMP Toolkit                     : Image::ExifTool 10.57
Description                     : This is a test description
Title                           : IMG_2543

Data in the tested .JSON file: 
{"Tags":"Test, Area, province","Description":"This is a test description","Title":"IMG_2543"}

I was thinking the idea having the Tags for the image would be so that when uploaded to FlickR, or maybe even Google photos, that it would automatically import TAGS for searching, and Description and title so that I would not have to enter that for each image uploaded.... 

Are TAGS not supported?


Hope someone can help me out here.

Phil Harvey

Try this:

exiftool -tagsfromfile %d%f.%e.json "-SOMETAG<tags" -description -title -ext jpg DIR

where SOMETAG is the name of the tag you want the "Tags" metadata to go.  The Description and Title will be written to the XMP tags with these names.  Maybe using XMP "Subject" for SOMETAG makes sense.

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

umdaman

Thanks!   I'm getting a little closer.   I had to change -tagsfromfile to -json  .  When I had -tagsfromfile I got an error: Error: File format error - 100_2440.jpg.json. on all the files.

Warning: No writable tags set from 100_2440.jpg
Warning: No writable tags set from 100_2441.jpg
Warning: No writable tags set from IMG_2539.jpg
Warning: No writable tags set from IMG_2540.jpg
Warning: No writable tags set from IMG_2541.jpg
Warning: No writable tags set from IMG_2542.jpg
    1 directories scanned
    2 image files updated

So out of the 8 files in the directory, I'm not sure why 2 worked and 6 others did not.



Phil Harvey

The -json option won't work.  It is meant to import a single json database for all files.

Can you attach one of your json files so I can try it out here?

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

umdaman

Ok on the not using .json option.  now really weird I was just editing the json that worked to add different text to see if it was adding correct one when I did the .json option, now all 8 files unchanged.....

I have attached a couple files.

Phil Harvey

The problem is that your JSON files begin with a leading UTF-8 byte order mark.  I will patch ExifTool to allow this, but until the next release (11.23) you can work around this problem if you can remove the BOM from the start of the files.

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

umdaman

Ahhhhhhhhhh!   I was wondering how the heck you saw that, but I did a type filename.json and I see that BOM your talking about!!    So the program I used that created those did that for some reason.  I wonder why.  So yes I edited one of my json's and cut and pasted the text into a new file, and saved it.   Then did what you told me and that worked!   I noticed the filesize of the .json was slightly smaller too.

Yes that will be great if you can fix that for the next release.  How long do you think before the next release is out?  I have like 16,000 photos that I'm working on.  I wonder if I could somehow create a simple Visual basic program that would rewrite all those .json files.

In the meantime I'm going to search if there is some kind of batch BOM remover.

Thanks for figuring this out for me!!

Phil Harvey

I'll see about doing a release tomorrow if I have time.

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

Phil Harvey

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

umdaman


timwillems

What about Flickr making names like _dsc1677_13425411743_o.jpg and photo_13425411743.json where just the number is the same? (working on Mac if that makes a difference)

Phil Harvey

Try this:

exiftool -tagsfromfile %d/photo_%-11.2f.json ... -ext jpg DIR

This should work as long as the file names all have this format with an 11-digit number.

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

timwillems

Wonderful! It's writing the exif data into the jpg
Should I be worried about this:
"Warning: [minor] XMP-cc:License written as a literal because value is not a valid URI"?

StarGeek

No, unless you feel the need to have the XMP-cc:License tag be absolutely accurate.  It's the Creative Commons license that applies to the image.  It's a very rare tag that I've never seen actually used.

For exiftool details on it, see Creative Commons Tags.  For more details, see CreativeCommons.org.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

Phil Harvey

Just for interest, what is the output of this command for the file?:

exiftool -XMP-cc:License 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 ($).