[tracker-miners/wip/jfelder/tracker-extract-musicbrainz-external-resources: 1/2] extract-mp3: Use ExtractReference to store musicbrainz tags
- From: Sam Thursfield <sthursfield src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker-miners/wip/jfelder/tracker-extract-musicbrainz-external-resources: 1/2] extract-mp3: Use ExtractReference to store musicbrainz tags
- Date: Tue, 6 Aug 2019 17:35:10 +0000 (UTC)
commit d6c9479f226c04beb58edf80ccd5e5407bceb030
Author: Jean Felder <jean felder estimages com>
Date: Mon Jul 15 17:40:30 2019 +0200
extract-mp3: Use ExtractReference to store musicbrainz tags
Store MusicBrainz IDs as ExternalResources instead of a list of
properties. This approach is more generic.
Extraction of MusicBrainz IDs is done based on tags used by Picard.
Tags Mapping: https://picard.musicbrainz.org/docs/mappings/
src/libtracker-extract/tracker-resource-helpers.c | 33 ++++++++++++++++++
src/libtracker-extract/tracker-resource-helpers.h | 1 +
src/tracker-extract/tracker-extract-mp3.c | 40 ++++++++++++++++++----
.../audio/audio-test-1.expected.json | 39 ++++++++++++++++++---
.../audio/audio-test-2.expected.json | 39 ++++++++++++++++++---
5 files changed, 136 insertions(+), 16 deletions(-)
---
diff --git a/src/libtracker-extract/tracker-resource-helpers.c
b/src/libtracker-extract/tracker-resource-helpers.c
index bc80a4942..53a287ecb 100644
--- a/src/libtracker-extract/tracker-resource-helpers.c
+++ b/src/libtracker-extract/tracker-resource-helpers.c
@@ -140,6 +140,39 @@ tracker_extract_new_equipment (const char *make,
return equipment;
}
+/**
+ * tracker_extract_new_external_reference:
+ * @source_uri: the source uri of the external reference
+ * @identifier: the identifier of the external reference
+ *
+ * Create a new tracker:ExternalReference resource and set its source and its
+ * identifier. Both @source and @identifer must be non-%NULL.
+ *
+ * Returns: a newly allocated #TrackerResource instance, of type tracker:ExternalReference
+ *
+ * Since: 2.3.0
+ */
+TrackerResource *
+tracker_extract_new_external_reference (const char *source_uri,
+ const char *identifier)
+{
+ TrackerResource *external_reference;
+ gchar *uri;
+
+ g_return_val_if_fail (source_uri != NULL && identifier != NULL, NULL);
+
+ uri = tracker_sparql_escape_uri_printf ("tracker:ExternalReference:%s", source_uri);
+
+ external_reference = tracker_resource_new (uri);
+ tracker_resource_set_uri (external_reference, "rdf:type", "tracker:ExternalReference");
+ tracker_resource_set_uri (external_reference, "tracker:referenceSource", source_uri);
+ tracker_resource_set_string (external_reference, "tracker:referenceIdentifier", identifier);
+
+ g_free(uri);
+
+ return external_reference;
+}
+
/**
* tracker_extract_new_location:
* @street_address: (allow none): main part of postal address, or %NULL
diff --git a/src/libtracker-extract/tracker-resource-helpers.h
b/src/libtracker-extract/tracker-resource-helpers.h
index dc5b0dc33..be067a516 100644
--- a/src/libtracker-extract/tracker-resource-helpers.h
+++ b/src/libtracker-extract/tracker-resource-helpers.h
@@ -32,6 +32,7 @@ G_BEGIN_DECLS
TrackerResource *tracker_extract_new_artist (const char *name);
TrackerResource *tracker_extract_new_contact (const char *fullname);
TrackerResource *tracker_extract_new_equipment (const char *make, const char *model);
+TrackerResource *tracker_extract_new_external_reference (const char *source_uri, const char *identifier);
TrackerResource *tracker_extract_new_location (const char *address, const char *state, const char *city,
const char *country, const char *gps_altitude, const char *gps_latitude, const char *gps_longitude);
TrackerResource *tracker_extract_new_music_album_disc (const char *album_title, TrackerResource
*album_artist, int disc_number, const char *date);
TrackerResource *tracker_extract_new_tag (const char *label);
diff --git a/src/tracker-extract/tracker-extract-mp3.c b/src/tracker-extract/tracker-extract-mp3.c
index 98a29e119..43878869f 100644
--- a/src/tracker-extract/tracker-extract-mp3.c
+++ b/src/tracker-extract/tracker-extract-mp3.c
@@ -2714,6 +2714,7 @@ tracker_extract_get_metadata (TrackerExtractInfo *info)
if (md.album_name) {
TrackerResource *album_disc = NULL, *album_artist = NULL;
+ TrackerResource *mb_release_id = NULL, *mb_release_group_id = NULL;
if (md.album_artist_name)
album_artist = tracker_extract_new_artist (md.album_artist_name);
@@ -2729,12 +2730,20 @@ tracker_extract_get_metadata (TrackerExtractInfo *info)
tracker_resource_set_relation (main_resource, "nmm:musicAlbumDisc", album_disc);
if (md.mb_release_id) {
- tracker_resource_set_string (md.album, "nmm:mbReleaseID", md.mb_release_id);
+ mb_release_id =
tracker_extract_new_external_reference("https://musicbrainz.org/doc/Release",
+ md.mb_release_id);
+
+ tracker_resource_set_relation (md.album, "tracker:hasExternalReference",
mb_release_id);
}
if (md.mb_release_group_id) {
- tracker_resource_set_string (md.album, "nmm:mbReleaseGroupID",
- md.mb_release_group_id);
+ mb_release_group_id =
tracker_extract_new_external_reference("https://musicbrainz.org/doc/Release_Group",
+ md.mb_release_group_id);
+
+ if (mb_release_id) {
+ tracker_resource_add_relation (md.album, "tracker:hasExternalReference",
mb_release_group_id);
+ } else
+ tracker_resource_set_relation (md.album, "tracker:hasExternalReference",
mb_release_group_id);
}
if (md.track_count > 0) {
@@ -2743,6 +2752,8 @@ tracker_extract_get_metadata (TrackerExtractInfo *info)
g_object_unref (album_disc);
g_clear_object (&album_artist);
+ g_object_unref (mb_release_id);
+ g_object_unref (mb_release_group_id);
}
tracker_resource_add_uri (main_resource, "rdf:type", "nmm:MusicPiece");
@@ -2762,7 +2773,11 @@ tracker_extract_get_metadata (TrackerExtractInfo *info)
if (md.performer) {
tracker_resource_set_relation (main_resource, "nmm:performer", md.performer);
if (md.mb_artist_id) {
- tracker_resource_set_string (md.performer, "nmm:mbArtistID", md.mb_artist_id);
+ TrackerResource *mb_artist_id =
tracker_extract_new_external_reference("https://musicbrainz.org/doc/Artist",
+
md.mb_artist_id);
+
+ tracker_resource_set_relation (md.performer, "tracker:hasExternalReference",
mb_artist_id);
+ g_object_unref (mb_artist_id);
}
}
@@ -2806,11 +2821,24 @@ tracker_extract_get_metadata (TrackerExtractInfo *info)
}
if (md.mb_recording_id) {
- tracker_resource_set_string (main_resource, "nmm:mbRecordingID", md.mb_recording_id);
+ TrackerResource *mb_recording_id =
tracker_extract_new_external_reference("https://musicbrainz.org/doc/Recording",
+ md.mb_recording_id);
+
+ tracker_resource_set_relation (main_resource, "tracker:hasExternalReference",
mb_recording_id);
+ g_object_unref (mb_recording_id);
}
if (md.mb_track_id) {
- tracker_resource_set_string (main_resource, "nmm:mbTrackID", md.mb_track_id);
+ TrackerResource *mb_track_id =
tracker_extract_new_external_reference("https://musicbrainz.org/doc/Track",
+ md.mb_track_id);
+
+ if (md.mb_recording_id) {
+ tracker_resource_add_relation (main_resource, "tracker:hasExternalReference",
mb_track_id);
+ } else {
+ tracker_resource_set_relation (main_resource, "tracker:hasExternalReference",
mb_track_id);
+ }
+
+ g_object_unref (mb_track_id);
}
if (md.acoustid_fingerprint) {
diff --git a/tests/functional-tests/test-extraction-data/audio/audio-test-1.expected.json
b/tests/functional-tests/test-extraction-data/audio/audio-test-1.expected.json
index a1e72a2b8..a20a519d3 100644
--- a/tests/functional-tests/test-extraction-data/audio/audio-test-1.expected.json
+++ b/tests/functional-tests/test-extraction-data/audio/audio-test-1.expected.json
@@ -16,19 +16,48 @@
"nfo:duration": "15",
"nfo:sampleRate": "22050",
"nfo:averageBitrate": "32000",
- "nmm:mbTrackID": "123456",
- "nmm:mbRecordingID": "456123",
"nmm:performer": {
"@type": "nmm:Artist",
"nmm:artistName": "AbBaby",
- "nmm:mbArtistID": "234561"
+ "tracker:hasExternalReference": {
+ "@id": "tracker:ExternalReference:https:%2F%2Fmusicbrainz.org%2Fdoc%2FArtist",
+ "@type": "tracker:ExternalReference",
+ "tracker:referenceSource": "https://musicbrainz.org/doc/Artist",
+ "tracker:referenceIdentifier": "234561"
+ }
},
"nmm:musicAlbum": {
"@type": "nmm:MusicAlbum",
"nie:title": "SinCos",
- "nmm:mbReleaseGroupID": "561234",
- "nmm:mbReleaseID": "345612"
+ "tracker:hasExternalReference": [
+ {
+ "@id": "tracker:ExternalReference:https:%2F%2Fmusicbrainz.org%2Fdoc%2FRelease",
+ "@type": "tracker:ExternalReference",
+ "tracker:referenceSource": "https://musicbrainz.org/doc/Release",
+ "tracker:referenceIdentifier": "345612"
+ },
+ {
+ "@id": "tracker:ExternalReference:https:%2F%2Fmusicbrainz.org%2Fdoc%2FRelease_Group",
+ "@type": "tracker:ExternalReference",
+ "tracker:referenceSource": "https://musicbrainz.org/doc/Release_Group",
+ "tracker:referenceIdentifier": "561234"
+ }
+ ]
},
+ "tracker:hasExternalReference": [
+ {
+ "@id": "tracker:ExternalReference:https:%2F%2Fmusicbrainz.org%2Fdoc%2FRecording",
+ "@type": "tracker:ExternalReference",
+ "tracker:referenceSource": "https://musicbrainz.org/doc/Recording",
+ "tracker:referenceIdentifier": "456123"
+ },
+ {
+ "@id": "tracker:ExternalReference:https:%2F%2Fmusicbrainz.org%2Fdoc%2FTrack",
+ "@type": "tracker:ExternalReference",
+ "tracker:referenceSource": "https://musicbrainz.org/doc/Track",
+ "tracker:referenceIdentifier": "123456"
+ }
+ ],
"nfo:hasHash": {
"@type": "nfo:hasHash",
"nfo:hashAlgorithm": "chromaprint",
diff --git a/tests/functional-tests/test-extraction-data/audio/audio-test-2.expected.json
b/tests/functional-tests/test-extraction-data/audio/audio-test-2.expected.json
index d4dd0089e..6941dc0b6 100644
--- a/tests/functional-tests/test-extraction-data/audio/audio-test-2.expected.json
+++ b/tests/functional-tests/test-extraction-data/audio/audio-test-2.expected.json
@@ -14,18 +14,47 @@
"nfo:channels": "2",
"nfo:sampleRate": "44100",
"nfo:averageBitrate": "256000",
- "nmm:mbTrackID": "123456",
- "nmm:mbRecordingID": "456123",
"nmm:performer": {
"@type": "nmm:Artist",
"nmm:artistName": "Anna Abreu",
- "nmm:mbArtistID": "234561"
+ "tracker:hasExternalReference": {
+ "@id": "tracker:ExternalReference:https:%2F%2Fmusicbrainz.org%2Fdoc%2FArtist",
+ "@type": "tracker:ExternalReference",
+ "tracker:referenceSource": "https://musicbrainz.org/doc/Artist",
+ "tracker:referenceIdentifier": "234561"
+ }
},
"nmm:musicAlbum": {
"@type": "nmm:MusicAlbum",
- "nmm:mbReleaseGroupID": "561234",
- "nmm:mbReleaseID": "345612"
+ "tracker:hasExternalReference": [
+ {
+ "@id": "tracker:ExternalReference:https:%2F%2Fmusicbrainz.org%2Fdoc%2FRelease",
+ "@type": "tracker:ExternalReference",
+ "tracker:referenceSource": "https://musicbrainz.org/doc/Release",
+ "tracker:referenceIdentifier": "345612"
+ },
+ {
+ "@id": "tracker:ExternalReference:https:%2F%2Fmusicbrainz.org%2Fdoc%2FRelease_Group",
+ "@type": "tracker:ExternalReference",
+ "tracker:referenceSource": "https://musicbrainz.org/doc/Release_Group",
+ "tracker:referenceIdentifier": "561234"
+ }
+ ]
},
+ "tracker:hasExternalReference": [
+ {
+ "@id": "tracker:ExternalReference:https:%2F%2Fmusicbrainz.org%2Fdoc%2FRecording",
+ "@type": "tracker:ExternalReference",
+ "tracker:referenceSource": "https://musicbrainz.org/doc/Recording",
+ "tracker:referenceIdentifier": "456123"
+ },
+ {
+ "@id": "tracker:ExternalReference:https:%2F%2Fmusicbrainz.org%2Fdoc%2FTrack",
+ "@type": "tracker:ExternalReference",
+ "tracker:referenceSource": "https://musicbrainz.org/doc/Track",
+ "tracker:referenceIdentifier": "123456"
+ }
+ ],
"nfo:hasHash": {
"@type": "nfo:hasHash",
"nfo:hashAlgorithm": "chromaprint",
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]