[tracker/wip/resource: 5/11] tracker-extract: Use TrackerResource in GStreamer extractor



commit 192217a21e14d67e572fa0a29c189f0dc4e29f5d
Author: Sam Thursfield <ssssam gmail com>
Date:   Sat Mar 26 19:53:54 2016 +0000

    tracker-extract: Use TrackerResource in GStreamer extractor

 src/tracker-extract/tracker-extract-gstreamer.c |  880 ++++++++---------------
 1 files changed, 287 insertions(+), 593 deletions(-)
---
diff --git a/src/tracker-extract/tracker-extract-gstreamer.c b/src/tracker-extract/tracker-extract-gstreamer.c
index a419b54..de3de76 100644
--- a/src/tracker-extract/tracker-extract-gstreamer.c
+++ b/src/tracker-extract/tracker-extract-gstreamer.c
@@ -2,6 +2,7 @@
  * Copyright (C) 2006, Laurent Aguerreche <laurent aguerreche free fr>
  * Copyright (C) 2007, Jamie McCracken <jamiemcc gnome org>
  * Copyright (C) 2008, Nokia <ivan frade nokia com>
+ * Copyright (C) 2016, Sam Thursfield <sam afuera me uk>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -151,95 +152,47 @@ typedef struct {
 
 static void common_extract_stream_metadata (MetadataExtractor    *extractor,
                                             const gchar          *uri,
-                                            TrackerSparqlBuilder *metadata);
+                                            TrackerResource      *resource);
 
