[tracker/cuesheets: 7/22] tracker-extract-gstreamer: Break up extract_metadata() into functions
- From: Sam Thursfield <sthursfield src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/cuesheets: 7/22] tracker-extract-gstreamer: Break up extract_metadata() into functions
- Date: Thu, 29 Sep 2011 10:02:14 +0000 (UTC)
commit ca5f7a71af2e102e42ccae7b4a7661b9d5862d50
Author: Sam Thursfield <sam thursfield codethink co uk>
Date: Thu Aug 18 18:49:43 2011 +0100
tracker-extract-gstreamer: Break up extract_metadata() into functions
src/tracker-extract/tracker-extract-gstreamer.c | 642 +++++++++++++----------
1 files changed, 354 insertions(+), 288 deletions(-)
---
diff --git a/src/tracker-extract/tracker-extract-gstreamer.c b/src/tracker-extract/tracker-extract-gstreamer.c
index 6cebd50..0e18e2c 100644
--- a/src/tracker-extract/tracker-extract-gstreamer.c
+++ b/src/tracker-extract/tracker-extract-gstreamer.c
@@ -432,351 +432,419 @@ get_embedded_album_art (MetadataExtractor *extractor)
return FALSE;
}
+
static void
-extract_metadata (MetadataExtractor *extractor,
- const gchar *file_url,
- TrackerSparqlBuilder *preupdate,
- TrackerSparqlBuilder *metadata,
- gchar **album_artist,
- gchar **album_title,
- const gchar *graph)
+extractor_guess_content_type (MetadataExtractor *extractor)
{
- gchar *model = NULL, *manuf = NULL;
- gchar *album_title_local = NULL, *genre = NULL;
-
- g_return_if_fail (extractor != NULL);
- g_return_if_fail (metadata != NULL);
-
- if (!gst_tag_list_is_empty (extractor->tagcache)) {
- gchar *performer_uri = NULL;
- gchar *composer_uri = NULL;
- gchar *album_artist_uri = NULL;
- gchar *album_uri = NULL;
- gchar *album_disc_uri = NULL;
- gchar *s;
-
- /* Try to guess content type */
- if (extractor->mime == EXTRACT_MIME_GUESS) {
#if defined(GSTREAMER_BACKEND_TAGREADBIN) || \
defined(GSTREAMER_BACKEND_DECODEBIN2)
- char *video_codec = NULL, *audio_codec = NULL;
+ char *video_codec = NULL, *audio_codec = NULL;
- gst_tag_list_get_string (extractor->tagcache, GST_TAG_VIDEO_CODEC, &video_codec);
- gst_tag_list_get_string (extractor->tagcache, GST_TAG_AUDIO_CODEC, &audio_codec);
+ gst_tag_list_get_string (extractor->tagcache, GST_TAG_VIDEO_CODEC, &video_codec);
+ gst_tag_list_get_string (extractor->tagcache, GST_TAG_AUDIO_CODEC, &audio_codec);
- g_debug ("Reading codecs from the stream... audio: '%s', video: '%s'",
- audio_codec ? audio_codec : "none",
- video_codec ? video_codec : "none");
+ g_debug ("Reading codecs from the stream... audio: '%s', video: '%s'",
+ audio_codec ? audio_codec : "none",
+ video_codec ? video_codec : "none");
- if (audio_codec && !video_codec) {
- extractor->mime = EXTRACT_MIME_AUDIO;
- } else {
- /* default to video */
- extractor->mime = EXTRACT_MIME_VIDEO;
- }
+ if (audio_codec && !video_codec) {
+ extractor->mime = EXTRACT_MIME_AUDIO;
+ } else {
+ /* default to video */
+ extractor->mime = EXTRACT_MIME_VIDEO;
+ }
- g_free (video_codec);
- g_free (audio_codec);
+ g_free (video_codec);
+ g_free (audio_codec);
#else /* DISCOVERER/GUPNP-DLNA... */
- if (extractor->has_video) {
- extractor->mime = EXTRACT_MIME_VIDEO;
- } else if (extractor->has_audio) {
- extractor->mime = EXTRACT_MIME_AUDIO;
- } else if (extractor->has_image) {
- extractor->mime = EXTRACT_MIME_IMAGE;
- } else {
- /* default to video */
- extractor->mime = EXTRACT_MIME_VIDEO;
- }
+ if (extractor->has_video) {
+ extractor->mime = EXTRACT_MIME_VIDEO;
+ } else if (extractor->has_audio) {
+ extractor->mime = EXTRACT_MIME_AUDIO;
+ } else if (extractor->has_image) {
+ extractor->mime = EXTRACT_MIME_IMAGE;
+ } else {
+ /* default to video */
+ extractor->mime = EXTRACT_MIME_VIDEO;
+ }
#endif /* DISCOVERER/GUPNP-DLNA... */
- }
+}
- /* General */
- if (extractor->mime == EXTRACT_MIME_AUDIO || extractor->mime == EXTRACT_MIME_VIDEO) {
- const gchar *performer = NULL;
- gchar *performer_temp = NULL;
- gchar *artist_temp = NULL;
- gchar *composer = NULL;
- gchar *album_artist_local = NULL;
+static void
+extractor_apply_general_metadata (MetadataExtractor *extractor,
+ const gchar *file_url,
+ TrackerSparqlBuilder *preupdate,
+ TrackerSparqlBuilder *metadata,
+ const gchar *graph,
+ gchar **p_performer_uri,
+ gchar **p_composer_uri)
+{
+ const gchar *performer = NULL;
+ gchar *performer_temp = NULL;
+ gchar *artist_temp = NULL;
+ gchar *composer = NULL;
+ gchar *genre = NULL;
+ gchar *title = NULL;
- gst_tag_list_get_string (extractor->tagcache, GST_TAG_PERFORMER, &performer_temp);
- gst_tag_list_get_string (extractor->tagcache, GST_TAG_ARTIST, &artist_temp);
- gst_tag_list_get_string (extractor->tagcache, GST_TAG_COMPOSER, &composer);
- gst_tag_list_get_string (extractor->tagcache, GST_TAG_ALBUM_ARTIST, &album_artist_local);
+ gst_tag_list_get_string (extractor->tagcache, GST_TAG_PERFORMER, &performer_temp);
+ gst_tag_list_get_string (extractor->tagcache, GST_TAG_ARTIST, &artist_temp);
+ gst_tag_list_get_string (extractor->tagcache, GST_TAG_COMPOSER, &composer);
- performer = tracker_coalesce_strip (2, performer_temp, artist_temp);
+ performer = tracker_coalesce_strip (2, performer_temp, artist_temp);
- if (performer != NULL) {
- add_artist (extractor, preupdate, graph, performer, &performer_uri);
- }
+ if (performer != NULL) {
+ add_artist (extractor, preupdate, graph, performer, p_performer_uri);
+ }
- if (composer != NULL) {
- add_artist (extractor, preupdate, graph, composer, &composer_uri);
- }
+ if (composer != NULL) {
+ add_artist (extractor, preupdate, graph, composer, p_composer_uri);
+ }
- if (album_artist_local != NULL) {
- add_artist (extractor, preupdate, graph, album_artist_local, &album_artist_uri);
+ gst_tag_list_get_string (extractor->tagcache, GST_TAG_GENRE, &genre);
+ gst_tag_list_get_string (extractor->tagcache, GST_TAG_TITLE, &title);
- *album_artist = g_strdup (album_artist_local);
- } else if (performer != NULL) {
- album_artist_uri = g_strdup (performer_uri);
+ if (genre && g_strcmp0 (genre, "Unknown") != 0) {
+ tracker_sparql_builder_predicate (metadata, "nfo:genre");
+ tracker_sparql_builder_object_unvalidated (metadata, genre);
+ }
- *album_artist = g_strdup (performer);
- }
+ tracker_guarantee_title_from_file (metadata, "nie:title", title, file_url);
+
+ add_date_time_gst_tag_with_mtime_fallback (metadata, file_url, "nie:contentCreated", extractor->tagcache, GST_TAG_DATE_TIME, GST_TAG_DATE);
+
+ add_string_gst_tag (metadata, "nie:copyright", extractor->tagcache, GST_TAG_COPYRIGHT);
+ add_string_gst_tag (metadata, "nie:license", extractor->tagcache, GST_TAG_LICENSE);
+ add_string_gst_tag (metadata, "dc:coverage", extractor->tagcache, GST_TAG_LOCATION);
+ add_string_gst_tag (metadata, "nie:comment", extractor->tagcache, GST_TAG_COMMENT);
+
+ g_free (performer_temp);
+ g_free (artist_temp);
+ g_free (composer);
+ g_free (genre);
+ g_free (title);
+}
- g_free (performer_temp);
- g_free (artist_temp);
- g_free (composer);
- g_free (album_artist_local);
+static void
+extractor_apply_album_metadata (MetadataExtractor *extractor,
+ TrackerSparqlBuilder *preupdate,
+ const gchar *graph,
+ gchar **p_album_artist_uri,
+ gchar **p_album_uri,
+ gchar **p_album_disc_uri,
+ gchar **p_album_artist,
+ gchar **p_album_title)
+{
+ gchar *album_artist;
+ gchar *album_title;
+ gchar *album_artist_temp = NULL;
+ gchar *track_artist_temp = NULL;
+ gboolean has_it;
+ guint count;
+
+ gst_tag_list_get_string (extractor->tagcache, GST_TAG_ALBUM, &album_title);
+
+ if (!album_title)
+ return;
+
+ gst_tag_list_get_string (extractor->tagcache, GST_TAG_ALBUM_ARTIST, &album_artist_temp);
+ gst_tag_list_get_string (extractor->tagcache, GST_TAG_ARTIST, &track_artist_temp);
+
+ album_artist = 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", album_title);
+
+ 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, "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);
+ }
+
+ if (graph) {
+ tracker_sparql_builder_graph_close (preupdate);
+ }
+ tracker_sparql_builder_insert_close (preupdate);
+
+ has_it = gst_tag_list_get_uint (extractor->tagcache,
+ 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);
}
- /* Audio */
+ tracker_sparql_builder_subject_iri (preupdate, *p_album_uri);
+ tracker_sparql_builder_predicate (preupdate, "nmm:albumTrackCount");
+ tracker_sparql_builder_object_int64 (preupdate, count);
- if (extractor->mime == EXTRACT_MIME_AUDIO) {
- gst_tag_list_get_string (extractor->tagcache, GST_TAG_ALBUM, &album_title_local);
+ if (graph) {
+ tracker_sparql_builder_graph_close (preupdate);
}
+ tracker_sparql_builder_insert_close (preupdate);
+ }
- if (album_title_local) {
- gboolean has_it;
- guint count;
+ has_it = gst_tag_list_get_uint (extractor->tagcache,
+ GST_TAG_ALBUM_VOLUME_NUMBER,
+ &count);
- album_uri = tracker_sparql_escape_uri_printf ("urn:album:%s", album_title_local);
+ *p_album_disc_uri = tracker_sparql_escape_uri_printf ("urn:album-disc:%s:Disc%d",
+ album_title,
+ has_it ? count : 1);
- tracker_sparql_builder_insert_open (preupdate, NULL);
- if (graph) {
- tracker_sparql_builder_graph_open (preupdate, graph);
- }
+ 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_subject_iri (preupdate, 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_local);
-
- if (album_artist_uri) {
- tracker_sparql_builder_predicate (preupdate, "nmm:albumArtist");
- tracker_sparql_builder_object_iri (preupdate, album_artist_uri);
- }
+ 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);
- if (graph) {
- tracker_sparql_builder_graph_close (preupdate);
- }
- tracker_sparql_builder_insert_close (preupdate);
-
- has_it = gst_tag_list_get_uint (extractor->tagcache,
- GST_TAG_TRACK_COUNT,
- &count);
-
- if (has_it) {
- tracker_sparql_builder_delete_open (preupdate, NULL);
- tracker_sparql_builder_subject_iri (preupdate, 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, 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_insert_open (preupdate, NULL);
+ if (graph) {
+ tracker_sparql_builder_graph_open (preupdate, graph);
+ }
- tracker_sparql_builder_subject_iri (preupdate, album_uri);
- tracker_sparql_builder_predicate (preupdate, "nmm:albumTrackCount");
- tracker_sparql_builder_object_int64 (preupdate, count);
+ 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);
- }
+ if (graph) {
+ tracker_sparql_builder_graph_close (preupdate);
+ }
+ tracker_sparql_builder_insert_close (preupdate);
- has_it = gst_tag_list_get_uint (extractor->tagcache,
- GST_TAG_ALBUM_VOLUME_NUMBER,
- &count);
-
- album_disc_uri = tracker_sparql_escape_uri_printf ("urn:album-disc:%s:Disc%d",
- album_title_local,
- has_it ? count : 1);
-
- tracker_sparql_builder_delete_open (preupdate, NULL);
- tracker_sparql_builder_subject_iri (preupdate, 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, 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, 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, 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);
- }
+ 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);
- tracker_sparql_builder_subject_iri (preupdate, 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, album_uri);
+ *p_album_artist = album_artist;
+ *p_album_title = album_title;
- if (graph) {
- tracker_sparql_builder_graph_close (preupdate);
- }
- tracker_sparql_builder_insert_close (preupdate);
+ g_free (album_artist_temp);
+ g_free (track_artist_temp);
+}
- replace_double_gst_tag (preupdate, album_uri, "nmm:albumGain", extractor->tagcache, GST_TAG_ALBUM_GAIN, graph);
- replace_double_gst_tag (preupdate, album_uri, "nmm:albumPeakGain", extractor->tagcache, GST_TAG_ALBUM_PEAK, graph);
+static void
+extractor_apply_device_metadata (MetadataExtractor *extractor,
+ TrackerSparqlBuilder *preupdate,
+ TrackerSparqlBuilder *metadata,
+ const gchar *graph)
+{
+ gchar *equip_uri;
+ gchar *model = NULL, *manuf = NULL;
- *album_title = album_title_local;
- }
+ gst_tag_list_get_string (extractor->tagcache, GST_TAG_DEVICE_MODEL, &model);
+ gst_tag_list_get_string (extractor->tagcache, GST_TAG_DEVICE_MANUFACTURER, &manuf);
- tracker_sparql_builder_predicate (metadata, "a");
+ if (model == NULL && manuf == NULL)
+ return;
- if (extractor->mime == EXTRACT_MIME_AUDIO) {
- tracker_sparql_builder_object (metadata, "nmm:MusicPiece");
- tracker_sparql_builder_object (metadata, "nfo:Audio");
- } else if (extractor->mime == EXTRACT_MIME_VIDEO) {
- tracker_sparql_builder_object (metadata, "nmm:Video");
- } else {
- tracker_sparql_builder_object (metadata, "nfo:Image");
+ equip_uri = tracker_sparql_escape_uri_printf ("urn:equipment:%s:%s:",
+ manuf ? manuf : "",
+ model ? model : "");
- if (extractor->mime != EXTRACT_MIME_SVG) {
- tracker_sparql_builder_object (metadata, "nmm:Photo");
- } else {
- tracker_sparql_builder_object (metadata, "nfo:VectorImage");
- }
- }
+ tracker_sparql_builder_insert_open (preupdate, NULL);
+ if (graph) {
+ tracker_sparql_builder_graph_open (preupdate, graph);
+ }
- gst_tag_list_get_string (extractor->tagcache, GST_TAG_GENRE, &genre);
- if (genre && g_strcmp0 (genre, "Unknown") != 0) {
- tracker_sparql_builder_predicate (metadata, "nfo:genre");
- tracker_sparql_builder_object_unvalidated (metadata, genre);
- }
- g_free (genre);
-
- s = NULL;
- gst_tag_list_get_string (extractor->tagcache, GST_TAG_TITLE, &s);
- tracker_guarantee_title_from_file (metadata,
- "nie:title",
- s,
- file_url);
- g_free (s);
+ tracker_sparql_builder_subject_iri (preupdate, equip_uri);
+ tracker_sparql_builder_predicate (preupdate, "a");
+ tracker_sparql_builder_object (preupdate, "nfo:Equipment");
- add_string_gst_tag (metadata, "nie:copyright", extractor->tagcache, GST_TAG_COPYRIGHT);
- add_string_gst_tag (metadata, "nie:license", extractor->tagcache, GST_TAG_LICENSE);
- add_string_gst_tag (metadata, "dc:coverage", extractor->tagcache, GST_TAG_LOCATION);
- add_string_gst_tag (metadata, "nie:comment", extractor->tagcache, GST_TAG_COMMENT);
+ if (manuf) {
+ tracker_sparql_builder_predicate (preupdate, "nfo:manufacturer");
+ tracker_sparql_builder_object_unvalidated (preupdate, manuf);
+ }
+ if (model) {
+ tracker_sparql_builder_predicate (preupdate, "nfo:model");
+ tracker_sparql_builder_object_unvalidated (preupdate, model);
+ }
- add_date_time_gst_tag_with_mtime_fallback (metadata,
- file_url,
- "nie:contentCreated",
- extractor->tagcache,
- GST_TAG_DATE_TIME,
- GST_TAG_DATE);
+ if (graph) {
+ tracker_sparql_builder_graph_close (preupdate);
+ }
+ tracker_sparql_builder_insert_close (preupdate);
- gst_tag_list_get_string (extractor->tagcache, GST_TAG_DEVICE_MODEL, &model);
- gst_tag_list_get_string (extractor->tagcache, GST_TAG_DEVICE_MANUFACTURER, &manuf);
+ tracker_sparql_builder_predicate (metadata, "nfo:equipment");
+ tracker_sparql_builder_object_iri (metadata, equip_uri);
+ g_free (equip_uri);
- if (model || manuf) {
- gchar *equip_uri;
+ g_free (model);
+ g_free (manuf);
+}
- equip_uri = tracker_sparql_escape_uri_printf ("urn:equipment:%s:%s:",
- manuf ? manuf : "",
- model ? model : "");
+static void
+extractor_apply_audio_metadata (MetadataExtractor *extractor,
+ TrackerSparqlBuilder *metadata,
+ const gchar *performer_uri,
+ const gchar *composer_uri,
+ const gchar *album_uri,
+ const gchar *album_disc_uri)
+{
+ add_uint_gst_tag (metadata, "nmm:trackNumber", extractor->tagcache, GST_TAG_TRACK_NUMBER);
+ add_string_gst_tag (metadata, "nfo:codec", extractor->tagcache, GST_TAG_AUDIO_CODEC);
+ add_double_gst_tag (metadata, "nfo:gain", extractor->tagcache, GST_TAG_TRACK_GAIN);
+ add_double_gst_tag (metadata, "nfo:peakGain", extractor->tagcache, GST_TAG_TRACK_PEAK);
+
+ if (performer_uri) {
+ tracker_sparql_builder_predicate (metadata, "nmm:performer");
+ tracker_sparql_builder_object_iri (metadata, performer_uri);
+ }
- tracker_sparql_builder_insert_open (preupdate, NULL);
- if (graph) {
- tracker_sparql_builder_graph_open (preupdate, graph);
- }
+ if (composer_uri) {
+ tracker_sparql_builder_predicate (metadata, "nmm:composer");
+ tracker_sparql_builder_object_iri (metadata, composer_uri);
+ }
- tracker_sparql_builder_subject_iri (preupdate, equip_uri);
- tracker_sparql_builder_predicate (preupdate, "a");
- tracker_sparql_builder_object (preupdate, "nfo:Equipment");
+ if (album_uri) {
+ tracker_sparql_builder_predicate (metadata, "nmm:musicAlbum");
+ tracker_sparql_builder_object_iri (metadata, album_uri);
+ }
- if (manuf) {
- tracker_sparql_builder_predicate (preupdate, "nfo:manufacturer");
- tracker_sparql_builder_object_unvalidated (preupdate, manuf);
- }
- if (model) {
- tracker_sparql_builder_predicate (preupdate, "nfo:model");
- tracker_sparql_builder_object_unvalidated (preupdate, model);
- }
+ if (album_disc_uri) {
+ tracker_sparql_builder_predicate (metadata, "nmm:musicAlbumDisc");
+ tracker_sparql_builder_object_iri (metadata, album_disc_uri);
+ }
+}
- if (graph) {
- tracker_sparql_builder_graph_close (preupdate);
- }
- tracker_sparql_builder_insert_close (preupdate);
+static void
+extractor_apply_video_metadata (MetadataExtractor *extractor,
+ TrackerSparqlBuilder *metadata,
+ const gchar *performer_uri,
+ const gchar *composer_uri)
+{
+ add_string_gst_tag (metadata, "dc:source", extractor->tagcache, GST_TAG_CLASSIFICATION);
- tracker_sparql_builder_predicate (metadata, "nfo:equipment");
- tracker_sparql_builder_object_iri (metadata, equip_uri);
- g_free (equip_uri);
- }
+ if (performer_uri) {
+ tracker_sparql_builder_predicate (metadata, "nmm:leadActor");
+ tracker_sparql_builder_object_iri (metadata, performer_uri);
+ }
- g_free (model);
- g_free (manuf);
+ if (composer_uri) {
+ tracker_sparql_builder_predicate (metadata, "nmm:director");
+ tracker_sparql_builder_object_iri (metadata, composer_uri);
+ }
- if (extractor->mime == EXTRACT_MIME_VIDEO) {
- add_string_gst_tag (metadata, "dc:source", extractor->tagcache, GST_TAG_CLASSIFICATION);
+ add_keywords_gst_tag (metadata, extractor->tagcache);
+}
- if (performer_uri) {
- tracker_sparql_builder_predicate (metadata, "nmm:leadActor");
- tracker_sparql_builder_object_iri (metadata, performer_uri);
- }
+static void
+extract_metadata (MetadataExtractor *extractor,
+ const gchar *file_url,
+ TrackerSparqlBuilder *preupdate,
+ TrackerSparqlBuilder *metadata,
+ gchar **album_artist,
+ gchar **album_title,
+ const gchar *graph)
+{
+ g_return_if_fail (extractor != NULL);
+ g_return_if_fail (metadata != NULL);
- if (composer_uri) {
- tracker_sparql_builder_predicate (metadata, "nmm:director");
- tracker_sparql_builder_object_iri (metadata, composer_uri);
- }
+ if (!gst_tag_list_is_empty (extractor->tagcache)) {
+ gchar *performer_uri = NULL;
+ gchar *composer_uri = NULL;
+ gchar *album_artist_uri = NULL;
+ gchar *album_uri = NULL;
+ gchar *album_disc_uri = NULL;
- add_keywords_gst_tag (metadata, extractor->tagcache);
- }
+ if (extractor->mime == EXTRACT_MIME_GUESS)
+ extractor_guess_content_type (extractor);
- if (extractor->mime == EXTRACT_MIME_AUDIO) {
- add_uint_gst_tag (metadata, "nmm:trackNumber", extractor->tagcache, GST_TAG_TRACK_NUMBER);
+ tracker_sparql_builder_predicate (metadata, "a");
- add_double_gst_tag (metadata, "nfo:gain", extractor->tagcache, GST_TAG_TRACK_GAIN);
- add_double_gst_tag (metadata, "nfo:peakGain", extractor->tagcache, GST_TAG_TRACK_PEAK);
+ if (extractor->mime == EXTRACT_MIME_AUDIO) {
+ tracker_sparql_builder_object (metadata, "nmm:MusicPiece");
+ tracker_sparql_builder_object (metadata, "nfo:Audio");
+ } else if (extractor->mime == EXTRACT_MIME_VIDEO) {
+ tracker_sparql_builder_object (metadata, "nmm:Video");
+ } else {
+ tracker_sparql_builder_object (metadata, "nfo:Image");
- if (performer_uri) {
- tracker_sparql_builder_predicate (metadata, "nmm:performer");
- tracker_sparql_builder_object_iri (metadata, performer_uri);
+ if (extractor->mime != EXTRACT_MIME_SVG) {
+ tracker_sparql_builder_object (metadata, "nmm:Photo");
+ } else {
+ tracker_sparql_builder_object (metadata, "nfo:VectorImage");
}
+ }
- if (composer_uri) {
- tracker_sparql_builder_predicate (metadata, "nmm:composer");
- tracker_sparql_builder_object_iri (metadata, composer_uri);
- }
+ extractor_apply_general_metadata (extractor,
+ file_url,
+ preupdate,
+ metadata,
+ graph,
+ &performer_uri,
+ &composer_uri);
- if (album_uri) {
- tracker_sparql_builder_predicate (metadata, "nmm:musicAlbum");
- tracker_sparql_builder_object_iri (metadata, album_uri);
- }
+ extractor_apply_device_metadata (extractor, preupdate, metadata, graph);
- if (album_disc_uri) {
- tracker_sparql_builder_predicate (metadata, "nmm:musicAlbumDisc");
- tracker_sparql_builder_object_iri (metadata, album_disc_uri);
- }
+ if (extractor->mime == EXTRACT_MIME_VIDEO)
+ extractor_apply_video_metadata (extractor,
+ metadata,
+ performer_uri,
+ composer_uri);
+
+ if (extractor->mime == EXTRACT_MIME_AUDIO) {
+ extractor_apply_album_metadata (extractor,
+ preupdate,
+ graph,
+ &album_artist_uri,
+ &album_uri,
+ &album_disc_uri,
+ album_artist,
+ album_title);
+
+ extractor_apply_audio_metadata (extractor,
+ metadata,
+ performer_uri,
+ composer_uri,
+ album_uri,
+ album_disc_uri);
}
g_free (performer_uri);
@@ -784,8 +852,6 @@ extract_metadata (MetadataExtractor *extractor,
g_free (album_uri);
g_free (album_disc_uri);
g_free (album_artist_uri);
-
- add_string_gst_tag (metadata, "nfo:codec", extractor->tagcache, GST_TAG_AUDIO_CODEC);
} else if (extractor->mime == EXTRACT_MIME_GUESS) {
g_warning ("Cannot guess real stream type if no tags were read! "
"Defaulting to Video.");
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]