[tracker] Moving reused code around for XMP extractors



commit 32900ade4e331402dcb23475ff0c6150457c2e57
Author: Philip Van Hoof <philip codeminded be>
Date:   Mon Sep 7 12:11:18 2009 +0200

    Moving reused code around for XMP extractors

 src/tracker-extract/tracker-extract-imagemagick.c |   16 ++-
 src/tracker-extract/tracker-extract-xmp.c         |  173 +--------------------
 src/tracker-extract/tracker-xmp.c                 |  177 +++++++++++++++++++++
 src/tracker-extract/tracker-xmp.h                 |    4 +
 4 files changed, 192 insertions(+), 178 deletions(-)
---
diff --git a/src/tracker-extract/tracker-extract-imagemagick.c b/src/tracker-extract/tracker-extract-imagemagick.c
index 160f3cb..286db5f 100644
--- a/src/tracker-extract/tracker-extract-imagemagick.c
+++ b/src/tracker-extract/tracker-extract-imagemagick.c
@@ -29,7 +29,7 @@
 
 #include <libtracker-common/tracker-ontology.h>
 #include <libtracker-common/tracker-os-dependant.h>
-#include <libtracker-common/tracker-statement.h>
+#include <libtracker-common/tracker-statement-list.h>
 
 #include "tracker-main.h"
 #include "tracker-xmp.h"
