[tracker-miners: 1/3] tracker-extract-gstreamer: Extract MusicBrainz IDs
- From: Sam Thursfield <sthursfield src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker-miners: 1/3] tracker-extract-gstreamer: Extract MusicBrainz IDs
- Date: Tue, 19 May 2020 20:55:59 +0000 (UTC)
commit ee8a95629c90e86cb3cf95b8379de42b9aaea339
Author: Sumaid Syed <sumaidsyed gmail com>
Date: Fri May 17 12:37:24 2019 +0530
tracker-extract-gstreamer: Extract MusicBrainz IDs
Extraction of MusicBrainz IDs is done based on the tags defined by
Gstreamer.
Some tags are already part of the stable GStreamer releases:
- recording id (GST_TAG_MUSICBRAINZ_TRACKID)
- release id (GST_TAG_MUSICBRAINZ_ALBUMID)
- artist id (GST_TAG_MUSICBRAINZ_ARTISTID)
Some tags are not part of a GStreamer release yet (they will be
introduced in the 1.18.0 version):
- track id (GST_TAG_MUSICBRAINZ_RELEASETRACKID)
- fingerprint id (GST_TAG_ACOUSTID_FINGERPRINT)
- release-group id (GST_TAG_MUSICBRAINZ_RELEASEGROUPID)
See:
https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/-/merge_requests/252
In the later case, the defined operator is used to check if the tag is
supported.
The flac extraction functional test is updated to handle recording id,
release id and artist id.
Closes: https://gitlab.gnome.org/GNOME/tracker-miners/issues/66
src/tracker-extract/tracker-extract-gstreamer.c | 90 ++++++++++++++++++++++
.../test-extraction-data/audio/flac.expected.json | 28 ++++++-
2 files changed, 116 insertions(+), 2 deletions(-)
---
diff --git a/src/tracker-extract/tracker-extract-gstreamer.c b/src/tracker-extract/tracker-extract-gstreamer.c
index 2f193c041..826e5d135 100644
--- a/src/tracker-extract/tracker-extract-gstreamer.c
+++ b/src/tracker-extract/tracker-extract-gstreamer.c
@@ -530,6 +530,11 @@ extractor_maybe_get_album_disc (MetadataExtractor *extractor,
gboolean has_it, has_date;
guint volume_number;
gchar album_datetime[26];
+ gchar *mb_release_id = NULL;
+
+ #if defined GST_TAG_MUSICBRAINZ_RELEASEGROUPID
+ gchar *mb_release_group_id = NULL;
+ #endif
gst_tag_list_get_string (tag_list, GST_TAG_ALBUM, &album_title);
@@ -555,6 +560,30 @@ extractor_maybe_get_album_disc (MetadataExtractor *extractor,
set_property_from_gst_tag (album, "nmm:albumGain", extractor->tagcache, GST_TAG_ALBUM_GAIN);
set_property_from_gst_tag (album, "nmm:albumPeakGain", extractor->tagcache, GST_TAG_ALBUM_PEAK);
+ gst_tag_list_get_string (tag_list, GST_TAG_MUSICBRAINZ_ALBUMID, &mb_release_id);
+ if (mb_release_id) {
+ g_autofree char *mb_release_uri = g_strdup_printf("https://musicbrainz.org/release/%s",
mb_release_id);
+ TrackerResource *mb_release =
tracker_extract_new_external_reference("https://musicbrainz.org/doc/Release",
+ mb_release_id,
+ mb_release_uri);
+
+ tracker_resource_add_take_relation (album, "tracker:hasExternalReference", mb_release);
+ g_free (mb_release_id);
+ }
+
+ #if defined GST_TAG_MUSICBRAINZ_RELEASEGROUPID
+ gst_tag_list_get_string (tag_list, GST_TAG_MUSICBRAINZ_RELEASEGROUPID, &mb_release_group_id);
+ if (mb_release_group_id) {
+ g_autofree char *mb_release_group_uri =
g_strdup_printf("https://musicbrainz.org/release-group/%s", mb_release_group_id);
+ TrackerResource *mb_release_group =
tracker_extract_new_external_reference("https://musicbrainz.org/doc/Release_Group",
+
mb_release_group_id,
+
mb_release_group_uri);
+
+ tracker_resource_add_take_relation (album, "tracker:hasExternalReference",
mb_release_group);
+ g_free (mb_release_group_id);
+ }
+ #endif
+
g_free (album_artist_name);
g_free (track_artist_temp);
g_free (album_title);
@@ -591,13 +620,74 @@ extractor_apply_audio_metadata (MetadataExtractor *extractor,
TrackerResource *composer,
TrackerResource *album_disc)
{
+ gchar *mb_recording_id = NULL;
+
+ #if defined GST_TAG_MUSICBRAINZ_RELEASETRACKID
+ gchar *mb_track_id = NULL;
+ #endif
+
+ #if defined GST_TAG_ACOUSTID_FINGERPRINT
+ GValue acoustid_fingerprint = G_VALUE_INIT;
+ #endif
+
set_property_from_gst_tag (audio, "nmm:trackNumber", tag_list, GST_TAG_TRACK_NUMBER);
set_property_from_gst_tag (audio, "nfo:codec", tag_list, GST_TAG_AUDIO_CODEC);
set_property_from_gst_tag (audio, "nfo:gain", tag_list, GST_TAG_TRACK_GAIN);
set_property_from_gst_tag (audio, "nfo:peakGain", tag_list, GST_TAG_TRACK_PEAK);
+ gst_tag_list_get_string (tag_list, GST_TAG_MUSICBRAINZ_TRACKID, &mb_recording_id);
+ if (mb_recording_id) {
+ g_autofree char *mb_recording_uri = g_strdup_printf("https://musicbrainz.org/recording/%s",
mb_recording_id);
+ TrackerResource *mb_recording =
tracker_extract_new_external_reference("https://musicbrainz.org/doc/Recording",
+ mb_recording_id,
+ mb_recording_uri);
+
+ tracker_resource_add_take_relation (audio, "tracker:hasExternalReference", mb_recording);
+ g_free (mb_recording_id);
+ }
+
+ #if defined GST_TAG_MUSICBRAINZ_RELEASETRACKID
+ gst_tag_list_get_string (tag_list, GST_TAG_MUSICBRAINZ_RELEASETRACKID, &mb_track_id);
+ if (mb_track_id) {
+ g_autofree char *mb_track_uri = g_strdup_printf("https://musicbrainz.org/track/%s",
mb_track_id);
+ TrackerResource *mb_track =
tracker_extract_new_external_reference("https://musicbrainz.org/doc/Track",
+ mb_track_id,
+ mb_track_uri);
+
+ tracker_resource_add_take_relation (audio, "tracker:hasExternalReference", mb_track);
+ g_free (mb_track_id);
+ }
+ #endif
+
+ #if defined GST_TAG_ACOUSTID_FINGERPRINT
+ gst_tag_list_copy_value (&acoustid_fingerprint, tag_list, GST_TAG_ACOUSTID_FINGERPRINT);
+ if (acoustid_fingerprint) {
+ TrackerResource *hash_resource = tracker_resource_new (NULL);
+
+ tracker_resource_set_uri (hash_resource, "rdf:type", "nfo:FileHash");
+ tracker_resource_set_string (hash_resource, "nfo:hashValue", acoustid_fingerprint);
+ tracker_resource_set_string (hash_resource, "nfo:hashAlgorithm", "chromaprint");
+
+ tracker_resource_add_take_relation (audio, "nfo:hasHash", hash_resource);
+ g_free (acoustid_fingerprint);
+ }
+ #endif
+
if (performer) {
+ gchar *mb_artist_id = NULL;
+
tracker_resource_set_relation (audio, "nmm:performer", performer);
+
+ gst_tag_list_get_string (tag_list, GST_TAG_MUSICBRAINZ_ARTISTID, &mb_artist_id);
+ if (mb_artist_id) {
+ g_autofree char *mb_artist_uri = g_strdup_printf("https://musicbrainz.org/artist/%s",
mb_artist_id);
+ TrackerResource *mb_artist =
tracker_extract_new_external_reference("https://musicbrainz.org/doc/Artist",
+ mb_artist_id,
+ mb_artist_uri);
+
+ tracker_resource_add_take_relation (performer, "tracker:hasExternalReference",
mb_artist);
+ g_free (mb_artist_id);
+ }
}
if (composer) {
diff --git a/tests/functional-tests/test-extraction-data/audio/flac.expected.json
b/tests/functional-tests/test-extraction-data/audio/flac.expected.json
index bce2420e7..04c123da8 100644
--- a/tests/functional-tests/test-extraction-data/audio/flac.expected.json
+++ b/tests/functional-tests/test-extraction-data/audio/flac.expected.json
@@ -25,6 +25,14 @@
"@type": "nmm:Artist",
"nmm:artistName": "my album artist"
}
+ ],
+ "tracker:hasExternalReference": [
+ {
+ "@id": "https://musicbrainz.org/release/524387feg",
+ "@type": "tracker:ExternalReference",
+ "tracker:referenceSource": "https://musicbrainz.org/doc/Release",
+ "tracker:referenceIdentifier": "524387feg"
+ }
]
},
"nmm:musicAlbumDisc": {
@@ -33,7 +41,23 @@
},
"nmm:performer": {
"@type": "nmm:Artist",
- "nmm:artistName": "my artist"
- }
+ "nmm:artistName": "my artist",
+ "tracker:hasExternalReference": [
+ {
+ "@id": "https://musicbrainz.org/artist/789-feg-7854",
+ "@type": "tracker:ExternalReference",
+ "tracker:referenceSource": "https://musicbrainz.org/doc/Artist",
+ "tracker:referenceIdentifier": "789-feg-7854"
+ }
+ ]
+ },
+ "tracker:hasExternalReference": [
+ {
+ "@id": "https://musicbrainz.org/recording/4-8-15-16-23-42-lost",
+ "@type": "tracker:ExternalReference",
+ "tracker:referenceSource": "https://musicbrainz.org/doc/Recording",
+ "tracker:referenceIdentifier": "4-8-15-16-23-42-lost"
+ }
+ ]
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]