Skip to main content
Participating Frequently
Sep 18, 2007 6:30 AM UTC
Question

Exporting metadata to an XML file

Hi!

I'm trying to write a script that exports the metadata (camera info and photo description) from all the images in a folder to an XML file and then saves it to the same folder.
My knowledge of JavaScript is a little rusty and i would need some help. I started reading through the Bridge Scripting Guide, but i gave up...
If someone could help me to get started with the script, i would really appreciate it.

Thank you

Balint
This topic is closed to new replies. Start a new post to keep the conversation going.

6 replies

Participating Frequently
Nov 30, 2008 8:16 PM UTC
No solution et?

Good Luck.
______
My Si tes
Translate
Participating Frequently
Sep 19, 2007 10:17 AM UTC
I have a simple script now working, but i am having problems, wherever the metadata tags use accented latin characters (áéüö, etc.).

I managed to save the resulting file in UTF-16 encoding, and if i do a test f.write("éáüöő"), the characters are preserved correctly.
However all the special characters in the meta tags are broken.
Translate
Participating Frequently
Sep 18, 2007 9:54 AM UTC
There should be about 40 images per folder maximum.

I also just found a "bridge to xml for adobe spry" script at imagic, here:
http://imagicdigital.wordpress.com/2006/07/12/export-xml-from-bridge-for-spry-gallery-ii/

It seems like another simple solution, i just copy the link here for other people for future reference...
Translate
Participating Frequently
Sep 18, 2007 9:38 AM UTC
Cool - glad to help :)

Have a look through the JavaScript Tools Guide though because there is more than one way to do this. If you have a lot of files then above code may not be the best solution.

Cheers.
Translate
Participating Frequently
Sep 18, 2007 9:28 AM UTC
Chanandler,

Thank you for the fast reply, the code you sent works great!
I just had to comment out line 57: $.writeln(updatedPacket);

I think i should be able to go from here, i want make it recursive for all the files in the folder and select only a couple of the entries in the metadata.
Translate
Participating Frequently
Sep 18, 2007 8:34 AM UTC
This will get you started. It extracts properties from the EXIF and XMP Basic schemas from a selected thumbnail and writes the metadata to the JS console and to a file. Open the script in the ESTK and run it against Bridge with a selection made.

The info you need to modify this script to suit your needs is in the JavaScript Tools guide which you can get with the Bridge SDK from http://www.adobe.com/devnet/bridge/

// Load the XMP Script library
if( xmpLib == undefined )
{
if( Folder.fs == "Windows" )
{
var pathToLib = Folder.startup.fsName + "/AdobeXMPScript.dll";
}
else
{
var pathToLib = Folder.startup.fsName + "/AdobeXMPScript.framework";
}

var libfile = new File( pathToLib );
var xmpLib = new ExternalObject("lib:" + pathToLib );
}

// Get a selected thumbnail
var thumb = app.document.selections[0];
if(thumb.hasMetadata)
{
// Get the selected file
var selectedFile = thumb.spec;

// Create an XMPFile - this allows you to extract the XMP data
var myXmpFile = new XMPFile( selectedFile.fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_READ);

// The XMP object from the selected thumb
var thumbXMP = myXmpFile.getXMP();

// An empty XMP object
var myXMP = new XMPMeta();

// Create an iterator that will only visit EXIF properties
var iter = thumbXMP.iterator(0, XMPConst.NS_EXIF);
while((prop = iter.next()) != null)
{
if(prop.path != "")
{
//$.writeln(prop.namespace + " " + prop.path + " " + prop.value, prop.options);
myXMP.setProperty(prop.namespace, prop.path, prop.value, prop.options);
}
}

// Create an iterator that will only visit XMP Basic properties
iter = thumbXMP.iterator(0, XMPConst.NS_XMP);
while((prop = iter.next()) != null)
{
if(prop.path != "")
{
//$.writeln(prop.namespace + " " + prop.path + " " + prop.value, prop.options);
myXMP.setProperty(prop.namespace, prop.path, prop.value, prop.options);
}
}

var myXMPPacket = myXMP.serialize (XMPConst.SERIALIZE_OMIT_PACKET_WRAPPER);

$.writeln(updatedPacket);

var outFile = File(thumb.spec.fsName + ".xml");
outFile.open("w");
outFile.write(myXMPPacket);
outFile.close();
}
Translate