@@ -89,21 +89,21 @@ extract_imagemagick (const gchar *uri,
 		if (exit_status == EXIT_SUCCESS) {
 
 
-			tracker_insert_statement (metadata, uri, 
+			tracker_statement_list_insert (metadata, uri, 
 			                          RDF_TYPE, 
 			                          NFO_PREFIX "Document");
 
 			lines = g_strsplit (identify, ";\n", 4);
 
-			tracker_insert_statement (metadata, uri,
+			tracker_statement_list_insert (metadata, uri,
 						  NFO_PREFIX "width", 
 						  lines[0]);
 
-			tracker_insert_statement (metadata, uri,
+			tracker_statement_list_insert (metadata, uri,
 						  NFO_PREFIX "height", 
 						  lines[1]);
 
-			tracker_insert_statement (metadata, uri,
+			tracker_statement_list_insert (metadata, uri,
 						  NIE_PREFIX "comment", 
 						  lines[2]);
 
@@ -124,7 +124,11 @@ extract_imagemagick (const gchar *uri,
 
 	if (tracker_spawn (argv, 10, &xmp, &exit_status)) {
 		if (exit_status == EXIT_SUCCESS && xmp) {
-			tracker_read_xmp (xmp, strlen (xmp), uri, metadata);
+			TrackerXmpData xmp_data = { 0 };
+
+			tracker_read_xmp (xmp, strlen (xmp), uri, &xmp_data);
+
+			tracker_apply_xmp (metadata, uri, &xmp_data);
 		}
 	}
 #endif /* HAVE_EXEMPI */
diff --git a/src/tracker-extract/tracker-extract-xmp.c b/src/tracker-extract/tracker-extract-xmp.c
index 6fb61cd..4ee2901 100644
--- a/src/tracker-extract/tracker-extract-xmp.c
+++ b/src/tracker-extract/tracker-extract-xmp.c
@@ -32,14 +32,6 @@
 #include "tracker-main.h"
 #include "tracker-xmp.h"
 
-
-#define NMM_PREFIX TRACKER_NMM_PREFIX
-#define NFO_PREFIX TRACKER_NFO_PREFIX
-#define NIE_PREFIX TRACKER_NIE_PREFIX
-#define DC_PREFIX TRACKER_DC_PREFIX
-#define NCO_PREFIX TRACKER_NCO_PREFIX
-#define RDF_PREFIX TRACKER_RDF_PREFIX
-
 static void extract_xmp (const gchar          *filename, 
                          TrackerSparqlBuilder *metadata);
 
@@ -144,32 +136,6 @@ find_orig_uri (const gchar *xmp_filename)
 	return found_file;
 }
 
-
-static void
-insert_keywords (TrackerSparqlBuilder *metadata, const gchar *uri, gchar *keywords)
-{
-	char *lasts, *keyw;
-	size_t len;
-
-	keyw = keywords;
-	keywords = strchr (keywords, '"');
-	if (keywords)
-		keywords++;
-	else 
-		keywords = keyw;
-
-	len = strlen (keywords);
-	if (keywords[len - 1] == '"')
-		keywords[len - 1] = '\0';
-
-	for (keyw = strtok_r (keywords, ",; ", &lasts); keyw; 
-	     keyw = strtok_r (NULL, ",; ", &lasts)) {
-		tracker_statement_list_insert (metadata, uri, 
-		                               NIE_PREFIX "keyword", 
-		                               (const gchar*) keyw);
-	}
-}
-
 static void
 extract_xmp (const gchar          *uri, 
              TrackerSparqlBuilder *metadata)
@@ -191,144 +157,7 @@ extract_xmp (const gchar          *uri,
 		                  orig_uri ? orig_uri : uri, 
 		                  &xmp_data);
 
-		if (xmp_data.keywords) {
-			insert_keywords (metadata, uri, xmp_data.keywords);
-			g_free (xmp_data.keywords);
-		}
-
-		if (xmp_data.subject) {
-			insert_keywords (metadata, uri, xmp_data.subject);
-			g_free (xmp_data.subject);
-		}
-
-		if (xmp_data.publisher) {
-			tracker_statement_list_insert (metadata, ":", RDF_PREFIX "type", NCO_PREFIX "Contact");
-			tracker_statement_list_insert (metadata, ":", NCO_PREFIX "fullname", xmp_data.publisher);
-			tracker_statement_list_insert (metadata, uri, NCO_PREFIX "publisher", ":");
-			g_free (xmp_data.publisher);
-		}
-
-		if (xmp_data.type) {
-			tracker_statement_list_insert (metadata, uri, DC_PREFIX "type", xmp_data.type);
-			g_free (xmp_data.type);
-		}
-
-		if (xmp_data.format) {
-			tracker_statement_list_insert (metadata, uri, DC_PREFIX "format", xmp_data.format);
-			g_free (xmp_data.format);
-		}
-
-		if (xmp_data.identifier) {
-			tracker_statement_list_insert (metadata, uri, DC_PREFIX "identifier", xmp_data.identifier);
-			g_free (xmp_data.identifier);
-		}
-
-		if (xmp_data.source) {
-			tracker_statement_list_insert (metadata, uri, DC_PREFIX "source", xmp_data.source);
-			g_free (xmp_data.source);
-		}
-
-		if (xmp_data.language) {
-			tracker_statement_list_insert (metadata, uri, DC_PREFIX "language", xmp_data.language);
-			g_free (xmp_data.language);
-		}
-
-		if (xmp_data.relation) {
-			tracker_statement_list_insert (metadata, uri, DC_PREFIX "relation", xmp_data.relation);
-			g_free (xmp_data.relation);
-		}
-
-		if (xmp_data.coverage) {
-			tracker_statement_list_insert (metadata, uri, DC_PREFIX "coverage", xmp_data.coverage);
-			g_free (xmp_data.coverage);
-		}
-
-		if (xmp_data.license) {
-			tracker_statement_list_insert (metadata, uri, NIE_PREFIX "license", xmp_data.license);
-			g_free (xmp_data.license);
-		}
-
-		if (xmp_data.Make || xmp_data.Model) {
-			gchar *final_camera = tracker_coalesce (2, xmp_data.Make, xmp_data.Model); 
-			tracker_statement_list_insert (metadata, uri, NMM_PREFIX "camera", final_camera);
-			g_free (final_camera);
-		}
-
-		if (xmp_data.title) {
-			tracker_statement_list_insert (metadata, uri, NIE_PREFIX "title", xmp_data.title);
-			g_free (xmp_data.title);
-		}
-
-		if (xmp_data.Orientation) {
-			tracker_statement_list_insert (metadata, uri, NFO_PREFIX "orientation", xmp_data.Orientation);
-			g_free (xmp_data.Orientation);
-		}
-
-		if (xmp_data.rights) {
-			tracker_statement_list_insert (metadata, uri, NIE_PREFIX "copyright", xmp_data.rights);
-			g_free (xmp_data.rights);
-		}
-
-		if (xmp_data.WhiteBalance) {
-			tracker_statement_list_insert (metadata, uri, NMM_PREFIX "whiteBalance", xmp_data.WhiteBalance);
-			g_free (xmp_data.WhiteBalance);
-		}
-
-		if (xmp_data.FNumber) {
-			tracker_statement_list_insert (metadata, uri, NMM_PREFIX "fnumber", xmp_data.FNumber);
-			g_free (xmp_data.FNumber);
-		}
-
-		if (xmp_data.Flash) {
-			tracker_statement_list_insert (metadata, uri, NMM_PREFIX "flash", xmp_data.Flash);
-			g_free (xmp_data.Flash);
-		}
-
-		if (xmp_data.FocalLength) {
-			tracker_statement_list_insert (metadata, uri, NMM_PREFIX "focalLength", xmp_data.FocalLength);
-			g_free (xmp_data.FocalLength);
-		}
-
-		if (xmp_data.Artist || xmp_data.contributor) {
-			gchar *final_artist =  tracker_coalesce (2, xmp_data.Artist, xmp_data.contributor);
-			tracker_statement_list_insert (metadata, ":", RDF_PREFIX "type", NCO_PREFIX "Contact");
-			tracker_statement_list_insert (metadata, ":", NCO_PREFIX "fullname", final_artist);
-			tracker_statement_list_insert (metadata, uri, NCO_PREFIX "contributor", ":");
-			g_free (final_artist);
-		}
-
-		if (xmp_data.ExposureTime) {
-			tracker_statement_list_insert (metadata, uri, NMM_PREFIX "exposureTime", xmp_data.ExposureTime);
-			g_free (xmp_data.ExposureTime);
-		}
-
-		if (xmp_data.ISOSpeedRatings) {
-			tracker_statement_list_insert (metadata, uri, NMM_PREFIX "isoSpeed", xmp_data.ISOSpeedRatings);
-			g_free (xmp_data.ISOSpeedRatings);
-		}
-
-		if (xmp_data.date || xmp_data.DateTimeOriginal) {
-			gchar *final_date =  tracker_coalesce (2, xmp_data.date, xmp_data.DateTimeOriginal);
-			tracker_statement_list_insert (metadata, uri, NIE_PREFIX "contentCreated", final_date);
-			g_free (final_date);
-		}
-
-		if (xmp_data.description) {
-			tracker_statement_list_insert (metadata, uri, NIE_PREFIX "description", xmp_data.description);
-			g_free (xmp_data.description);
-		}
-
-		if (xmp_data.MeteringMode) {
-			tracker_statement_list_insert (metadata, uri, NMM_PREFIX "meteringMode", xmp_data.MeteringMode);
-			g_free (xmp_data.MeteringMode);
-		}
-
-		if (xmp_data.creator) {
-			tracker_statement_list_insert (metadata, ":", RDF_PREFIX "type", NCO_PREFIX "Contact");
-			tracker_statement_list_insert (metadata, ":", NCO_PREFIX "fullname", xmp_data.creator);
-			tracker_statement_list_insert (metadata, uri, NCO_PREFIX "creator", ":");
-			g_free (xmp_data.creator);
-		}
+		tracker_apply_xmp (metadata, uri, &xmp_data);
 
 		g_free (orig_uri);
 	}
diff --git a/src/tracker-extract/tracker-xmp.c b/src/tracker-extract/tracker-xmp.c
index ebfaa28..645345b 100644
--- a/src/tracker-extract/tracker-xmp.c
+++ b/src/tracker-extract/tracker-xmp.c
@@ -30,6 +30,14 @@
 
 #include <libtracker-common/tracker-type-utils.h>
 #include <libtracker-common/tracker-utils.h>
+#include <libtracker-common/tracker-ontology.h>
+
+#define NMM_PREFIX TRACKER_NMM_PREFIX
+#define NFO_PREFIX TRACKER_NFO_PREFIX
+#define NIE_PREFIX TRACKER_NIE_PREFIX
+#define DC_PREFIX TRACKER_DC_PREFIX
+#define NCO_PREFIX TRACKER_NCO_PREFIX
+#define RDF_PREFIX TRACKER_RDF_PREFIX
 
 #ifdef HAVE_EXEMPI
 
@@ -500,3 +508,172 @@ tracker_read_xmp (const gchar          *buffer,
 	xmp_terminate ();
 #endif
 }
+
+
+static void
+insert_keywords (TrackerSparqlBuilder *metadata, const gchar *uri, gchar *keywords)
+{
+	char *lasts, *keyw;
+	size_t len;
+
+	keyw = keywords;
+	keywords = strchr (keywords, '"');
+	if (keywords)
+		keywords++;
+	else 
+		keywords = keyw;
+
+	len = strlen (keywords);
+	if (keywords[len - 1] == '"')
+		keywords[len - 1] = '\0';
+
+	for (keyw = strtok_r (keywords, ",; ", &lasts); keyw; 
+	     keyw = strtok_r (NULL, ",; ", &lasts)) {
+		tracker_statement_list_insert (metadata, uri, 
+		                               NIE_PREFIX "keyword", 
+		                               (const gchar*) keyw);
+	}
+}
+
+void
+tracker_apply_xmp (TrackerSparqlBuilder *metadata, const gchar *uri, TrackerXmpData *xmp_data)
+{
+	if (xmp_data->keywords) {
+		insert_keywords (metadata, uri, xmp_data->keywords);
+		g_free (xmp_data->keywords);
+	}
+
+	if (xmp_data->subject) {
+		insert_keywords (metadata, uri, xmp_data->subject);
+		g_free (xmp_data->subject);
+	}
+
+	if (xmp_data->publisher) {
+		tracker_statement_list_insert (metadata, ":", RDF_PREFIX "type", NCO_PREFIX "Contact");
+		tracker_statement_list_insert (metadata, ":", NCO_PREFIX "fullname", xmp_data->publisher);
+		tracker_statement_list_insert (metadata, uri, NCO_PREFIX "publisher", ":");
+		g_free (xmp_data->publisher);
+	}
+
+	if (xmp_data->type) {
+		tracker_statement_list_insert (metadata, uri, DC_PREFIX "type", xmp_data->type);
+		g_free (xmp_data->type);
+	}
+
+	if (xmp_data->format) {
+		tracker_statement_list_insert (metadata, uri, DC_PREFIX "format", xmp_data->format);
+		g_free (xmp_data->format);
+	}
+
+	if (xmp_data->identifier) {
+		tracker_statement_list_insert (metadata, uri, DC_PREFIX "identifier", xmp_data->identifier);
+		g_free (xmp_data->identifier);
+	}
+
+	if (xmp_data->source) {
+		tracker_statement_list_insert (metadata, uri, DC_PREFIX "source", xmp_data->source);
+		g_free (xmp_data->source);
+	}
+
+	if (xmp_data->language) {
+		tracker_statement_list_insert (metadata, uri, DC_PREFIX "language", xmp_data->language);
+		g_free (xmp_data->language);
+	}
+
+	if (xmp_data->relation) {
+		tracker_statement_list_insert (metadata, uri, DC_PREFIX "relation", xmp_data->relation);
+		g_free (xmp_data->relation);
+	}
+
+	if (xmp_data->coverage) {
+		tracker_statement_list_insert (metadata, uri, DC_PREFIX "coverage", xmp_data->coverage);
+		g_free (xmp_data->coverage);
+	}
+
+	if (xmp_data->license) {
+		tracker_statement_list_insert (metadata, uri, NIE_PREFIX "license", xmp_data->license);
+		g_free (xmp_data->license);
+	}
+
+	if (xmp_data->Make || xmp_data->Model) {
+		gchar *final_camera = tracker_coalesce (2, xmp_data->Make, xmp_data->Model); 
+		tracker_statement_list_insert (metadata, uri, NMM_PREFIX "camera", final_camera);
+		g_free (final_camera);
+	}
+
+	if (xmp_data->title) {
+		tracker_statement_list_insert (metadata, uri, NIE_PREFIX "title", xmp_data->title);
+		g_free (xmp_data->title);
+	}
+
+	if (xmp_data->Orientation) {
+		tracker_statement_list_insert (metadata, uri, NFO_PREFIX "orientation", xmp_data->Orientation);
+		g_free (xmp_data->Orientation);
+	}
+
+	if (xmp_data->rights) {
+		tracker_statement_list_insert (metadata, uri, NIE_PREFIX "copyright", xmp_data->rights);
+		g_free (xmp_data->rights);
+	}
+
+	if (xmp_data->WhiteBalance) {
+		tracker_statement_list_insert (metadata, uri, NMM_PREFIX "whiteBalance", xmp_data->WhiteBalance);
+		g_free (xmp_data->WhiteBalance);
+	}
+
+	if (xmp_data->FNumber) {
+		tracker_statement_list_insert (metadata, uri, NMM_PREFIX "fnumber", xmp_data->FNumber);
+		g_free (xmp_data->FNumber);
+	}
+
+	if (xmp_data->Flash) {
+		tracker_statement_list_insert (metadata, uri, NMM_PREFIX "flash", xmp_data->Flash);
+		g_free (xmp_data->Flash);
+	}
+
+	if (xmp_data->FocalLength) {
+		tracker_statement_list_insert (metadata, uri, NMM_PREFIX "focalLength", xmp_data->FocalLength);
+		g_free (xmp_data->FocalLength);
+	}
+
+	if (xmp_data->Artist || xmp_data->contributor) {
+		gchar *final_artist =  tracker_coalesce (2, xmp_data->Artist, xmp_data->contributor);
+		tracker_statement_list_insert (metadata, ":", RDF_PREFIX "type", NCO_PREFIX "Contact");
+		tracker_statement_list_insert (metadata, ":", NCO_PREFIX "fullname", final_artist);
+		tracker_statement_list_insert (metadata, uri, NCO_PREFIX "contributor", ":");
+		g_free (final_artist);
+	}
+
+	if (xmp_data->ExposureTime) {
+		tracker_statement_list_insert (metadata, uri, NMM_PREFIX "exposureTime", xmp_data->ExposureTime);
+		g_free (xmp_data->ExposureTime);
+	}
+
+	if (xmp_data->ISOSpeedRatings) {
+		tracker_statement_list_insert (metadata, uri, NMM_PREFIX "isoSpeed", xmp_data->ISOSpeedRatings);
+		g_free (xmp_data->ISOSpeedRatings);
+	}
+
+	if (xmp_data->date || xmp_data->DateTimeOriginal) {
+		gchar *final_date =  tracker_coalesce (2, xmp_data->date, xmp_data->DateTimeOriginal);
+		tracker_statement_list_insert (metadata, uri, NIE_PREFIX "contentCreated", final_date);
+		g_free (final_date);
+	}
+
+	if (xmp_data->description) {
+		tracker_statement_list_insert (metadata, uri, NIE_PREFIX "description", xmp_data->description);
+		g_free (xmp_data->description);
+	}
+
+	if (xmp_data->MeteringMode) {
+		tracker_statement_list_insert (metadata, uri, NMM_PREFIX "meteringMode", xmp_data->MeteringMode);
+		g_free (xmp_data->MeteringMode);
+	}
+
+	if (xmp_data->creator) {
+		tracker_statement_list_insert (metadata, ":", RDF_PREFIX "type", NCO_PREFIX "Contact");
+		tracker_statement_list_insert (metadata, ":", NCO_PREFIX "fullname", xmp_data->creator);
+		tracker_statement_list_insert (metadata, uri, NCO_PREFIX "creator", ":");
+		g_free (xmp_data->creator);
+	}
+}
diff --git a/src/tracker-extract/tracker-xmp.h b/src/tracker-extract/tracker-xmp.h
index f14b2c3..0d01760 100644
--- a/src/tracker-extract/tracker-xmp.h
+++ b/src/tracker-extract/tracker-xmp.h
@@ -48,4 +48,8 @@ void tracker_read_xmp (const gchar          *buffer,
                        const gchar          *uri,
                        TrackerXmpData       *data);
 
+void tracker_apply_xmp (TrackerSparqlBuilder *metadata,
+                        const gchar *uri,
+                        TrackerXmpData *xmp_data);
+
 #endif /* _TRACKER_XMP_H_ */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]