[tracker/miner-web-review: 49/74] tracker-extract: Fixed various properties for albums in FLAC and Vorbis
- From: Adrien Bustany <abustany src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/miner-web-review: 49/74] tracker-extract: Fixed various properties for albums in FLAC and Vorbis
- Date: Mon, 1 Mar 2010 15:36:20 +0000 (UTC)
commit 844abc0fa0298d5b9cfa666f765b5bacbb47eed2
Author: Philip Van Hoof <philip codeminded be>
Date: Thu Feb 25 16:44:14 2010 +0100
tracker-extract: Fixed various properties for albums in FLAC and Vorbis
src/tracker-extract/tracker-extract-flac.c | 164 ++++++++++++++++-------
src/tracker-extract/tracker-extract-gstreamer.c | 56 ++++++++-
src/tracker-extract/tracker-extract-vorbis.c | 100 ++++++++++----
3 files changed, 242 insertions(+), 78 deletions(-)
---
diff --git a/src/tracker-extract/tracker-extract-flac.c b/src/tracker-extract/tracker-extract-flac.c
index 973eff3..21b8dd8 100644
--- a/src/tracker-extract/tracker-extract-flac.c
+++ b/src/tracker-extract/tracker-extract-flac.c
@@ -22,6 +22,7 @@
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
+#include <stdlib.h>
#include <glib.h>
@@ -216,40 +217,103 @@ extract_flac (const gchar *uri,
FLAC__metadata_simple_iterator_next (iter);
}
- /* This will find the first non-NULL and then free the rest */
creator = tracker_coalesce (3, fd.artist, fd.albumartist,
fd.performer);
if (creator) {
- artist_uri = tracker_uri_printf_escaped ("urn:artist:%s",
- creator);
- tracker_sparql_builder_subject_iri (metadata, artist_uri);
- tracker_sparql_builder_predicate (metadata, "a");
- tracker_sparql_builder_object (metadata, "nmm:Artist");
- tracker_sparql_builder_predicate (metadata, "nmm:artistName");
- tracker_sparql_builder_object_unvalidated (metadata, creator);
- g_free (creator);
+ artist_uri = tracker_uri_printf_escaped ("urn:artist:%s", creator);
+
+ tracker_sparql_builder_insert_open (preupdate, NULL);
+ tracker_sparql_builder_subject_iri (preupdate, 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, creator);
+ tracker_sparql_builder_insert_close (preupdate);
+
+ g_free (creator);
}
if (fd.album) {
- album_uri = tracker_uri_printf_escaped ("urn:album:%s",
- fd.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,
- fd.album);
-
- if (fd.trackcount) {
- tracker_sparql_builder_predicate (metadata, "nmm:albumTrackCount");
- tracker_sparql_builder_object_unvalidated (metadata,
- fd.trackcount);
- }
+ album_uri = tracker_uri_printf_escaped ("urn:album:%s", fd.album);
+
+ tracker_sparql_builder_insert_open (preupdate, NULL);
+
+ tracker_sparql_builder_subject_iri (preupdate, album_uri);
+ tracker_sparql_builder_predicate (preupdate, "a");
+ tracker_sparql_builder_object (preupdate, "nmm:MusicAlbum");
+ tracker_sparql_builder_predicate (preupdate, "nmm:albumTitle");
+ tracker_sparql_builder_object_unvalidated (preupdate, fd.album);
+
+ if (fd.trackcount) {
+ 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);
+
+ tracker_sparql_builder_subject_iri (preupdate, album_uri);
+ tracker_sparql_builder_predicate (preupdate, "nmm:albumTrackCount");
+ tracker_sparql_builder_object_unvalidated (preupdate, fd.trackcount);
+
+ tracker_sparql_builder_insert_close (preupdate);
+ }
+
+ if (fd.albumgain) {
+ tracker_sparql_builder_delete_open (preupdate, NULL);
+ tracker_sparql_builder_subject_iri (preupdate, album_uri);
+ tracker_sparql_builder_predicate (preupdate, "nmm:albumGain");
+ 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:albumGain");
+ tracker_sparql_builder_object_variable (preupdate, "unknown");
+ tracker_sparql_builder_where_close (preupdate);
+
+ tracker_sparql_builder_insert_open (preupdate, NULL);
+
+ tracker_sparql_builder_subject_iri (preupdate, album_uri);
+ tracker_sparql_builder_predicate (preupdate, "nmm:albumGain");
+ tracker_sparql_builder_object_double (preupdate, atof (fd.albumgain));
+
+ tracker_sparql_builder_insert_close (preupdate);
+ }
+
+ if (fd.albumpeakgain) {
+ tracker_sparql_builder_delete_open (preupdate, NULL);
+ tracker_sparql_builder_subject_iri (preupdate, album_uri);
+ tracker_sparql_builder_predicate (preupdate, "nmm:albumPeakGain");
+ 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:albumPeakGain");
+ tracker_sparql_builder_object_variable (preupdate, "unknown");
+ tracker_sparql_builder_where_close (preupdate);
+
+ tracker_sparql_builder_insert_open (preupdate, NULL);
+
+ tracker_sparql_builder_subject_iri (preupdate, album_uri);
+ tracker_sparql_builder_predicate (preupdate, "nmm:albumPeakGain");
+ tracker_sparql_builder_object_double (preupdate, atof (fd.albumpeakgain));
+
+ tracker_sparql_builder_insert_close (preupdate);
+ }
+ tracker_sparql_builder_insert_close (preupdate);
}
- tracker_sparql_builder_subject_iri (metadata, uri);
tracker_sparql_builder_predicate (metadata, "a");
tracker_sparql_builder_object (metadata, "nmm:MusicPiece");
tracker_sparql_builder_object (metadata, "nfo:Audio");
@@ -268,8 +332,6 @@ extract_flac (const gchar *uri,
/* FIXME: Trackgain/Trackpeakgain: commented out in vorbis */
- add_tuple (metadata, "nmm:albumGain", fd.albumgain);
- add_tuple (metadata, "nmm:albumPeakGain", fd.albumpeakgain);
add_tuple (metadata, "nie:comment", fd.comment);
add_tuple (metadata, "nie:contentCreated", fd.date);
add_tuple (metadata, "nfo:genre", fd.genre);
@@ -278,36 +340,36 @@ extract_flac (const gchar *uri,
add_tuple (metadata, "nie:license", fd.license);
if (fd.publisher) {
- tracker_sparql_builder_predicate (metadata, "dc:publisher");
+ tracker_sparql_builder_predicate (metadata, "dc:publisher");
- tracker_sparql_builder_object_blank_open (metadata);
- tracker_sparql_builder_predicate (metadata, "a");
- tracker_sparql_builder_object (metadata, "nco:Contact");
+ tracker_sparql_builder_object_blank_open (metadata);
+ tracker_sparql_builder_predicate (metadata, "a");
+ tracker_sparql_builder_object (metadata, "nco:Contact");
- tracker_sparql_builder_predicate (metadata, "nco:fullname");
- tracker_sparql_builder_object_unvalidated (metadata,
- fd.publisher);
- tracker_sparql_builder_object_blank_close (metadata);
+ tracker_sparql_builder_predicate (metadata, "nco:fullname");
+ tracker_sparql_builder_object_unvalidated (metadata,
+ fd.publisher);
+ tracker_sparql_builder_object_blank_close (metadata);
}
if (stream) {
- tracker_sparql_builder_predicate (metadata, "nfo:sampleRate");
- tracker_sparql_builder_object_int64 (metadata,
- stream->data.stream_info.sample_rate);
-
- tracker_sparql_builder_predicate (metadata, "nfo:channels");
- tracker_sparql_builder_object_int64 (metadata,
- stream->data.stream_info.channels);
-
- tracker_sparql_builder_predicate (metadata,
- "nfo:averageBitrate");
- tracker_sparql_builder_object_int64 (metadata,
- stream->data.stream_info.bits_per_sample);
-
- tracker_sparql_builder_predicate (metadata, "nfo:duration");
- tracker_sparql_builder_object_int64 (metadata,
- stream->data.stream_info.total_samples /
- stream->data.stream_info.sample_rate);
+ tracker_sparql_builder_predicate (metadata, "nfo:sampleRate");
+ tracker_sparql_builder_object_int64 (metadata,
+ stream->data.stream_info.sample_rate);
+
+ tracker_sparql_builder_predicate (metadata, "nfo:channels");
+ tracker_sparql_builder_object_int64 (metadata,
+ stream->data.stream_info.channels);
+
+ tracker_sparql_builder_predicate (metadata,
+ "nfo:averageBitrate");
+ tracker_sparql_builder_object_int64 (metadata,
+ stream->data.stream_info.bits_per_sample);
+
+ tracker_sparql_builder_predicate (metadata, "nfo:duration");
+ tracker_sparql_builder_object_int64 (metadata,
+ stream->data.stream_info.total_samples /
+ stream->data.stream_info.sample_rate);
}
g_free (fd.title);
diff --git a/src/tracker-extract/tracker-extract-gstreamer.c b/src/tracker-extract/tracker-extract-gstreamer.c
index 69aa169..e9c25dc 100644
--- a/src/tracker-extract/tracker-extract-gstreamer.c
+++ b/src/tracker-extract/tracker-extract-gstreamer.c
@@ -541,6 +541,7 @@ extract_metadata (MetadataExtractor *extractor,
if (s) {
gboolean has_it;
guint count;
+ gdouble gain;
needs_audio = TRUE;
@@ -608,7 +609,60 @@ extract_metadata (MetadataExtractor *extractor,
tracker_sparql_builder_insert_close (preupdate);
}
+ has_it = gst_tag_list_get_double (extractor->tagcache,
+ GST_TAG_ALBUM_GAIN,
+ &gain);
+
+ if (has_it) {
+ tracker_sparql_builder_delete_open (preupdate, NULL);
+ tracker_sparql_builder_subject_iri (preupdate, album_uri);
+ tracker_sparql_builder_predicate (preupdate, "nmm:albumGain");
+ 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:albumGain");
+ tracker_sparql_builder_object_variable (preupdate, "unknown");
+ tracker_sparql_builder_where_close (preupdate);
+
+ tracker_sparql_builder_insert_open (preupdate, NULL);
+
+ tracker_sparql_builder_subject_iri (preupdate, album_uri);
+ tracker_sparql_builder_predicate (preupdate, "nmm:albumGain");
+ tracker_sparql_builder_object_double (preupdate, gain);
+
+ tracker_sparql_builder_insert_close (preupdate);
+ }
+
+ has_it = gst_tag_list_get_double (extractor->tagcache,
+ GST_TAG_ALBUM_PEAK,
+ &gain);
+
+ if (has_it) {
+ tracker_sparql_builder_delete_open (preupdate, NULL);
+ tracker_sparql_builder_subject_iri (preupdate, album_uri);
+ tracker_sparql_builder_predicate (preupdate, "nmm:albumPeakGain");
+ 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:albumPeakGain");
+ tracker_sparql_builder_object_variable (preupdate, "unknown");
+ tracker_sparql_builder_where_close (preupdate);
+
+ tracker_sparql_builder_insert_open (preupdate, NULL);
+
+ tracker_sparql_builder_subject_iri (preupdate, album_uri);
+ tracker_sparql_builder_predicate (preupdate, "nmm:albumPeakGain");
+ tracker_sparql_builder_object_double (preupdate, gain);
+
+ tracker_sparql_builder_insert_close (preupdate);
+ }
+
*album = s;
+
}
if (extractor->mime == EXTRACT_MIME_AUDIO)
@@ -672,8 +726,6 @@ extract_metadata (MetadataExtractor *extractor,
add_double_gst_tag (metadata, uri, "nfo:gain", extractor->tagcache, GST_TAG_TRACK_GAIN);
add_double_gst_tag (metadata, uri, "nfo:peakGain", extractor->tagcache, GST_TAG_TRACK_PEAK);
- add_double_gst_tag (metadata, uri, "nmm:albumGain", extractor->tagcache, GST_TAG_ALBUM_GAIN);
- add_double_gst_tag (metadata, uri, "nmm:albumPeakGain", extractor->tagcache, GST_TAG_ALBUM_PEAK);
if (performer_uri) {
tracker_sparql_builder_predicate (metadata, "nmm:performer");
diff --git a/src/tracker-extract/tracker-extract-vorbis.c b/src/tracker-extract/tracker-extract-vorbis.c
index 7fbe1c5..5815ca1 100644
--- a/src/tracker-extract/tracker-extract-vorbis.c
+++ b/src/tracker-extract/tracker-extract-vorbis.c
@@ -22,6 +22,7 @@
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
+#include <stdlib.h>
#include <glib.h>
@@ -96,7 +97,7 @@ extract_vorbis (const char *uri,
gchar *filename;
VorbisData vorbis_data = { 0 };
VorbisNeedsMergeData merge_data = { 0 };
- gchar *artist_uri = NULL, *album_uri = NULL;
+ gchar *artist_uri = NULL, *album_uri = NULL, *publisher_uri = NULL;
filename = g_filename_from_uri (uri, NULL, NULL);
f = tracker_file_open (filename, "r", FALSE);
@@ -187,6 +188,7 @@ extract_vorbis (const char *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");
@@ -196,17 +198,86 @@ extract_vorbis (const char *uri,
tracker_sparql_builder_insert_open (preupdate, NULL);
tracker_sparql_builder_subject_iri (preupdate, album_uri);
- tracker_sparql_builder_predicate (metadata, "nmm:albumTrackCount");
- tracker_sparql_builder_object_unvalidated (metadata, vorbis_data.trackcount);
+ tracker_sparql_builder_predicate (preupdate, "nmm:albumTrackCount");
+ tracker_sparql_builder_object_unvalidated (preupdate, vorbis_data.trackcount);
tracker_sparql_builder_insert_close (preupdate);
+ }
+
+ if (vorbis_data.AlbumGain) {
+ tracker_sparql_builder_delete_open (preupdate, NULL);
+ tracker_sparql_builder_subject_iri (preupdate, album_uri);
+ tracker_sparql_builder_predicate (preupdate, "nmm:albumGain");
+ 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:albumGain");
+ tracker_sparql_builder_object_variable (preupdate, "unknown");
+ tracker_sparql_builder_where_close (preupdate);
+
+ tracker_sparql_builder_insert_open (preupdate, NULL);
- g_free (vorbis_data.trackcount);
+ tracker_sparql_builder_subject_iri (preupdate, album_uri);
+ tracker_sparql_builder_predicate (preupdate, "nmm:albumGain");
+ tracker_sparql_builder_object_double (preupdate, atof (vorbis_data.AlbumGain));
+
+ tracker_sparql_builder_insert_close (preupdate);
+ }
+
+ if (vorbis_data.AlbumPeakGain) {
+ tracker_sparql_builder_delete_open (preupdate, NULL);
+ tracker_sparql_builder_subject_iri (preupdate, album_uri);
+ tracker_sparql_builder_predicate (preupdate, "nmm:albumPeakGain");
+ 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:albumPeakGain");
+ tracker_sparql_builder_object_variable (preupdate, "unknown");
+ tracker_sparql_builder_where_close (preupdate);
+
+ tracker_sparql_builder_insert_open (preupdate, NULL);
+
+ tracker_sparql_builder_subject_iri (preupdate, album_uri);
+ tracker_sparql_builder_predicate (preupdate, "nmm:albumPeakGain");
+ tracker_sparql_builder_object_double (preupdate, atof (vorbis_data.AlbumPeakGain));
+
+ tracker_sparql_builder_insert_close (preupdate);
+ }
+
+ if (vorbis_data.DiscNo) {
+ tracker_sparql_builder_delete_open (preupdate, NULL);
+ tracker_sparql_builder_subject_iri (preupdate, album_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_uri);
+ tracker_sparql_builder_predicate (preupdate, "nmm:setNumber");
+ tracker_sparql_builder_object_variable (preupdate, "unknown");
+ tracker_sparql_builder_where_close (preupdate);
+
+ tracker_sparql_builder_insert_open (preupdate, NULL);
+
+ tracker_sparql_builder_subject_iri (preupdate, album_uri);
+ tracker_sparql_builder_predicate (preupdate, "nmm:setNumber");
+ tracker_sparql_builder_object_int64 (preupdate, atoi (vorbis_data.DiscNo));
+
+ tracker_sparql_builder_insert_close (preupdate);
}
g_free (vorbis_data.album);
}
+ g_free (vorbis_data.trackcount);
+ g_free (vorbis_data.AlbumPeakGain);
+ g_free (vorbis_data.AlbumGain);
+ g_free (vorbis_data.DiscNo);
+
tracker_sparql_builder_predicate (metadata, "a");
tracker_sparql_builder_object (metadata, "nmm:MusicPiece");
tracker_sparql_builder_object (metadata, "nfo:Audio");
@@ -229,15 +300,6 @@ extract_vorbis (const char *uri,
g_free (vorbis_data.tracknumber);
}
- if (vorbis_data.DiscNo) {
-#if 0
- /* nmm:setNumber is of domain nmm:MusicAlbum, but there could be several of these... */
- tracker_sparql_builder_predicate (metadata, "nmm:setNumber");
- tracker_sparql_builder_object_unvalidated (metadata, vorbis_data.DiscNo);
-#endif
- g_free (vorbis_data.DiscNo);
- }
-
if (vorbis_data.TrackGain) {
/* tracker_statement_list_insert (metadata, uri, _PREFIX "", vorbis_data.); */
g_free (vorbis_data.TrackGain);
@@ -247,18 +309,6 @@ extract_vorbis (const char *uri,
g_free (vorbis_data.TrackPeakGain);
}
- if (vorbis_data.AlbumGain) {
- tracker_sparql_builder_predicate (metadata, "nmm:albumGain");
- tracker_sparql_builder_object_unvalidated (metadata, vorbis_data.AlbumGain);
- g_free (vorbis_data.AlbumGain);
- }
-
- if (vorbis_data.AlbumPeakGain) {
- tracker_sparql_builder_predicate (metadata, "nmm:albumPeakGain");
- tracker_sparql_builder_object_unvalidated (metadata, vorbis_data.AlbumPeakGain);
- g_free (vorbis_data.AlbumPeakGain);
- }
-
if (vorbis_data.comment) {
tracker_sparql_builder_predicate (metadata, "nie:comment");
tracker_sparql_builder_object_unvalidated (metadata, vorbis_data.comment);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]