[tracker/cuesheets: 18/18] tracker-extract-gstreamer: Use ToC information



commit 906aad1582fd279c953cb4f9198c2f5ed86bc9f3
Author: Sam Thursfield <sam thursfield codethink co uk>
Date:   Tue Aug 23 18:15:09 2011 +0100

    tracker-extract-gstreamer: Use ToC information
    
    Fixes GB#657183

 src/tracker-extract/tracker-extract-gstreamer.c |  128 ++++++++++++++++++++++-
 1 files changed, 127 insertions(+), 1 deletions(-)
---
diff --git a/src/tracker-extract/tracker-extract-gstreamer.c b/src/tracker-extract/tracker-extract-gstreamer.c
index 5a3ec10..41767e5 100644
--- a/src/tracker-extract/tracker-extract-gstreamer.c
+++ b/src/tracker-extract/tracker-extract-gstreamer.c
@@ -54,6 +54,7 @@
 #include <libtracker-extract/tracker-extract.h>
 
 #include "tracker-albumart.h"
+#include "tracker-cue-sheet.h"
 
 /* We wait this long (seconds) for NULL state before freeing */
 #define TRACKER_EXTRACT_GUARD_TIMEOUT 3
@@ -99,6 +100,7 @@ typedef enum {
 typedef struct {
 	ExtractMime     mime;
 	GstTagList     *tagcache;
+	TrackerToc     *toc;
 	gboolean        is_content_encrypted;
 
 	GSList         *artist_list;
@@ -352,6 +354,25 @@ replace_double_gst_tag (TrackerSparqlBuilder  *preupdate,
 	tracker_sparql_builder_insert_close (preupdate);
 }
 
+static void
+get_embedded_cue_sheet_data (GstTagList  *tag_list,
+                             gchar      **p_data)
+{
+	gint i, count;
+	gchar *buffer;
+
+	count = gst_tag_list_get_tag_size (tag_list, GST_TAG_EXTENDED_COMMENT);
+	for (i = 0; i < count; i++) {
+		gst_tag_list_get_string_index (tag_list, GST_TAG_EXTENDED_COMMENT, i, &buffer);
+
+		if (strncmp (buffer, "cuesheet=", 9) == 0) {
+			*p_data = buffer;
+			break;
+		}
+
+		g_free (buffer);
+	}
+}
 
 static gboolean
 get_embedded_album_art (MetadataExtractor *extractor)
@@ -723,6 +744,68 @@ extractor_apply_video_metadata (MetadataExtractor    *extractor,
 }
 
 static void
+extract_track_metadata (MetadataExtractor    *extractor,
+                        TrackerTocEntry      *toc_entry,
+                        const gchar          *file_url,
+                        TrackerSparqlBuilder *preupdate,
+                        const gchar          *album_uri,
+                        const gchar          *album_disc_uri)
+{
+	TrackerSparqlBuilder *track_metadata;
+	gchar *track_performer_uri = NULL;
+	gchar *track_composer_uri = NULL;
+	gchar *track_uri;
+	gchar *track_url;
+
+	track_uri = tracker_sparql_get_uuid_urn ();
+
+	track_metadata = tracker_sparql_builder_new_update ();
+	tracker_sparql_builder_insert_open (track_metadata, NULL);
+	tracker_sparql_builder_subject_iri (track_metadata, track_uri);
+
+	tracker_sparql_builder_predicate (track_metadata, "a");
+	tracker_sparql_builder_object (track_metadata, "nfo:MusicPiece");
+
+	extractor_apply_general_metadata (extractor,
+	                                  toc_entry->tag_list,
+	                                  file_url,
+	                                  preupdate,
+	                                  track_metadata,
+	                                  &track_performer_uri,
+	                                  &track_composer_uri);
+
+	extractor_apply_audio_metadata (extractor,
+	                                toc_entry->tag_list,
+	                                track_metadata,
+	                                track_performer_uri,
+	                                track_composer_uri,
+	                                album_uri,
+	                                album_disc_uri);
+
+	if (toc_entry->duration > 0) {
+		tracker_sparql_builder_predicate (track_metadata, "nmm:duration");
+		tracker_sparql_builder_object_int64 (track_metadata, (gint64)toc_entry->duration);
+	}
+
+	track_url = g_strdup_printf ("%s#%lf", file_url, toc_entry->start);
+	tracker_sparql_builder_predicate (track_metadata, "nie:url");
+	tracker_sparql_builder_object_unvalidated (track_metadata, track_url);
+
+	tracker_sparql_builder_insert_close (track_metadata);
+
+	tracker_sparql_builder_append (preupdate,
+	                               tracker_sparql_builder_get_result (track_metadata));
+
+	g_object_unref (track_metadata);
+
+	g_free (track_performer_uri);
+	g_free (track_composer_uri);
+
+	g_free (track_uri);
+	g_free (track_url);
+}
+
+static void
 extract_metadata (MetadataExtractor      *extractor,
                   const gchar            *file_url,
                   TrackerSparqlBuilder   *preupdate,
@@ -733,6 +816,11 @@ extract_metadata (MetadataExtractor      *extractor,
 	g_return_if_fail (extractor != NULL);
 	g_return_if_fail (metadata != NULL);
 
+	if (extractor->toc)
+		gst_tag_list_insert (extractor->tagcache,
+		                     extractor->toc->tag_list,
+		                     GST_TAG_MERGE_REPLACE);
+
 	if (extractor->mime == EXTRACT_MIME_GUESS && extractor->tagcache)
 		extractor_guess_content_type (extractor);
 
@@ -745,8 +833,14 @@ extract_metadata (MetadataExtractor      *extractor,
 		tracker_sparql_builder_predicate (metadata, "a");
 
 		if (extractor->mime == EXTRACT_MIME_AUDIO) {
-			tracker_sparql_builder_object (metadata, "nmm:MusicPiece");
+			/* 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");
+
+			if (extractor->toc == NULL || extractor->toc->entry_list == NULL)
+				tracker_sparql_builder_object (metadata, "nmm:MusicPiece");
 		} else if (extractor->mime == EXTRACT_MIME_VIDEO) {
 			tracker_sparql_builder_object (metadata, "nmm:Video");
 		} else {
@@ -761,6 +855,7 @@ extract_metadata (MetadataExtractor      *extractor,
 	}
 
 	if (!gst_tag_list_is_empty (extractor->tagcache)) {
+		GList *node;
 		gchar *performer_uri = NULL;
 		gchar *composer_uri = NULL;
 		gchar *album_artist_uri = NULL;
@@ -804,6 +899,16 @@ extract_metadata (MetadataExtractor      *extractor,
 			                                composer_uri,
 			                                album_uri,
 			                                album_disc_uri);
+
+			if (extractor->toc && g_list_length (extractor->toc->entry_list) > 1) {
+				for (node=extractor->toc->entry_list; node; node=node->next)
+					extract_track_metadata (extractor,
+					                        node->data,
+					                        file_url,
+					                        preupdate,
+					                        album_uri,
+					                        album_disc_uri);
+			}
 		}
 
 		g_free (performer_uri);
@@ -1574,6 +1679,7 @@ tracker_extract_gstreamer (const gchar          *uri,
 	extractor = g_slice_new0 (MetadataExtractor);
 	extractor->mime = type;
 	extractor->tagcache = gst_tag_list_new ();
+	extractor->toc = NULL;
 	extractor->artist_list = NULL;
 	extractor->album_art_data = NULL;
 	extractor->album_art_size = 0;
@@ -1590,6 +1696,22 @@ tracker_extract_gstreamer (const gchar          *uri,
 		return;
 #endif
 
+	if (extractor->tagcache) {
+		gchar *cue_sheet = NULL;
+
+		get_embedded_cue_sheet_data (extractor->tagcache, &cue_sheet);
+
+		if (cue_sheet) {
+			extractor->toc = tracker_parse_cue_sheet (cue_sheet + strlen("cuesheet="));
+			g_free (cue_sheet);
+			g_debug ("Using embedded CUE sheet.");
+		}
+	}
+
+	if (extractor->toc == NULL) {
+		extractor->toc = tracker_process_external_cue_sheets (uri);
+	}
+
 	album_artist = NULL;
 	album_title = NULL;
 
@@ -1607,6 +1729,10 @@ tracker_extract_gstreamer (const gchar          *uri,
 
 	gst_tag_list_free (extractor->tagcache);
 
+	if (extractor->toc) {
+		tracker_toc_free (extractor->toc);
+	}
+
 	g_slist_foreach (extractor->artist_list, (GFunc)g_free, NULL);
 	g_slist_free (extractor->artist_list);
 



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