-static void
-add_artist (MetadataExtractor     *extractor,
-            TrackerSparqlBuilder  *preupdate,
-            const gchar           *graph,
-            const gchar           *artist_name,
-            gchar                **p_artist_uri)
-{
-       g_return_if_fail (artist_name != NULL);
-
-       *p_artist_uri = tracker_sparql_escape_uri_printf ("urn:artist:%s", artist_name);
-
-       /* Check if already added to the preupdate, to avoid sending 9 identical INSERTs */
-       if (g_slist_find_custom (extractor->artist_list, artist_name, (GCompareFunc) strcmp))
-               return;
-
-       tracker_sparql_builder_insert_open (preupdate, NULL);
-       if (graph) {
-               tracker_sparql_builder_graph_open (preupdate, graph);
-       }
-
-       tracker_sparql_builder_subject_iri (preupdate, *p_artist_uri);
-       tracker_sparql_builder_predicate (preupdate, "a");
-       tracker_sparql_builder_object (preupdate, "nmm:Artist");
-       tracker_sparql_builder_predicate (preupdate, "nmm:artistName");
-       tracker_sparql_builder_object_unvalidated (preupdate, artist_name);
-
-       if (graph) {
-               tracker_sparql_builder_graph_close (preupdate);
-       }
-       tracker_sparql_builder_insert_close (preupdate);
-
-       extractor->artist_list = g_slist_prepend (extractor->artist_list, g_strdup (artist_name));
-}
-
-static void
-add_string_gst_tag (TrackerSparqlBuilder *metadata,
-                    const gchar          *key,
-                    GstTagList           *tag_list,
-                    const gchar          *tag)
+static TrackerResource *
+intern_artist (MetadataExtractor     *extractor,
+               const gchar           *artist_name)
 {
-       gchar *s;
-       gboolean ret;
+       TrackerResource *artist;
+       gchar *artist_uri;
 
-       s = NULL;
-       ret = gst_tag_list_get_string (tag_list, tag, &s);
+       g_return_if_fail (artist_name != NULL);
 
-       if (s) {
-               if (ret && s[0] != '\0') {
-                       tracker_sparql_builder_predicate (metadata, key);
-                       tracker_sparql_builder_object_unvalidated (metadata, s);
-               }
+       artist_uri = tracker_sparql_escape_uri_printf ("urn:artist:%s", artist_name);
 
-               g_free (s);
-       }
-}
+       artist = g_slist_find_custom (extractor->artist_list, artist_uri,
+                                     tracker_resource_identifier_compare_func);
+       if (artist) {
+               return artist;
+       } else {
+               artist = tracker_resource_new (artist_uri);
 
-static void
-add_uint_gst_tag (TrackerSparqlBuilder  *metadata,
-                  const gchar           *key,
-                  GstTagList            *tag_list,
-                  const gchar           *tag)
-{
-       gboolean ret;
-       guint n;
+       tracker_resource_set_property_uri(artist, "rdf:type", "nmm:Artist");
+       tracker_resource_set_property_string(artist, "nmm:artistName", artist_name);
 
-       ret = gst_tag_list_get_uint (tag_list, tag, &n);
+       extractor->artist_list = g_slist_prepend (extractor->artist_list, artist);
 
-       if (ret) {
-               tracker_sparql_builder_predicate (metadata, key);
-               tracker_sparql_builder_object_int64 (metadata, n);
-       }
+       return artist;
 }
 
 static void
-add_double_gst_tag (TrackerSparqlBuilder  *metadata,
-                    const gchar           *key,
-                    GstTagList            *tag_list,
-                    const gchar           *tag)
+set_property_from_gst_tag (TrackerResource *resource,
+                           const gchar     *property_uri,
+                           GstTagList      *tag_list,
+                           const gchar     *tag)
 {
        gboolean ret;
-       gdouble n;
+       GValue *value;
 
-       ret = gst_tag_list_get_double (tag_list, tag, &n);
+       ret = gst_tag_list_copy_value (&value, tag_list, tag);
 
        if (ret) {
-               tracker_sparql_builder_predicate (metadata, key);
-               tracker_sparql_builder_object_int64 (metadata, (gint64) n);
+               tracker_resource_set_property_gvalue (property_uri, value);
        }
 }
 
@@ -311,12 +264,12 @@ get_gst_date_time_to_buf (GstDateTime *date_time,
 }
 
 static void
-add_date_time_gst_tag_with_mtime_fallback (TrackerSparqlBuilder  *metadata,
-                                           const gchar           *uri,
-                                           const gchar           *key,
-                                           GstTagList            *tag_list,
-                                           const gchar           *tag_date_time,
-                                           const gchar           *tag_date)
+add_date_time_gst_tag_with_mtime_fallback (TrackerResource *resource,
+                                           const gchar     *uri,
+                                           const gchar     *key,
+                                           GstTagList      *tag_list,
+                                           const gchar     *tag_date_time,
+                                           const gchar     *tag_date)
 {
        GstDateTime *date_time;
        GDate *date;
@@ -355,12 +308,12 @@ add_date_time_gst_tag_with_mtime_fallback (TrackerSparqlBuilder  *metadata,
                g_date_free (date);
        }
 
-       tracker_guarantee_date_from_file_mtime (metadata, key, buf, uri);
+       tracker_guarantee_resource_date_from_file_mtime (resource, key, buf, uri);
 }
 
 static void
-add_keywords_gst_tag (TrackerSparqlBuilder *metadata,
-                      GstTagList           *tag_list)
+set_keywords_from_gst_tag (TrackerResource *resource,
+                           GstTagList      *tag_list)
 {
        gboolean ret;
        gchar *str;
@@ -374,8 +327,7 @@ add_keywords_gst_tag (TrackerSparqlBuilder *metadata,
                keywords = g_strsplit_set (str, " ,", -1);
 
                while (keywords[i]) {
-                       tracker_sparql_builder_predicate (metadata, "nie:keyword");
-                       tracker_sparql_builder_object_unvalidated (metadata, g_strstrip (keywords[i]));
+                       tracker_resource_add_property_string (resource, "nie:keyword", g_strstrip 
(keywords[i]);
                        i++;
                }
 
@@ -385,46 +337,20 @@ add_keywords_gst_tag (TrackerSparqlBuilder *metadata,
 }
 
 static void
-replace_double_gst_tag (TrackerSparqlBuilder  *preupdate,
-                        const gchar           *uri,
-                        const gchar           *key,
-                        GstTagList            *tag_list,
-                        const gchar           *tag,
-                        const gchar           *graph)
+replace_gst_tag (TrackerSparqlBuilder  *preupdate,
+                 const gchar           *key,
+                 GstTagList            *tag_list,
+                 const gchar           *tag)
 {
-       gdouble  value;
+       GValue *value;
        gboolean has_it;
 
-       has_it = gst_tag_list_get_double (tag_list, tag, &value);
+       has_it = gst_tag_list_copy_value (tag_list, tag, &value);
 
        if (! has_it)
                return;
 
-       tracker_sparql_builder_delete_open (preupdate, NULL);
-       tracker_sparql_builder_subject_iri (preupdate, uri);
-       tracker_sparql_builder_predicate (preupdate, key);
-       tracker_sparql_builder_object_variable (preupdate, "unknown");
-       tracker_sparql_builder_delete_close (preupdate);
-
-       tracker_sparql_builder_where_open (preupdate);
-       tracker_sparql_builder_subject_iri (preupdate, uri);
-       tracker_sparql_builder_predicate (preupdate, key);
-       tracker_sparql_builder_object_variable (preupdate, "unknown");
-       tracker_sparql_builder_where_close (preupdate);
-
-       tracker_sparql_builder_insert_open (preupdate, NULL);
-       if (graph) {
-               tracker_sparql_builder_graph_open (preupdate, graph);
-       }
-
-       tracker_sparql_builder_subject_iri (preupdate, uri);
-       tracker_sparql_builder_predicate (preupdate, key);
-       tracker_sparql_builder_object_double (preupdate, value);
-
-       if (graph) {
-               tracker_sparql_builder_graph_close (preupdate);
-       }
-       tracker_sparql_builder_insert_close (preupdate);
+       tracker_resource_set_property (key, value);
 }
 
 static gchar *
@@ -531,95 +457,67 @@ get_embedded_media_art (MetadataExtractor *extractor)
 
 #endif
 
-static void
-extractor_apply_geolocation_metadata (MetadataExtractor     *extractor,
-                                      GstTagList            *tag_list,
-                                      TrackerSparqlBuilder  *preupdate,
-                                      TrackerSparqlBuilder  *metadata,
-                                      const gchar           *graph)
+static TrackerResource *
+extractor_get_geolocation (MetadataExtractor     *extractor,
+                           GstTagList            *tag_list)
 {
-       gchar *country = NULL, *city = NULL, *sublocation = NULL;
+       TrackerResource *location = NULL;
        gdouble lat, lon, alt;
        gboolean has_coords;
 
        g_debug ("Retrieving geolocation metadata...");
 
-       country = city = sublocation = NULL;
        has_coords = (gst_tag_list_get_double (tag_list, GST_TAG_GEO_LOCATION_LATITUDE, &lat) &&
                      gst_tag_list_get_double (tag_list, GST_TAG_GEO_LOCATION_LONGITUDE, &lon) &&
                      gst_tag_list_get_double (tag_list, GST_TAG_GEO_LOCATION_ELEVATION, &alt));
 
-       gst_tag_list_get_string (tag_list, GST_TAG_GEO_LOCATION_CITY, &city);
-       gst_tag_list_get_string (tag_list, GST_TAG_GEO_LOCATION_COUNTRY, &country);
-       gst_tag_list_get_string (tag_list, GST_TAG_GEO_LOCATION_SUBLOCATION, &sublocation);
-
-       if (city || country || sublocation || has_coords) {
-               gchar *address_uri = NULL;
-
-               /* Create postal address */
-               if (city || country || sublocation) {
-                       address_uri = tracker_sparql_get_uuid_urn ();
+       if (has_coords) {
+               location = tracker_resource_new (NULL);
+               tracker_resource_set_property_uri (location, "rdf:type", "slo:GeoLocation");
 
-                       tracker_sparql_builder_insert_open (preupdate, NULL);
-                       if (graph) {
-                               tracker_sparql_builder_graph_open (preupdate, graph);
-                       }
+               tracker_resource_set_property_double (location, "slo:latitude", lat);
+               tracker_resource_set_property_double (location, "slo:longitude", lon);
+               tracker_resource_set_property_double (location, "slo:altitude", alt);
+       }
 
-                       tracker_sparql_builder_subject_iri (preupdate, address_uri);
-                       tracker_sparql_builder_predicate (preupdate, "a");
-                       tracker_sparql_builder_object (preupdate, "nco:PostalAddress");
+       return location;
+}
 
-                       if (sublocation) {
-                               tracker_sparql_builder_predicate (preupdate, "nco:region");
-                               tracker_sparql_builder_object_unvalidated (preupdate, sublocation);
-                       }
+static TrackerResource *
+extractor_get_address (MetadataExtractor     *extractor,
+                       GstTagList            *tag_list)
+{
+       TrackerResource *address = NULL;
+       gchar *country = NULL, *city = NULL, *sublocation = NULL;
 
-                       if (city) {
-                               tracker_sparql_builder_predicate (preupdate, "nco:locality");
-                               tracker_sparql_builder_object_unvalidated (preupdate, city);
-                       }
+       g_debug ("Retrieving address metadata...");
 
-                       if (country) {
-                               tracker_sparql_builder_predicate (preupdate, "nco:country");
-                               tracker_sparql_builder_object_unvalidated (preupdate, country);
-                       }
+       gst_tag_list_get_string (tag_list, GST_TAG_GEO_LOCATION_CITY, &city);
+       gst_tag_list_get_string (tag_list, GST_TAG_GEO_LOCATION_COUNTRY, &country);
+       gst_tag_list_get_string (tag_list, GST_TAG_GEO_LOCATION_SUBLOCATION, &sublocation);
 
-                       if (graph) {
-                               tracker_sparql_builder_graph_close (preupdate);
-                       }
-                       tracker_sparql_builder_insert_close (preupdate);
-               }
+       if (city || country || sublocation) {
+               gchar *address_uri = NULL;
 
-               /* Create geolocation */
-               tracker_sparql_builder_predicate (metadata, "slo:location");
+               address_uri = tracker_sparql_get_uuid_urn ();
+               address = tracker_resource_new (address_uri);
 
-               tracker_sparql_builder_object_blank_open (metadata);
-               tracker_sparql_builder_predicate (metadata, "a");
-               tracker_sparql_builder_object (metadata, "slo:GeoLocation");
+               tracker_resource_set_property_string (address, "rdf:type", "nco:PostalAddress");
 
-               if (address_uri) {
-                       tracker_sparql_builder_predicate (metadata, "slo:postalAddress");
-                       tracker_sparql_builder_object_iri (metadata, address_uri);
+               if (sublocation) {
+                       tracker_resource_set_property_string (address, "nco:region", sublocation);
                }
 
-               if (has_coords) {
-                       tracker_sparql_builder_predicate (metadata, "slo:latitude");
-                       tracker_sparql_builder_object_double (metadata, lat);
-
-                       tracker_sparql_builder_predicate (metadata, "slo:longitude");
-                       tracker_sparql_builder_object_double (metadata, lon);
-
-                       tracker_sparql_builder_predicate (metadata, "slo:altitude");
-                       tracker_sparql_builder_object_double (metadata, alt);
+               if (city) {
+                       tracker_resource_set_property_string (address, "nco:locality", city);
                }
 
-               tracker_sparql_builder_object_blank_close (metadata);
-               g_free (address_uri);
+               if (country) {
+                       tracker_resource_set_property_string (address, "nco:country", country);
+               }
        }
 
-       g_free (city);
-       g_free (country);
-       g_free (sublocation);
+       return address;
 }
 
 static void
@@ -641,59 +539,59 @@ static void
 extractor_apply_general_metadata (MetadataExtractor     *extractor,
                                   GstTagList            *tag_list,
                                   const gchar           *file_url,
-                                  TrackerSparqlBuilder  *preupdate,
-                                  TrackerSparqlBuilder  *metadata,
-                                  const gchar           *graph,
-                                  gchar                **p_performer_uri,
-                                  gchar                **p_composer_uri)
+                                  TrackerResource       *resource,
+                                  TrackerResource      **p_performer,
+                                  TrackerResource      **p_composer)
 {
-       const gchar *performer = NULL;
+       const gchar *performer_name = NULL;
        gchar *performer_temp = NULL;
        gchar *artist_temp = NULL;
-       gchar *composer = NULL;
+       gchar *composer_name = NULL;
        gchar *genre = NULL;
        gchar *title = NULL;
        gchar *title_guaranteed = NULL;
 
+       *p_composer = NULL;
+       *p_performer = NULL;
+
        gst_tag_list_get_string (tag_list, GST_TAG_PERFORMER, &performer_temp);
        gst_tag_list_get_string (tag_list, GST_TAG_ARTIST, &artist_temp);
        gst_tag_list_get_string (tag_list, GST_TAG_COMPOSER, &composer);
 
-       performer = tracker_coalesce_strip (2, performer_temp, artist_temp);
+       performer_name = tracker_coalesce_strip (2, performer_temp, artist_temp);
 
-       if (performer != NULL) {
-               add_artist (extractor, preupdate, graph, performer, p_performer_uri);
+       if (performer_name != NULL) {
+               *p_performer = intern_artist (extractor, performer_name);
        }
 
-       if (composer != NULL) {
-               add_artist (extractor, preupdate, graph, composer, p_composer_uri);
+       if (composer_name != NULL) {
+               *p_composer = intern_artist (extractor, composer_name);
        }
 
        gst_tag_list_get_string (tag_list, GST_TAG_GENRE, &genre);
        gst_tag_list_get_string (tag_list, GST_TAG_TITLE, &title);
 
        if (genre && g_strcmp0 (genre, "Unknown") != 0) {
-               tracker_sparql_builder_predicate (metadata, "nfo:genre");
-               tracker_sparql_builder_object_unvalidated (metadata, genre);
+               tracker_resource_add_property_string ("nfo:genre", genre);
        }
 
-       tracker_guarantee_title_from_file (metadata,
-                                          "nie:title",
-                                          title,
-                                          file_url,
-                                          &title_guaranteed);
+       tracker_guarantee_resource_title_from_file (resource,
+                                                  "nie:title",
+                                                   title,
+                                                   file_url,
+                                                   &title_guaranteed);
 
-       add_date_time_gst_tag_with_mtime_fallback (metadata,
+       add_date_time_gst_tag_with_mtime_fallback (resource,
                                                   file_url,
                                                   "nie:contentCreated",
                                                   tag_list,
                                                   GST_TAG_DATE_TIME,
                                                   GST_TAG_DATE);
 
-       add_string_gst_tag (metadata, "nie:copyright", tag_list, GST_TAG_COPYRIGHT);
-       add_string_gst_tag (metadata, "nie:license", tag_list, GST_TAG_LICENSE);
-       add_string_gst_tag (metadata, "dc:coverage", tag_list, GST_TAG_LOCATION);
-       add_string_gst_tag (metadata, "nie:comment", tag_list, GST_TAG_COMMENT);
+       set_property_from_gst_tag (resource, "nie:copyright", tag_list, GST_TAG_COPYRIGHT);
+       set_property_from_gst_tag (resource, "nie:license", tag_list, GST_TAG_LICENSE);
+       set_property_from_gst_tag (resource, "dc:coverage", tag_list, GST_TAG_LOCATION);
+       set_property_from_gst_tag (resource, "nie:comment", tag_list, GST_TAG_COMMENT);
 
 #ifdef HAVE_LIBMEDIAART
        if (extractor->media_art_type == MEDIA_ART_VIDEO) {
@@ -707,152 +605,72 @@ extractor_apply_general_metadata (MetadataExtractor     *extractor,
 
        g_free (performer_temp);
        g_free (artist_temp);
-       g_free (composer);
+       g_free (composer_name);
        g_free (genre);
        g_free (title);
 }
 
-static void
-extractor_apply_album_metadata (MetadataExtractor     *extractor,
-                                GstTagList            *tag_list,
-                                TrackerSparqlBuilder  *preupdate,
-                                const gchar           *graph,
-                                gchar                **p_album_artist_uri,
-                                gchar                **p_album_uri,
-                                gchar                **p_album_disc_uri)
+static TrackerResource *
+extractor_get_album_disc (MetadataExtractor *extractor,
+                          GstTagList        *tag_list)
 {
-       gchar *album_artist;
+       TrackerResource *album = NULL, *album_artist = NULL, *album_disc = NULL;
+       gchar *album_uri, *album_artist_uri, *album_disc_uri;
+       gchar *album_artist_name;
        gchar *album_title = NULL;
        gchar *album_artist_temp = NULL;
        gchar *track_artist_temp = NULL;
        gboolean has_it;
-       guint count;
+       guint volume_number;
 
        gst_tag_list_get_string (tag_list, GST_TAG_ALBUM, &album_title);
 
        if (!album_title)
-               return;
+               return NULL;
 
        gst_tag_list_get_string (tag_list, GST_TAG_ALBUM_ARTIST, &album_artist_temp);
        gst_tag_list_get_string (tag_list, GST_TAG_ARTIST, &track_artist_temp);
 
-       album_artist = g_strdup (tracker_coalesce_strip (2, album_artist_temp, track_artist_temp));
+       album_artist_name = g_strdup (tracker_coalesce_strip (2, album_artist_temp, track_artist_temp));
 
-        if (album_artist != NULL) {
-                add_artist (extractor, preupdate, graph, album_artist, p_album_artist_uri);
-                *p_album_uri = tracker_sparql_escape_uri_printf ("urn:album:%s:%s", album_title, 
album_artist);
+        if (album_artist_name != NULL) {
+                album_artist = intern_artist (extractor, album_artist_name);
+                album_uri = tracker_sparql_escape_uri_printf ("urn:album:%s:%s", album_title, album_artist);
         } else {
-                *p_album_uri = tracker_sparql_escape_uri_printf ("urn:album:%s", album_title);
+                album_uri = tracker_sparql_escape_uri_printf ("urn:album:%s", album_title);
         }
 
-       tracker_sparql_builder_insert_open (preupdate, NULL);
-       if (graph) {
-               tracker_sparql_builder_graph_open (preupdate, graph);
-       }
+       album = tracker_resource_new (album_uri);
+       tracker_resource_set_property_uri (album, "rdf:type", "nmm:MusicAlbum");
 
-       tracker_sparql_builder_subject_iri (preupdate, *p_album_uri);
-       tracker_sparql_builder_predicate (preupdate, "a");
-       tracker_sparql_builder_object (preupdate, "nmm:MusicAlbum");
-       /* FIXME: nmm:albumTitle is now deprecated
-        * tracker_sparql_builder_predicate (preupdate, "nie:title");
-        */
-       tracker_sparql_builder_predicate (preupdate, "nmm:albumTitle");
-       tracker_sparql_builder_object_unvalidated (preupdate, album_title);
-
-       if (*p_album_artist_uri) {
-               tracker_sparql_builder_predicate (preupdate, "nmm:albumArtist");
-               tracker_sparql_builder_object_iri (preupdate, *p_album_artist_uri);
-       }
+       /* FIXME: nmm:albumTitle is now deprecated, should use nie:title ??  */
+       tracker_resource_set_property_string (album, "nmm:albumTitle", album_title);
 
-       if (graph) {
-               tracker_sparql_builder_graph_close (preupdate);
+       if (album_artist) {
+               tracker_resource_set_property_resource (album, "nmm:albumArtist", album_artist);
        }
-       tracker_sparql_builder_insert_close (preupdate);
-
-       has_it = gst_tag_list_get_uint (tag_list, GST_TAG_TRACK_COUNT, &count);
-
-       if (has_it) {
-               tracker_sparql_builder_delete_open (preupdate, NULL);
-               tracker_sparql_builder_subject_iri (preupdate, *p_album_uri);
-               tracker_sparql_builder_predicate (preupdate, "nmm:albumTrackCount");
-               tracker_sparql_builder_object_variable (preupdate, "unknown");
-               tracker_sparql_builder_delete_close (preupdate);
-               tracker_sparql_builder_where_open (preupdate);
-               tracker_sparql_builder_subject_iri (preupdate, *p_album_uri);
-               tracker_sparql_builder_predicate (preupdate, "nmm:albumTrackCount");
-               tracker_sparql_builder_object_variable (preupdate, "unknown");
-               tracker_sparql_builder_where_close (preupdate);
-
-               tracker_sparql_builder_insert_open (preupdate, NULL);
-               if (graph) {
-                       tracker_sparql_builder_graph_open (preupdate, graph);
-               }
 
-               tracker_sparql_builder_subject_iri (preupdate, *p_album_uri);
-               tracker_sparql_builder_predicate (preupdate, "nmm:albumTrackCount");
-               tracker_sparql_builder_object_int64 (preupdate, count);
+       set_property_from_gst_tag (album, "nmm:albumTrackCount", tag_list, GST_TAG_TRACK_COUNT);
 
-               if (graph) {
-                       tracker_sparql_builder_graph_close (preupdate);
-               }
-               tracker_sparql_builder_insert_close (preupdate);
-       }
-
-       has_it = gst_tag_list_get_uint (tag_list, GST_TAG_ALBUM_VOLUME_NUMBER, &count);
+       has_it = gst_tag_list_get_uint (tag_list, GST_TAG_ALBUM_VOLUME_NUMBER, &volume_number);
 
         if (album_artist) {
-                *p_album_disc_uri = tracker_sparql_escape_uri_printf ("urn:album-disc:%s:%s:Disc%d",
-                                                                      album_title, album_artist,
-                                                                      has_it ? count : 1);
+                album_disc_uri = tracker_sparql_escape_uri_printf ("urn:album-disc:%s:%s:Disc%d",
+                                                                   album_title, album_artist,
+                                                                   has_it ? volume_number : 1);
         } else {
-                *p_album_disc_uri = tracker_sparql_escape_uri_printf ("urn:album-disc:%s:Disc%d",
-                                                                      album_title,
-                                                                      has_it ? count : 1);
+                album_disc_uri = tracker_sparql_escape_uri_printf ("urn:album-disc:%s:Disc%d",
+                                                                   album_title,
+                                                                   has_it ? volume_number : 1);
         }
 
+       album_disc = tracker_resource_new (album_disc_uri);
+       tracker_resource_set_property_resource (album_disc, "rdf:type", "nmm:MusicAlbumDisc");
+       tracker_resource_set_property_int64 (album_disc, "nmm:setNumber", has_it ? volume_number : 1);
+       tracker_resource_set_resource (album_disc, "nmm:albumDiscAlbum", album);
 
-       tracker_sparql_builder_delete_open (preupdate, NULL);
-       tracker_sparql_builder_subject_iri (preupdate, *p_album_disc_uri);
-       tracker_sparql_builder_predicate (preupdate, "nmm:setNumber");
-       tracker_sparql_builder_object_variable (preupdate, "unknown");
-       tracker_sparql_builder_delete_close (preupdate);
-       tracker_sparql_builder_where_open (preupdate);
-       tracker_sparql_builder_subject_iri (preupdate, *p_album_disc_uri);
-       tracker_sparql_builder_predicate (preupdate, "nmm:setNumber");
-       tracker_sparql_builder_object_variable (preupdate, "unknown");
-       tracker_sparql_builder_where_close (preupdate);
-
-       tracker_sparql_builder_delete_open (preupdate, NULL);
-       tracker_sparql_builder_subject_iri (preupdate, *p_album_disc_uri);
-       tracker_sparql_builder_predicate (preupdate, "nmm:albumDiscAlbum");
-       tracker_sparql_builder_object_variable (preupdate, "unknown");
-       tracker_sparql_builder_delete_close (preupdate);
-       tracker_sparql_builder_where_open (preupdate);
-       tracker_sparql_builder_subject_iri (preupdate, *p_album_disc_uri);
-       tracker_sparql_builder_predicate (preupdate, "nmm:albumDiscAlbum");
-       tracker_sparql_builder_object_variable (preupdate, "unknown");
-       tracker_sparql_builder_where_close (preupdate);
-
-       tracker_sparql_builder_insert_open (preupdate, NULL);
-       if (graph) {
-               tracker_sparql_builder_graph_open (preupdate, graph);
-       }
-
-       tracker_sparql_builder_subject_iri (preupdate, *p_album_disc_uri);
-       tracker_sparql_builder_predicate (preupdate, "a");
-       tracker_sparql_builder_object (preupdate, "nmm:MusicAlbumDisc");
-       tracker_sparql_builder_predicate (preupdate, "nmm:setNumber");
-       tracker_sparql_builder_object_int64 (preupdate, has_it ? count : 1);
-       tracker_sparql_builder_predicate (preupdate, "nmm:albumDiscAlbum");
-       tracker_sparql_builder_object_iri (preupdate, *p_album_uri);
-
-       if (graph) {
-               tracker_sparql_builder_graph_close (preupdate);
-       }
-       tracker_sparql_builder_insert_close (preupdate);
-
-       replace_double_gst_tag (preupdate, *p_album_uri, "nmm:albumGain", extractor->tagcache, 
GST_TAG_ALBUM_GAIN, graph);
-       replace_double_gst_tag (preupdate, *p_album_uri, "nmm:albumPeakGain", extractor->tagcache, 
GST_TAG_ALBUM_PEAK, graph);
+       set_property_from_gst_tag (album, "nmm:albumGain", extractor->tagcache, GST_TAG_ALBUM_GAIN);
+       set_property_from_gst_tag (album, "nmm:albumPeakGain", extractor->tagcache, GST_TAG_ALBUM_PEAK);
 
 #ifdef HAVE_LIBMEDIAART
        extractor->media_art_artist = album_artist;
@@ -861,15 +679,15 @@ extractor_apply_album_metadata (MetadataExtractor     *extractor,
 
        g_free (album_artist_temp);
        g_free (track_artist_temp);
+
+       return album_disc;
 }
 
-static void
-extractor_apply_device_metadata (MetadataExtractor    *extractor,
-                                 GstTagList           *tag_list,
-                                 TrackerSparqlBuilder *preupdate,
-                                 TrackerSparqlBuilder *metadata,
-                                 const gchar          *graph)
+static TrackerResource *
+extractor_get_equipment (MetadataExtractor    *extractor,
+                         GstTagList           *tag_list)
 {
+       TrackerResource *equipment;
        gchar *equip_uri;
        gchar *model = NULL, *manuf = NULL;
 
@@ -877,142 +695,110 @@ extractor_apply_device_metadata (MetadataExtractor    *extractor,
        gst_tag_list_get_string (tag_list, GST_TAG_DEVICE_MANUFACTURER, &manuf);
 
        if (model == NULL && manuf == NULL)
-               return;
+               return NULL;
 
        equip_uri = tracker_sparql_escape_uri_printf ("urn:equipment:%s:%s:",
                                                      manuf ? manuf : "",
                                                      model ? model : "");
+       equipment = tracker_resource_new (equip_uri);
 
-       tracker_sparql_builder_insert_open (preupdate, NULL);
-       if (graph) {
-               tracker_sparql_builder_graph_open (preupdate, graph);
-       }
-
-       tracker_sparql_builder_subject_iri (preupdate, equip_uri);
-       tracker_sparql_builder_predicate (preupdate, "a");
-       tracker_sparql_builder_object (preupdate, "nfo:Equipment");
+       tracker_resource_set_property_uri (resource, "rdf:type", "nfo:Equipment");
 
        if (manuf) {
-               tracker_sparql_builder_predicate (preupdate, "nfo:manufacturer");
-               tracker_sparql_builder_object_unvalidated (preupdate, manuf);
+               tracker_resource_set_property_string (equipment, "nfo:manufacturer", manuf);
        }
        if (model) {
-               tracker_sparql_builder_predicate (preupdate, "nfo:model");
-               tracker_sparql_builder_object_unvalidated (preupdate, model);
-       }
-
-       if (graph) {
-               tracker_sparql_builder_graph_close (preupdate);
+               tracker_resource_set_property_string (equipment, "nfo:model", model);
        }
-       tracker_sparql_builder_insert_close (preupdate);
-
-       tracker_sparql_builder_predicate (metadata, "nfo:equipment");
-       tracker_sparql_builder_object_iri (metadata, equip_uri);
 
        g_free (equip_uri);
        g_free (model);
        g_free (manuf);
+
+       return equipment;
 }
 
 static void
 extractor_apply_audio_metadata (MetadataExtractor     *extractor,
                                 GstTagList            *tag_list,
-                                TrackerSparqlBuilder  *metadata,
-                                const gchar           *performer_uri,
-                                const gchar           *composer_uri,
-                                const gchar           *album_uri,
-                                const gchar           *album_disc_uri)
+                                TrackerResource       *audio,
+                                TrackerResource       *performer,
+                                TrackerResource       *composer,
+                                TrackerResource       *album_disc)
 {
-       add_uint_gst_tag (metadata, "nmm:trackNumber", tag_list, GST_TAG_TRACK_NUMBER);
-       add_string_gst_tag (metadata, "nfo:codec", tag_list, GST_TAG_AUDIO_CODEC);
-       add_double_gst_tag (metadata, "nfo:gain", tag_list, GST_TAG_TRACK_GAIN);
-       add_double_gst_tag (metadata, "nfo:peakGain", tag_list, GST_TAG_TRACK_PEAK);
-
-       if (performer_uri) {
-               tracker_sparql_builder_predicate (metadata, "nmm:performer");
-               tracker_sparql_builder_object_iri (metadata, performer_uri);
+       set_property_from_gst_tag (audio, "nmm:trackNumber", tag_list, GST_TAG_TRACK_NUMBER);
+       set_property_from_gst_tag (audio, "nfo:codec", tag_list, GST_TAG_AUDIO_CODEC);
+       set_property_from_gst_tag (audio, "nfo:gain", tag_list, GST_TAG_TRACK_GAIN);
+       set_property_from_gst_tag (audio, "nfo:peakGain", tag_list, GST_TAG_TRACK_PEAK);
+
+       if (performer) {
+               tracker_resource_set_property_resource (audio, "nmm:performer", performer);
        }
 
-       if (composer_uri) {
-               tracker_sparql_builder_predicate (metadata, "nmm:composer");
-               tracker_sparql_builder_object_iri (metadata, composer_uri);
+       if (composer) {
+               tracker_resource_set_property_resource (audio, "nmm:composer", composer);
        }
 
-       if (album_uri) {
-               tracker_sparql_builder_predicate (metadata, "nmm:musicAlbum");
-               tracker_sparql_builder_object_iri (metadata, album_uri);
+       if (album) {
+               tracker_resource_set_property_resource (audio, "nmm:musicAlbum", album);
        }
 
-       if (album_disc_uri) {
-               tracker_sparql_builder_predicate (metadata, "nmm:musicAlbumDisc");
-               tracker_sparql_builder_object_iri (metadata, album_disc_uri);
+       if (album_disc) {
+               tracker_resource_set_property_resource (audio, "nmm:musicAlbumDisc", album_disc);
        }
 }
 
 static void
-extractor_apply_video_metadata (MetadataExtractor    *extractor,
-                                GstTagList           *tag_list,
-                                TrackerSparqlBuilder *metadata,
-                                const gchar          *performer_uri,
-                                const gchar          *composer_uri)
+extractor_apply_video_metadata (MetadataExtractor *extractor,
+                                GstTagList        *tag_list,
+                                TrackerResource   *video,
+                                TrackerResource   *performer,
+                                TrackerResource   *composer)
 {
-       add_string_gst_tag (metadata, "dc:source", tag_list, GST_TAG_CLASSIFICATION);
+       set_property_from_gst_tag (video, "dc:source", tag_list, GST_TAG_CLASSIFICATION);
 
-       if (performer_uri) {
-               tracker_sparql_builder_predicate (metadata, "nmm:leadActor");
-               tracker_sparql_builder_object_iri (metadata, performer_uri);
+       if (performer) {
+               tracker_resource_set_property_resource (video, "nmm:leadActor", performer);
        }
 
-       if (composer_uri) {
-               tracker_sparql_builder_predicate (metadata, "nmm:director");
-               tracker_sparql_builder_object_iri (metadata, composer_uri);
+       if (composer) {
+               tracker_resource_set_property_resource (video, "nmm:director", composer);
        }
 
-       add_keywords_gst_tag (metadata, tag_list);
+       set_keywords_from_gst_tag (video, tag_list);
 }
 
-static void
-extract_track_metadata (MetadataExtractor    *extractor,
-                        TrackerTocEntry      *toc_entry,
-                        const gchar          *file_url,
-                        TrackerSparqlBuilder *preupdate,
-                        TrackerSparqlBuilder *postupdate,
-                        const gchar          *graph,
-                        const gchar          *album_uri,
-                        const gchar          *album_disc_uri)
+static TrackerResource *
+extract_track (MetadataExtractor    *extractor,
+               TrackerTocEntry      *toc_entry,
+               const gchar          *file_url)
 {
-       gchar *track_performer_uri = NULL;
-       gchar *track_composer_uri = NULL;
+       TrackerResource *track;
+       TrackerResource *track_performer = NULL, *track_composer = NULL;
        gchar *track_uri;
 
        track_uri = tracker_sparql_get_uuid_urn ();
+       track = tracker_resource_new (track_uri);
 
-       tracker_sparql_builder_subject_iri (postupdate, track_uri);
-
-       tracker_sparql_builder_predicate (postupdate, "a");
-       tracker_sparql_builder_object (postupdate, "nmm:MusicPiece");
-       tracker_sparql_builder_object (postupdate, "nfo:Audio");
+       tracker_resource_add_property_uri (track, "rdf:type", "nmm:MusicPiece");
+       tracker_resource_add_property_uri (track, "rdf:type", "nfo:Audio");
 
        extractor_apply_general_metadata (extractor,
                                          toc_entry->tag_list,
                                          file_url,
-                                         preupdate,
-                                         postupdate,
-                                         graph,
-                                         &track_performer_uri,
-                                         &track_composer_uri);
+                                         track,
+                                         &track_performer,
+                                         &track_composer);
 
        extractor_apply_audio_metadata (extractor,
                                        toc_entry->tag_list,
-                                       postupdate,
-                                       track_performer_uri,
-                                       track_composer_uri,
-                                       album_uri,
-                                       album_disc_uri);
+                                       track,
+                                       track_performer,
+                                       track_composer,
+                                       album_disc);
 
        if (toc_entry->duration > 0) {
-               tracker_sparql_builder_predicate (postupdate, "nfo:duration");
-               tracker_sparql_builder_object_int64 (postupdate, (gint64)toc_entry->duration);
+               tracker_resource_set_property_int64 (track, "nfo:duration", (gint64)toc_entry->duration);
        } else if (extractor->toc->entry_list &&
                   toc_entry == g_list_last (extractor->toc->entry_list)->data) {
                /* The last element may not have a duration, because it depends
@@ -1020,19 +806,10 @@ extract_track_metadata (MetadataExtractor    *extractor,
                 * cue sheet. In this case figure the data out from the total
                 * duration.
                 */
-               tracker_sparql_builder_predicate (postupdate, "nfo:duration");
-               tracker_sparql_builder_object_int64 (postupdate,
-                                                    (gint64) extractor->duration - toc_entry->start);
+               tracker_resource_set_property_int64 (track, "nfo:duration", (gint64)extractor->duration - 
toc_entry->start);
        }
 
-       tracker_sparql_builder_predicate (postupdate, "nfo:audioOffset");
-       tracker_sparql_builder_object_double (postupdate, toc_entry->start);
-
-       /* Link the track to its container file. Since the file might not have been
-        * inserted yet, we use a WHERE clause based on its nie:url to refer to it.
-        */
-       tracker_sparql_builder_predicate (postupdate, "nie:isStoredAs");
-       tracker_sparql_builder_object_variable (postupdate, "file");
+       tracker_resource_set_property_double (track, "nfo:audioOffset", toc_entry->start);
 
        g_free (track_performer_uri);
        g_free (track_composer_uri);
@@ -1040,40 +817,6 @@ extract_track_metadata (MetadataExtractor    *extractor,
        g_free (track_uri);
 }
 
-static void
-delete_existing_tracks (TrackerSparqlBuilder *postupdate,
-                        const gchar          *graph,
-                        const gchar          *file_url)
-{
-       gchar *sparql;
-
-       /* Delete existing tracks */
-
-       tracker_sparql_builder_delete_open (postupdate, NULL);
-       if (graph) {
-               tracker_sparql_builder_graph_open (postupdate, graph);
-       }
-
-       tracker_sparql_builder_subject_variable (postupdate, "track");
-       tracker_sparql_builder_predicate (postupdate, "a");
-       tracker_sparql_builder_object (postupdate, "nmm:MusicPiece");
-
-       if (graph) {
-               tracker_sparql_builder_graph_close (postupdate);
-       }
-       tracker_sparql_builder_delete_close (postupdate);
-
-       sparql = g_strdup_printf ("WHERE { "
-                                 "  ?track a nmm:MusicPiece . "
-                                 "  ?file a nfo:FileDataObject ; "
-                                 "        nie:url \"%s\" . "
-                                 "  ?track nie:isStoredAs ?file "
-                                 "} \n",
-                                 file_url);
-       tracker_sparql_builder_append (postupdate, sparql);
-       g_free (sparql);
-}
-
 #define CHUNK_N_BYTES (2 << 15)
 
 static guint64
@@ -1125,18 +868,11 @@ end:
        return 0;
 }
 
-static void
+static TrackerResource *
 extract_metadata (MetadataExtractor      *extractor,
-                  const gchar            *file_url,
-                  TrackerSparqlBuilder   *preupdate,
-                  TrackerSparqlBuilder   *postupdate,
-                  TrackerSparqlBuilder   *metadata,
-                  const gchar            *graph)
+                  const gchar            *file_url)
 {
        g_return_if_fail (extractor != NULL);
-       g_return_if_fail (preupdate != NULL);
-       g_return_if_fail (postupdate != NULL);
-       g_return_if_fail (metadata != NULL);
 
 #ifdef HAVE_LIBMEDIAART
        extractor->media_art_type = MEDIA_ART_NONE;
@@ -1184,130 +920,109 @@ extract_metadata (MetadataExtractor      *extractor,
        if (extractor->mime == EXTRACT_MIME_GUESS) {
                g_warning ("Cannot guess real stream type if no tags were read! "
                           "Defaulting to Video.");
-               tracker_sparql_builder_predicate (metadata, "a");
-               tracker_sparql_builder_object (metadata, "nmm:Video");
+               tracker_resource_set_property_uri (resource, "rdf:type", "nmm:Video");
        } else {
-               tracker_sparql_builder_predicate (metadata, "a");
-
                if (extractor->mime == EXTRACT_MIME_AUDIO) {
                        /* Audio: don't make an nmm:MusicPiece for the file resource if it's
                         * actually a container for an entire album - we will make a
                         * nmm:MusicPiece for each of the tracks inside instead.
                         */
-                       tracker_sparql_builder_object (metadata, "nfo:Audio");
+                       tracker_resource_set_property_uri (resource, "rdf:type", "nfo:Audio");
 
                        if (extractor->toc == NULL || extractor->toc->entry_list == NULL)
-                               tracker_sparql_builder_object (metadata, "nmm:MusicPiece");
+                               tracker_resource_add_property_uri (resource, "rdf:type", "nfo:MusicPiece");
 
 #ifdef HAVE_LIBMEDIAART
                        extractor->media_art_type = MEDIA_ART_ALBUM;
 #endif
                } else if (extractor->mime == EXTRACT_MIME_VIDEO) {
-                       tracker_sparql_builder_object (metadata, "nmm:Video");
+                       tracker_resource_set_property_uri (resource, "rdf:type", "nmm:Video");
 
 #ifdef HAVE_LIBMEDIAART
                        extractor->media_art_type = MEDIA_ART_VIDEO;
 #endif
                } else {
-                       tracker_sparql_builder_object (metadata, "nfo:Image");
-                       tracker_sparql_builder_object (metadata, "nmm:Photo");
+                       tracker_resource_set_property_uri_list (resource, "rdf:type",
+                                                               "nfo:Image", "nmm:Photo", NULL);
                }
        }
 
        if (!gst_tag_list_is_empty (extractor->tagcache)) {
                GList *node;
-               gchar *performer_uri = NULL;
-               gchar *composer_uri = NULL;
-               gchar *album_artist_uri = NULL;
-               gchar *album_uri = NULL;
-               gchar *album_disc_uri = NULL;
+               TrackerResource *equipment;
+               TrackerResource *geolocation, *address;
+               TrackerResource *performer = NULL, *composer = NULL;
+               TrackerResource *album_disc;
 
                extractor_apply_general_metadata (extractor,
                                                  extractor->tagcache,
                                                  file_url,
-                                                 preupdate,
-                                                 metadata,
-                                                 graph,
-                                                 &performer_uri,
-                                                 &composer_uri);
-
-               extractor_apply_device_metadata (extractor,
-                                                extractor->tagcache,
-                                                preupdate,
-                                                metadata,
-                                                graph);
-
-               extractor_apply_geolocation_metadata (extractor,
-                                                     extractor->tagcache,
-                                                     preupdate,
-                                                     metadata,
-                                                     graph);
+                                                 &performer,
+                                                 &composer);
+
+               equipment = extractor_get_equipment (extractor, extractor->tagcache);
+               if (equipment) {
+                       tracker_resource_set_property_resource (main_resource, "nfo:equipment", equipment);
+                       g_object_unref (equipment);
+               }
+
+               geolocation = extractor_get_geolocation (extractor, extractor->tagcache);
+               if (geolocation) {
+                       tracker_resource_set_property (main_resource, "slo:location", geolocation);
+                       g_object_unref (geolocation);
+               }
+
+               address = extractor_get_address (extractor, extractor->tagcache);
+               if (address) {
+                       tracker_resource_set_property (main_resource, "slo:postalAddress", address);
+                       g_object_unref (address);
+               }
 
                if (extractor->mime == EXTRACT_MIME_VIDEO) {
                        extractor_apply_video_metadata (extractor,
                                                        extractor->tagcache,
-                                                       metadata,
-                                                       performer_uri,
-                                                       composer_uri);
+                                                       main_resource,
+                                                       performer,
+                                                       composer);
                }
 
                if (extractor->mime == EXTRACT_MIME_AUDIO) {
-                       extractor_apply_album_metadata (extractor,
-                                                       extractor->tagcache,
-                                                       preupdate,
-                                                       graph,
-                                                       &album_artist_uri,
-                                                       &album_uri,
-                                                       &album_disc_uri);
+                       album_disc = extractor_get_album_disc (extractor, extractor->tagcache);
 
                        extractor_apply_audio_metadata (extractor,
                                                        extractor->tagcache,
                                                        metadata,
-                                                       performer_uri,
-                                                       composer_uri,
-                                                       album_uri,
-                                                       album_disc_uri);
+                                                       performer,
+                                                       composer,
+                                                       album,
+                                                       album_disc);
 
                        /* If the audio file contains multiple tracks, we create the tracks
                         * as abstract information element types and relate them to the
                         * concrete nfo:FileDataObject using nie:isStoredAs.
                         */
                        if (extractor->toc && g_list_length (extractor->toc->entry_list) > 1) {
-                               delete_existing_tracks (postupdate, graph, file_url);
-
-                               tracker_sparql_builder_insert_open (postupdate, NULL);
-                               if (graph) {
-                                       tracker_sparql_builder_graph_open (postupdate, graph);
-                               }
+                               for (node = extractor->toc->entry_list; node; node = node->next) {
+                                       TrackerResource *track;
 
-                               for (node = extractor->toc->entry_list; node; node = node->next)
-                                       extract_track_metadata (extractor,
-                                                               node->data,
-                                                               file_url,
-                                                               preupdate,
-                                                               postupdate,
-                                                               graph,
-                                                               album_uri,
-                                                               album_disc_uri);
-
-                               if (graph) {
-                                       tracker_sparql_builder_graph_close (postupdate);
+                                       track = extract_track_metadata (extractor, node->data, file_url, 
album_disc);
+                                       tracker_resource_set_property_resource (track, "nie:isStoredAs", 
main_resource);
+                                       g_object_unref (track);
                                }
-                               tracker_sparql_builder_insert_close (postupdate);
 
-                               tracker_sparql_builder_where_open (postupdate);
-                               tracker_sparql_builder_subject_variable (postupdate, "file");
-                               tracker_sparql_builder_predicate (postupdate, "nie:url");
-                               tracker_sparql_builder_object_string (postupdate, file_url);
-                               tracker_sparql_builder_where_close (postupdate);
+                               tracker_resource_set_property_string (main_resource, "nie:url", file_url);
                        }
+
+                       g_object_unref (album_disc);
                }
 
-               g_free (performer_uri);
-               g_free (composer_uri);
-               g_free (album_uri);
-               g_free (album_disc_uri);
-               g_free (album_artist_uri);
+               if (performer) {
+                       g_object_unref (performer);
+               }
+
+               if (composer) {
+                       g_object_unref (composer);
+               }
        }
 
        /* OpenSubtitles compatible hash */
@@ -1320,31 +1035,28 @@ extract_metadata (MetadataExtractor      *extractor,
                g_object_unref (file);
 
                if (hash) {
+                       TrackerResource *hash_resource;
                        char *hash_str;
 
-                       /* { <foo> a nfo:FileHash; nfo:hashValue "..."; nfo:hashAlgorithm "gibest" } */
-                       tracker_sparql_builder_predicate (metadata, "nfo:hasHash");
+                       hash_resource = tracker_resource_new (NULL);
+                       tracker_resource_set_property_uri (hash_resource, "rdf:type", "nfo:FileHash");
 
-                       tracker_sparql_builder_object_blank_open (metadata);
-                       tracker_sparql_builder_predicate (metadata, "a");
-                       tracker_sparql_builder_object (metadata, "nfo:FileHash");
-
-                       tracker_sparql_builder_predicate (metadata, "nfo:hashValue");
                        hash_str = g_strdup_printf ("%" G_GSIZE_MODIFIER "x", hash);
-                       tracker_sparql_builder_object_string (metadata, hash_str);
+                       tracker_resource_set_property_string (hash_resource, "nfo:hashValue", hash_str);
                        g_free (hash_str);
 
-                       tracker_sparql_builder_predicate (metadata, "nfo:hashAlgorithm");
-                       tracker_sparql_builder_object_string (metadata, "gibest");
+                       tracker_resource_set_property_string (resource, "nfo:hashAlgorithm", "gibest");
+
+                       tracker_resource_set_property_string_resource (main_resource, "nfo:hasHash", 
hash_resource);
 
-                       tracker_sparql_builder_object_blank_close (metadata);
+                       g_object_unref (hash_resource);
                }
        }
 
        /* If content was encrypted, set it. */
 /* #warning TODO: handle encrypted content with the Discoverer/GUPnP-DLNA backends */
 
-       common_extract_stream_metadata (extractor, file_url, metadata);
+       common_extract_stream_metadata (extractor, file_url, main_resource);
 
 #ifdef HAVE_LIBMEDIAART
        if (extractor->mime == EXTRACT_MIME_AUDIO) {
@@ -1358,30 +1070,26 @@ extract_metadata (MetadataExtractor      *extractor,
 static void
 common_extract_stream_metadata (MetadataExtractor    *extractor,
                                 const gchar          *uri,
-                                TrackerSparqlBuilder *metadata)
+                                TrackerResource      *resource)
 {
        if (extractor->mime == EXTRACT_MIME_AUDIO ||
            extractor->mime == EXTRACT_MIME_VIDEO) {
                if (extractor->audio_channels >= 0) {
-                       tracker_sparql_builder_predicate (metadata, "nfo:channels");
-                       tracker_sparql_builder_object_int64 (metadata, extractor->audio_channels);
+                       tracker_resource_set_property_int64 (resource, "nfo:channels", 
extractor->audio_channels);
                }
 
                if (extractor->audio_samplerate >= 0) {
-                       tracker_sparql_builder_predicate (metadata, "nfo:sampleRate");
-                       tracker_sparql_builder_object_int64 (metadata, extractor->audio_samplerate);
+                       tracker_resource_set_property_int64 (resource, "nfo:sampleRate", 
extractor->audio_samplerate);
                }
 
                if (extractor->duration >= 0) {
-                       tracker_sparql_builder_predicate (metadata, "nfo:duration");
-                       tracker_sparql_builder_object_int64 (metadata, extractor->duration);
+                       tracker_resource_set_property_int64 (resource, "nfo:duration", extractor->duration);
                }
        }
 
        if (extractor->mime == EXTRACT_MIME_VIDEO) {
                if (extractor->video_fps >= 0) {
-                       tracker_sparql_builder_predicate (metadata, "nfo:frameRate");
-                       tracker_sparql_builder_object_double (metadata, (gdouble)extractor->video_fps);
+                       tracker_resource_set_property_double (resource, "nfo:frameRate", 
(gdouble)extractor->video_fps);
                }
        }
 
@@ -1389,32 +1097,27 @@ common_extract_stream_metadata (MetadataExtractor    *extractor,
            extractor->mime == EXTRACT_MIME_VIDEO) {
 
                if (extractor->width >= 0) {
-                       tracker_sparql_builder_predicate (metadata, "nfo:width");
-                       tracker_sparql_builder_object_int64 (metadata, extractor->width);
+                       tracker_resource_set_property_int64 (resource, "nfo:width", extractor->width);
                }
 
                if (extractor->height >= 0) {
-                       tracker_sparql_builder_predicate (metadata, "nfo:height");
-                       tracker_sparql_builder_object_int64 (metadata, extractor->height);
+                       tracker_resource_set_property_int64 (resource, "nfo:height", extractor->height);
                }
 
                if (extractor->aspect_ratio >= 0) {
-                       tracker_sparql_builder_predicate (metadata, "nfo:aspectRatio");
-                       tracker_sparql_builder_object_double (metadata, (gdouble)extractor->aspect_ratio);
+                       tracker_resource_set_property_double (resource, "nfo:aspectRatio", 
(gdouble)extractor->aspect_ratio);
                }
        }
 
 #if defined(GSTREAMER_BACKEND_GUPNP_DLNA)
        if (extractor->dlna_profile) {
-               tracker_sparql_builder_predicate (metadata, "nmm:dlnaProfile");
-               tracker_sparql_builder_object_string (metadata, extractor->dlna_profile);
+               tracker_resource_set_property_string (resource, "nmm:dlnaProfile", extractor->dlna_profile);
        } else {
                g_debug ("No DLNA profile found");
        }
 
        if (extractor->dlna_mime) {
-               tracker_sparql_builder_predicate (metadata, "nmm:dlnaMime");
-               tracker_sparql_builder_object_string (metadata, extractor->dlna_mime);
+               tracker_resource_set_property_string (resource, "nmm:dlnaMime", extractor->dlna_mime);
        } else {
                g_debug ("No DLNA mime found");
        }
@@ -1608,13 +1311,12 @@ discoverer_init_and_run (MetadataExtractor *extractor,
 #endif /* defined(GSTREAMER_BACKEND_DISCOVERER) || \
           defined(GSTREAMER_BACKEND_GUPNP_DLNA) */
 
-static void
+static TrackerResource *
 tracker_extract_gstreamer (const gchar          *uri,
                            TrackerExtractInfo   *info,
-                           ExtractMime           type,
-                           const gchar          *graph)
+                           ExtractMime           type)
 {
-       TrackerSparqlBuilder *metadata, *preupdate, *postupdate;
+       TrackerResource *main_resource;
        MetadataExtractor *extractor;
        GstBuffer *buffer;
        gchar *cue_sheet;
@@ -1626,13 +1328,6 @@ tracker_extract_gstreamer (const gchar          *uri,
 
        g_return_if_fail (uri);
 
-       graph = tracker_extract_info_get_graph (info);
-       metadata = tracker_extract_info_get_metadata_builder (info);
-       preupdate = tracker_extract_info_get_preupdate_builder (info);
-       postupdate = tracker_extract_info_get_postupdate_builder (info);
-
-       g_return_if_fail (metadata);
-
        gst_init (NULL, NULL);
 
        extractor = g_slice_new0 (MetadataExtractor);
@@ -1661,12 +1356,7 @@ tracker_extract_gstreamer (const gchar          *uri,
                        extractor->toc = tracker_cue_sheet_parse_uri (uri);
                }
 
-               extract_metadata (extractor,
-                                 uri,
-                                 preupdate,
-                                 postupdate,
-                                 metadata,
-                                 graph);
+               main_resource = extract_metadata (extractor, uri);
 
 #ifdef HAVE_LIBMEDIAART
                if (extractor->media_art_type != MEDIA_ART_NONE &&
@@ -1724,12 +1414,14 @@ tracker_extract_gstreamer (const gchar          *uri,
 
        tracker_toc_free (extractor->toc);
 
-       g_slist_foreach (extractor->artist_list, (GFunc)g_free, NULL);
+       g_slist_foreach (extractor->artist_list, (GFunc)g_object_unref, NULL);
        g_slist_free (extractor->artist_list);
 
        discoverer_shutdown (extractor);
 
        g_slice_free (MetadataExtractor, extractor);
+
+       return main)resource;
 }
 
 G_MODULE_EXPORT gboolean
@@ -1737,17 +1429,16 @@ tracker_extract_get_metadata (TrackerExtractInfo *info)
 {
        GFile *file;
        gchar *uri;
-       const gchar *graph;
        const gchar *mimetype;
+       TrackerResource *main_resource;
 
        file = tracker_extract_info_get_file (info);
        uri = g_file_get_uri (file);
-       graph = tracker_extract_info_get_graph (info);
        mimetype = tracker_extract_info_get_mimetype (info);
 
 #if defined(GSTREAMER_BACKEND_GUPNP_DLNA)
        if (g_str_has_prefix (mimetype, "dlna/")) {
-               tracker_extract_gstreamer (uri, info, EXTRACT_MIME_GUESS, graph);
+               main_resource = tracker_extract_gstreamer (uri, info, EXTRACT_MIME_GUESS);
        } else
 #endif /* GSTREAMER_BACKEND_GUPNP_DLNA */
 
@@ -1756,18 +1447,21 @@ tracker_extract_get_metadata (TrackerExtractInfo *info)
                    strcmp (mimetype, "video/x-ms-asf") == 0 ||
                    strcmp (mimetype, "application/vnd.ms-asf") == 0 ||
                   strcmp (mimetype, "application/vnd.rn-realmedia") == 0) {
-               tracker_extract_gstreamer (uri, info, EXTRACT_MIME_GUESS, graph);
+               main_resource = tracker_extract_gstreamer (uri, info, EXTRACT_MIME_GUESS);
        } else if (g_str_has_prefix (mimetype, "audio/")) {
-               tracker_extract_gstreamer (uri, info, EXTRACT_MIME_AUDIO, graph);
+               main_resource = tracker_extract_gstreamer (uri, info, EXTRACT_MIME_AUDIO);
        } else if (g_str_has_prefix (mimetype, "video/")) {
-               tracker_extract_gstreamer (uri, info, EXTRACT_MIME_VIDEO, graph);
+               main_resource = tracker_extract_gstreamer (uri, info, EXTRACT_MIME_VIDEO);
        } else if (g_str_has_prefix (mimetype, "image/")) {
-               tracker_extract_gstreamer (uri, info, EXTRACT_MIME_IMAGE, graph);
+               main_resource = tracker_extract_gstreamer (uri, info, EXTRACT_MIME_IMAGE);
        } else {
                g_free (uri);
                return FALSE;
        }
 
+       tracker_extract_info_add_resource (main_resource);
+       g_object_unref (main_resource);
+
        g_free (uri);
        return TRUE;
 }


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