[tracker] tracker-extract-totem.c: Use TrackerSparqlBuilder.
- From: Carlos Garnacho <carlosg src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [tracker] tracker-extract-totem.c: Use TrackerSparqlBuilder.
- Date: Wed, 4 Nov 2009 17:35:08 +0000 (UTC)
commit a00f6c4d5333cca0c43957e4a72e218c011b703f
Author: Carlos Garnacho <carlos lanedo com>
Date: Wed Nov 4 17:33:09 2009 +0100
tracker-extract-totem.c: Use TrackerSparqlBuilder.
src/tracker-extract/tracker-extract-totem.c | 123 ++++++++++++++++++++-------
1 files changed, 92 insertions(+), 31 deletions(-)
---
diff --git a/src/tracker-extract/tracker-extract-totem.c b/src/tracker-extract/tracker-extract-totem.c
index 484b2a1..ba76556 100644
--- a/src/tracker-extract/tracker-extract-totem.c
+++ b/src/tracker-extract/tracker-extract-totem.c
@@ -24,7 +24,6 @@
#include <glib.h>
#include <libtracker-common/tracker-os-dependant.h>
-#include <libtracker-common/tracker-statement-list.h>
#include <libtracker-common/tracker-ontology.h>
#include <libtracker-common/tracker-utils.h>
@@ -40,17 +39,18 @@
#define RDF_TYPE RDF_PREFIX "type"
static const gchar *tags[][2] = {
- { "TOTEM_INFO_VIDEO_HEIGHT", NFO_PREFIX "height" },
- { "TOTEM_INFO_VIDEO_WIDTH", NFO_PREFIX "width" },
- { "TOTEM_INFO_FPS", NFO_PREFIX "frameRate" },
- { "TOTEM_INFO_VIDEO_CODEC", NFO_PREFIX "codec" },
- { "TOTEM_INFO_VIDEO_BITRATE", NFO_PREFIX "averageBitrate" },
- { "TOTEM_INFO_TITLE", NIE_PREFIX "title" },
- { "TOTEM_INFO_AUTHOR", NCO_PREFIX "creator" },
- { "TOTEM_INFO_AUDIO_BITRATE", NMM_PREFIX "averageBitrate" },
- { "TOTEM_INFO_AUDIO_SAMPLE_RATE", NFO_PREFIX "sampleRate" },
- { "TOTEM_INFO_AUDIO_CODEC", NFO_PREFIX "codec" },
- { "TOTEM_INFO_AUDIO_CHANNELS", NFO_PREFIX "channels" },
+ { "TOTEM_INFO_VIDEO_HEIGHT", "nfo:height" },
+ { "TOTEM_INFO_VIDEO_WIDTH", "nfo:width" },
+ { "TOTEM_INFO_FPS", "nfo:frameRate" },
+ { "TOTEM_INFO_VIDEO_CODEC", "nfo:codec" },
+ { "TOTEM_INFO_VIDEO_BITRATE", "nfo:averageBitrate" },
+ { "TOTEM_INFO_TITLE", "nie:title" },
+ { "TOTEM_INFO_ARTIST", "nco:creator" },
+ { "TOTEM_INFO_ALBUM", "nmm:musicAlbum" },
+ { "TOTEM_INFO_AUDIO_BITRATE", "nmm:averageBitrate" },
+ { "TOTEM_INFO_AUDIO_SAMPLE_RATE", "nfo:sampleRate" },
+ { "TOTEM_INFO_AUDIO_CODEC", "nfo:codec" },
+ { "TOTEM_INFO_AUDIO_CHANNELS", "nfo:channels" },
{ NULL, NULL }
};
@@ -64,19 +64,38 @@ static TrackerExtractData data[] = {
};
static void
+metadata_write_foreach (gpointer key,
+ gpointer value,
+ gpointer user_data)
+{
+ TrackerSparqlBuilder *metadata = user_data;
+
+ tracker_sparql_builder_predicate (metadata, (const gchar *) key);
+ tracker_sparql_builder_object_unvalidated (metadata, (const gchar *) value);
+}
+
+static void
extract_totem (const gchar *uri,
TrackerSparqlBuilder *metadata)
{
gchar *argv[3];
gchar *totem;
gboolean has_video = FALSE;
+ GHashTable *tmp_metadata;
argv[0] = g_strdup ("totem-video-indexer");
argv[1] = g_filename_from_uri (uri, NULL, NULL);
argv[2] = NULL;
+ tmp_metadata = g_hash_table_new_full (g_str_hash,
+ g_str_equal,
+ (GDestroyNotify) g_free,
+ (GDestroyNotify) g_free);
+
if (tracker_spawn (argv, 10, &totem, NULL)) {
gchar **lines, **line;
+ gchar *artist = NULL, *album = NULL;
+ gchar *artist_uri = NULL, *album_uri = NULL;
lines = g_strsplit (totem, "\n", -1);
@@ -84,42 +103,84 @@ extract_totem (const gchar *uri,
gint i;
for (i = 0; tags[i][0]; i++) {
- if (g_strcmp0 (*line, "TOTEM_INFO_HAS_VIDEO=True")) {
+ if (g_strcmp0 (*line, "TOTEM_INFO_HAS_VIDEO=True") == 0) {
has_video = TRUE;
}
if (g_str_has_prefix (*line, tags[i][0])) {
gchar *value = (*line) + strlen (tags[i][0]) + 1;
- if (g_strcmp0 (tags[i][0], "TOTEM_INFO_AUTHOR")) {
- gchar *canonical_uri = tracker_uri_printf_escaped ("urn:artist:%s", value);
- tracker_statement_list_insert (metadata, canonical_uri, RDF_TYPE, NCO_PREFIX "Contact");
- tracker_statement_list_insert (metadata, canonical_uri, NCO_PREFIX "fullname", value);
- tracker_statement_list_insert (metadata, uri, tags[i][1], canonical_uri);
- g_free (canonical_uri);
+ if (g_strcmp0 (tags[i][0], "TOTEM_INFO_ARTIST") == 0) {
+ artist = g_strdup (value);
+ artist_uri = tracker_uri_printf_escaped ("urn:artist:%s", artist);
+ } else if (g_strcmp0 (tags[i][0], "TOTEM_INFO_ALBUM") == 0) {
+ album = g_strdup (value);
+ album_uri = tracker_uri_printf_escaped ("urn:album:%s", album);
} else {
- tracker_statement_list_insert (metadata, uri,
- tags[i][1],
- value);
+ g_hash_table_insert (tmp_metadata, g_strdup (tags[i][1]), g_strdup (value));
}
break;
}
}
}
+ if (artist) {
+ tracker_sparql_builder_subject_iri (metadata, artist_uri);
+ tracker_sparql_builder_predicate (metadata, "a");
+ tracker_sparql_builder_object (metadata, "nmm:Artist");
+
+ if (has_video) {
+ tracker_sparql_builder_object (metadata, "nmm:director");
+ } else {
+ tracker_sparql_builder_object (metadata, "nmm:composer");
+ }
+
+ tracker_sparql_builder_predicate (metadata, "nmm:artistName");
+ tracker_sparql_builder_object_unvalidated (metadata, artist);
+ }
+
+ if (album) {
+ tracker_sparql_builder_subject_iri (metadata, album_uri);
+ tracker_sparql_builder_predicate (metadata, "a");
+ tracker_sparql_builder_object (metadata, "nmm:MusicAlbum");
+ tracker_sparql_builder_predicate (metadata, "nmm:albumTitle");
+ tracker_sparql_builder_object_unvalidated (metadata, album);
+ }
+
+ tracker_sparql_builder_subject_iri (metadata, uri);
+ tracker_sparql_builder_predicate (metadata, "a");
+
if (has_video) {
- tracker_statement_list_insert (metadata, uri,
- RDF_TYPE,
- NMM_PREFIX "Video");
+ tracker_sparql_builder_object (metadata, "nmm:Video");
} else {
- tracker_statement_list_insert (metadata, uri,
- RDF_TYPE,
- NMM_PREFIX "MusicPiece");
- tracker_statement_list_insert (metadata, uri,
- RDF_TYPE,
- NFO_PREFIX "Audio");
+ tracker_sparql_builder_object (metadata, "nmm:MusicPiece");
+ tracker_sparql_builder_object (metadata, "nfo:Audio");
}
+
+ g_hash_table_foreach (tmp_metadata, metadata_write_foreach, metadata);
+
+ if (artist) {
+ if (has_video) {
+ tracker_sparql_builder_object (metadata, "nmm:leadActor");
+ } else {
+ tracker_sparql_builder_predicate (metadata, "nmm:performer");
+ }
+
+ tracker_sparql_builder_object_iri (metadata, artist_uri);
+ }
+
+ if (album && !has_video) {
+ tracker_sparql_builder_predicate (metadata, "nmm:musicAlbum");
+ tracker_sparql_builder_object_iri (metadata, album_uri);
+ }
+
+ g_free (album_uri);
+ g_free (artist_uri);
+ g_free (album);
+ g_free (artist);
}
+
+ g_hash_table_destroy (tmp_metadata);
}
TrackerExtractData *
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]