From b995cfb4e88f8a6297c791ab85fe2b2c3156e3a0 Mon Sep 17 00:00:00 2001 From: Jean-Francois Dockes Date: Fri, 8 Apr 2016 11:37:23 +0200 Subject: [PATCH] added module for simplified interface to libxmp --- src/Makefile.am | 1 + src/filters/rclxmp.py | 68 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100755 src/filters/rclxmp.py diff --git a/src/Makefile.am b/src/Makefile.am index 72133dd7..898e0bf4 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -608,6 +608,7 @@ filters/rclwar \ filters/rclwpd \ filters/rclxls.py \ filters/rclxml.py \ +filters/rclxmp.py \ filters/rclxslt.py \ filters/rclzip \ filters/ppt-dump.py \ diff --git a/src/filters/rclxmp.py b/src/filters/rclxmp.py new file mode 100755 index 00000000..9dce6741 --- /dev/null +++ b/src/filters/rclxmp.py @@ -0,0 +1,68 @@ +#!/usr/bin/env python +# Copyright (C) 2016 J.F.Dockes +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the +# Free Software Foundation, Inc., +# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +# Code to extract XMP tags using libexempi and python-xmp +from __future__ import print_function + +can_xmp = True +try: + import libxmp.utils +except: + can_xmp = False + +import re +import sys + +xmp_index_re = re.compile('''\[[0-9+]\]$''') +#xmp_index_re = re.compile('''3''') + +def rclxmp_enabled(): + return can_xmp + +def rclxmp(filename): + if not can_xmp: + return None, "python-xmp not accessible" + errstr = "" + try: + xmp = libxmp.utils.file_to_dict(filename) + except Exception as e: + errstr = str(e) + + if errstr: + return None, errstr + + out = {} + for ns in xmp.keys(): + for entry in xmp[ns]: + if entry[1]: + k = xmp_index_re.sub('', entry[0]) + if k.find("/") != -1: + continue + if k in out: + out[k] += " " + entry[1] + else: + out[k] = entry[1] + return out, "" + +if __name__ == "__main__": + d, err = rclxmp(sys.argv[1]) + if d: + print("Data: %s" % d) + else: + print("Error: %s" % err) + +