[tracker/media-art-enhancements: 6/16] libtracker-extract, tracker-extract: Return guaranteed title



commit ab159e969ca09cf97546fe52a24b80bfc4a5ff93
Author: Sam Thursfield <sam thursfield codethink co uk>
Date:   Thu Oct 20 15:07:38 2011 +0100

    libtracker-extract,tracker-extract: Return guaranteed title
    
    When a title is generated from the filename (--enable-guarantee-metadata), return it to the
    calling extractor so that it can be used for media art. This allows storing video poster art
    for any video, provided guaranteed metadata is enabled.

 src/libtracker-extract/tracker-guarantee.c        |   28 ++++++++++++++++----
 src/libtracker-extract/tracker-guarantee.h        |    9 +++---
 src/tracker-extract/tracker-extract-flac.c        |    2 +-
 src/tracker-extract/tracker-extract-gif.c         |    3 +-
 src/tracker-extract/tracker-extract-gstreamer.c   |    9 +-----
 src/tracker-extract/tracker-extract-jpeg.c        |    3 +-
 src/tracker-extract/tracker-extract-mp3.c         |    3 +-
 src/tracker-extract/tracker-extract-png.c         |    3 +-
 src/tracker-extract/tracker-extract-tiff.c        |    3 +-
 tests/libtracker-extract/tracker-guarantee-test.c |    8 +++++-
 10 files changed, 47 insertions(+), 24 deletions(-)
---
diff --git a/src/libtracker-extract/tracker-guarantee.c b/src/libtracker-extract/tracker-guarantee.c
index fa34b04..01d1152 100644
--- a/src/libtracker-extract/tracker-guarantee.c
+++ b/src/libtracker-extract/tracker-guarantee.c
@@ -74,8 +74,10 @@ get_date_from_file_mtime (const gchar *uri)
  * tracker_guarantee_title_from_file:
  * @metadata: the metadata object to insert the data into
  * @key: the key to insert into @metadata
- * @current_value: the current data to check before looking at @uri
+ * @current_value: the current data to check before looking at @uri.
  * @uri: a string representing a URI to use
+ * @new_value: pointer to a string which receives the new title, or
+ *             %NULL
  *
  * Checks @current_value to make sure it is sane (i.e. not %NULL or an
  * empty string). If it is, then @uri is parsed to guarantee a
@@ -90,10 +92,11 @@ get_date_from_file_mtime (const gchar *uri)
  * Since: 0.10
  **/
 gboolean
