[tracker] tracker-extract-playlist: Support nie:title for the playlist



commit ea88b91b5250475bc78616d17fa7509e932cbe8c
Author: Martyn Russell <martyn lanedo com>
Date:   Sat Feb 2 11:45:24 2013 +0000

    tracker-extract-playlist: Support nie:title for the playlist
    
    Fixed GB#692409, New: playlist extractor should index playlist title if
    available

 src/tracker-extract/tracker-extract-playlist.c |   72 +++++++++++++++---------
 1 files changed, 45 insertions(+), 27 deletions(-)
---
diff --git a/src/tracker-extract/tracker-extract-playlist.c b/src/tracker-extract/tracker-extract-playlist.c
index ba8a685..27fe39a 100644
--- a/src/tracker-extract/tracker-extract-playlist.c
+++ b/src/tracker-extract/tracker-extract-playlist.c
@@ -48,12 +48,27 @@
 typedef struct {
 	guint32 track_counter;
 	gint64 total_time;
+	gchar *title;
 	TrackerSparqlBuilder *metadata;
 } PlaylistMetadata;
 
 static void
+playlist_started (TotemPlParser         *parser,
+                  gchar                 *to_uri,
+                  TotemPlParserMetadata *to_metadata,
+                  gpointer               user_data)
+{
+	PlaylistMetadata *data;
+
+	data = (PlaylistMetadata *) user_data;
+
+	/* Avoid looking up every time */
+	data->title = g_strdup (g_hash_table_lookup (to_metadata, TOTEM_PL_PARSER_FIELD_TITLE));
+}
+
+static void
 entry_parsed (TotemPlParser *parser,
-              const gchar   *to_uri,
+              gchar         *to_uri,
               GHashTable    *to_metadata,
               gpointer       user_data)
 {
@@ -108,48 +123,51 @@ G_MODULE_EXPORT gboolean
 tracker_extract_get_metadata (TrackerExtractInfo *info)
 {
 	TotemPlParser *pl;
-	TotemPlParserResult  result;
-	TrackerSparqlBuilder *metadata = tracker_extract_info_get_metadata_builder (info);
-	PlaylistMetadata data = { 0, 0, metadata };
+	TrackerSparqlBuilder *metadata;
+	PlaylistMetadata data;
 	GFile *file;
 	gchar *uri;
 
 	pl = totem_pl_parser_new ();
 	file = tracker_extract_info_get_file (info);
 	uri = g_file_get_uri (file);
+	metadata = tracker_extract_info_get_metadata_builder (info);
+
+	data.track_counter = PLAYLIST_DEFAULT_NO_TRACKS;
+	data.total_time =  PLAYLIST_DEFAULT_DURATION;
+	data.title = NULL;
+	data.metadata = metadata;
 
 	g_object_set (pl, "recurse", FALSE, "disable-unsafe", TRUE, NULL);
 
-	g_signal_connect (G_OBJECT (pl), "entry-parsed",
-	                  G_CALLBACK (entry_parsed), &data);
+	g_signal_connect (G_OBJECT (pl), "playlist-started", G_CALLBACK (playlist_started), &data);
+	g_signal_connect (G_OBJECT (pl), "entry-parsed", G_CALLBACK (entry_parsed), &data);
 
 	tracker_sparql_builder_predicate (metadata, "a");
 	tracker_sparql_builder_object (metadata, "nmm:Playlist");
 	tracker_sparql_builder_object (metadata, "nfo:MediaList");
 
-	result = totem_pl_parser_parse (pl, uri, FALSE);
-
-	switch (result) {
-	case TOTEM_PL_PARSER_RESULT_SUCCESS:
-		break;
-	case TOTEM_PL_PARSER_RESULT_IGNORED:
-	case TOTEM_PL_PARSER_RESULT_ERROR:
-	case TOTEM_PL_PARSER_RESULT_UNHANDLED:
-		data.total_time = PLAYLIST_DEFAULT_NO_TRACKS;
-		data.track_counter = PLAYLIST_DEFAULT_DURATION;
-		break;
-	default:
-		g_warning ("Undefined result in totem-plparser");
-	}
+	if (totem_pl_parser_parse (pl, uri, FALSE) == TOTEM_PL_PARSER_RESULT_SUCCESS) {
+		if (data.title != NULL) {
+			g_message ("Playlist title:'%s'", data.title);
+			tracker_sparql_builder_predicate (metadata, "nie:title");
+			tracker_sparql_builder_object_unvalidated (metadata, data.title);
+			g_free (data.title);
+		} else {
+			g_message ("Playlist has no title");
+		}
 
-	if (data.total_time > 0) {
-		tracker_sparql_builder_predicate (metadata, "nfo:listDuration");
-		tracker_sparql_builder_object_int64 (metadata, data.total_time);
-	}
+		if (data.total_time > 0) {
+			tracker_sparql_builder_predicate (metadata, "nfo:listDuration");
+			tracker_sparql_builder_object_int64 (metadata, data.total_time);
+		}
 
-	if (data.track_counter > 0) {
-		tracker_sparql_builder_predicate (metadata, "nfo:entryCounter");
-		tracker_sparql_builder_object_int64 (metadata, data.track_counter);
+		if (data.track_counter > 0) {
+			tracker_sparql_builder_predicate (metadata, "nfo:entryCounter");
+			tracker_sparql_builder_object_int64 (metadata, data.track_counter);
+		}
+	} else {
+		g_warning ("Playlist could not be parsed, no error given");
 	}
 
 	g_object_unref (pl);



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