-tracker_guarantee_title_from_file (TrackerSparqlBuilder *metadata,
-                                   const gchar          *key,
-                                   const gchar          *current_value,
-                                   const gchar          *uri)
+tracker_guarantee_title_from_file (TrackerSparqlBuilder  *metadata,
+                                   const gchar           *key,
+                                   const gchar           *current_value,
+                                   const gchar           *uri,
+                                   gchar                **p_new_value)
 {
 #ifdef GUARANTEE_METADATA
 	g_return_val_if_fail (metadata != NULL, FALSE);
@@ -104,17 +107,30 @@ tracker_guarantee_title_from_file (TrackerSparqlBuilder *metadata,
 
 	if (current_value && *current_value != '\0') {
 		tracker_sparql_builder_object_unvalidated (metadata, current_value);
+
+		if (p_new_value != NULL) {
+			*p_new_value = g_strdup (current_value);
+		}
 	} else {
 		gchar *value;
 
 		value = get_title_from_file (uri);
 		tracker_sparql_builder_object_unvalidated (metadata, value);
-		g_free (value);
+
+		if (p_new_value != NULL) {
+			*p_new_value = value;
+		} else {
+			g_free (value);
+		}
 	}
 #else  /* GUARANTEE_METADATA */
 	if (current_value && *current_value != '\0') {
 		tracker_sparql_builder_predicate (metadata, key);
 		tracker_sparql_builder_object_unvalidated (metadata, current_value);
+
+		if (p_new_value != NULL) {
+			*p_new_value = g_strdup (current_value);
+		}
 	}
 #endif /* GUARANTEE_METADATA */
 
diff --git a/src/libtracker-extract/tracker-guarantee.h b/src/libtracker-extract/tracker-guarantee.h
index bbf4878..e14fd8e 100644
--- a/src/libtracker-extract/tracker-guarantee.h
+++ b/src/libtracker-extract/tracker-guarantee.h
@@ -30,10 +30,11 @@
 
 G_BEGIN_DECLS
 
-gboolean tracker_guarantee_title_from_file      (TrackerSparqlBuilder *metadata,
-                                                 const gchar          *key,
-                                                 const gchar          *current_value,
-                                                 const gchar          *uri);
+gboolean tracker_guarantee_title_from_file      (TrackerSparqlBuilder  *metadata,
+                                                 const gchar           *key,
+                                                 const gchar           *current_value,
+                                                 const gchar           *uri,
+                                                 gchar                **p_new_value);
 gboolean tracker_guarantee_date_from_file_mtime (TrackerSparqlBuilder *metadata,
                                                  const gchar          *key,
                                                  const gchar          *current_value,
diff --git a/src/tracker-extract/tracker-extract-flac.c b/src/tracker-extract/tracker-extract-flac.c
index b212823..cc1abc1 100644
--- a/src/tracker-extract/tracker-extract-flac.c
+++ b/src/tracker-extract/tracker-extract-flac.c
@@ -350,7 +350,7 @@ tracker_extract_get_metadata (TrackerExtractInfo *info)
 
 	add_tuple (metadata, "nmm:musicAlbum", album_uri);
 
-	tracker_guarantee_title_from_file (metadata, "nie:title", fd.title, uri);
+	tracker_guarantee_title_from_file (metadata, "nie:title", fd.title, uri, NULL);
 	add_tuple (metadata, "nmm:trackNumber", fd.tracknumber);
 
 	if (fd.album && album_uri) {
diff --git a/src/tracker-extract/tracker-extract-gif.c b/src/tracker-extract/tracker-extract-gif.c
index b97851d..6a63353 100644
--- a/src/tracker-extract/tracker-extract-gif.c
+++ b/src/tracker-extract/tracker-extract-gif.c
@@ -289,7 +289,8 @@ read_metadata (TrackerSparqlBuilder *preupdate,
 	tracker_guarantee_title_from_file (metadata,
 	                                   "nie:title",
 	                                   md.title,
-	                                   uri);
+	                                   uri,
+	                                   NULL);
 
 	if (md.artist) {
 		gchar *uri = tracker_sparql_escape_uri_printf ("urn:contact:%s", md.artist);
diff --git a/src/tracker-extract/tracker-extract-gstreamer.c b/src/tracker-extract/tracker-extract-gstreamer.c
index fc1038e..102b517 100644
--- a/src/tracker-extract/tracker-extract-gstreamer.c
+++ b/src/tracker-extract/tracker-extract-gstreamer.c
@@ -630,7 +630,7 @@ extractor_apply_general_metadata (MetadataExtractor     *extractor,
 		tracker_sparql_builder_object_unvalidated (metadata, genre);
 	}
 
-	tracker_guarantee_title_from_file (metadata, "nie:title", title, file_url);
+	tracker_guarantee_title_from_file (metadata, "nie:title", title, file_url, p_media_title);
 
 	add_date_time_gst_tag_with_mtime_fallback (metadata,
 	                                           file_url,
@@ -648,12 +648,7 @@ extractor_apply_general_metadata (MetadataExtractor     *extractor,
 	g_free (artist_temp);
 	g_free (composer);
 	g_free (genre);
-
-	if (p_media_title != NULL) {
-		*p_media_title = title;
-	} else {
-		g_free (title);
-	}
+	g_free (title);
 }
 
 static void
diff --git a/src/tracker-extract/tracker-extract-jpeg.c b/src/tracker-extract/tracker-extract-jpeg.c
index a9d15cb..533227c 100644
--- a/src/tracker-extract/tracker-extract-jpeg.c
+++ b/src/tracker-extract/tracker-extract-jpeg.c
@@ -532,7 +532,8 @@ tracker_extract_get_metadata (TrackerExtractInfo *info)
 	tracker_guarantee_title_from_file (metadata,
 	                                   "nie:title",
 	                                   md.title,
-	                                   uri);
+	                                   uri,
+	                                   NULL);
 
 	if (md.orientation) {
 		tracker_sparql_builder_predicate (metadata, "nfo:orientation");
diff --git a/src/tracker-extract/tracker-extract-mp3.c b/src/tracker-extract/tracker-extract-mp3.c
index 9842e5a..6cd77bc 100644
--- a/src/tracker-extract/tracker-extract-mp3.c
+++ b/src/tracker-extract/tracker-extract-mp3.c
@@ -2380,7 +2380,8 @@ tracker_extract_get_metadata (TrackerExtractInfo *info)
 	tracker_guarantee_title_from_file (metadata,
 	                                   "nie:title",
 	                                   md.title,
-	                                   uri);
+	                                   uri,
+	                                   NULL);
 
 	if (md.lyricist_uri) {
 		tracker_sparql_builder_predicate (metadata, "nmm:lyricist");
diff --git a/src/tracker-extract/tracker-extract-png.c b/src/tracker-extract/tracker-extract-png.c
index 350848b..7fdaae2 100644
--- a/src/tracker-extract/tracker-extract-png.c
+++ b/src/tracker-extract/tracker-extract-png.c
@@ -412,7 +412,8 @@ read_metadata (TrackerSparqlBuilder *preupdate,
 	tracker_guarantee_title_from_file (metadata,
 	                                   "nie:title",
 	                                   md.title,
-	                                   uri);
+	                                   uri,
+	                                   NULL);
 
 	if (md.make || md.model) {
 		gchar *equip_uri;
diff --git a/src/tracker-extract/tracker-extract-tiff.c b/src/tracker-extract/tracker-extract-tiff.c
index ca55ce2..d201b91 100644
--- a/src/tracker-extract/tracker-extract-tiff.c
+++ b/src/tracker-extract/tracker-extract-tiff.c
@@ -710,7 +710,8 @@ tracker_extract_get_metadata (TrackerExtractInfo *info)
 	tracker_guarantee_title_from_file (metadata,
 	                                   "nie:title",
 	                                   md.title,
-	                                   uri);
+	                                   uri,
+	                                   NULL);
 
 	if (md.orientation) {
 		tracker_sparql_builder_predicate (metadata, "nfo:orientation");
diff --git a/tests/libtracker-extract/tracker-guarantee-test.c b/tests/libtracker-extract/tracker-guarantee-test.c
index 10af11d..ee8265c 100644
--- a/tests/libtracker-extract/tracker-guarantee-test.c
+++ b/tests/libtracker-extract/tracker-guarantee-test.c
@@ -54,6 +54,7 @@ internal_test_title (const gchar *uri,
 {
         TrackerSparqlBuilder *builder;
         gchar                *sparql;
+        gchar                *title_guaranteed;
 
         builder = tracker_sparql_builder_new_update ();
         tracker_sparql_builder_insert_open (builder, "test");
@@ -61,7 +62,8 @@ internal_test_title (const gchar *uri,
         g_assert (tracker_guarantee_title_from_file (builder, 
                                                      "nie:title",
                                                      value,
-                                                     uri));
+                                                     uri,
+                                                     &title_guaranteed));
         tracker_sparql_builder_insert_close (builder);
 
         sparql = g_strdup_printf ("INSERT INTO <test> {\n<test://resource> nie:title \"%s\" .\n}\n",
@@ -70,6 +72,10 @@ internal_test_title (const gchar *uri,
                          ==,
                          tracker_sparql_builder_get_result (builder));
 
+        g_assert_cmpstr (title_guaranteed,
+                         ==,
+                         expected);
+
         g_object_unref (builder);
         g_free (sparql);
 }



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