[tracker-miners/wip/jfelder/tracker-extract-musicbrainz-external-resources: 2/2] extract-vorbis: Use ExtractReference to store musicbrainz tags



commit 897252849aa7c3adb6df0f0098ab8f73a817cf49
Author: Jean Felder <jean felder estimages com>
Date:   Mon Jul 15 20:45:25 2019 +0200

    extract-vorbis: 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/tracker-extract/tracker-extract-vorbis.c       | 43 +++++++++++++++++++---
 .../audio-test-vorbis-extractor.expected.json      | 37 +++++++++++++++++--
 2 files changed, 72 insertions(+), 8 deletions(-)
---
diff --git a/src/tracker-extract/tracker-extract-vorbis.c b/src/tracker-extract/tracker-extract-vorbis.c
index 2e5507d8c..6a4df3bae 100644
--- a/src/tracker-extract/tracker-extract-vorbis.c
+++ b/src/tracker-extract/tracker-extract-vorbis.c
@@ -171,7 +171,11 @@ tracker_extract_get_metadata (TrackerExtractInfo *info)
                md.creator = tracker_extract_new_artist (md.creator_name);
 
                if (vd.mb_artist_id) {
-                       tracker_resource_set_string (md.creator, "nmm:mbArtistID", vd.mb_artist_id);
+                       TrackerResource *mb_artist_id = 
tracker_extract_new_external_reference("https://musicbrainz.org/doc/Artist";,
+                                                                                              
vd.mb_artist_id);
+
+                       tracker_resource_set_relation (md.creator, "tracker:hasExternalReference", 
mb_artist_id);
+                       g_object_unref (mb_artist_id);
                        g_free (vd.mb_artist_id);
                }
 
@@ -180,6 +184,7 @@ tracker_extract_get_metadata (TrackerExtractInfo *info)
 
        if (vd.album) {
                TrackerResource *album, *album_disc, *album_artist;
+               TrackerResource *mb_release_id = NULL, *mb_release_group_id = NULL;
 
                if (vd.album_artist) {
                        album_artist = tracker_extract_new_artist (vd.album_artist);
@@ -210,12 +215,23 @@ tracker_extract_get_metadata (TrackerExtractInfo *info)
                }
 
                if (vd.mb_release_id) {
-                       tracker_resource_set_string (album, "nmm:mbReleaseID", vd.mb_release_id);
+                       mb_release_id = 
tracker_extract_new_external_reference("https://musicbrainz.org/doc/Release";,
+                                                                              vd.mb_release_id);
+
+                       tracker_resource_set_relation (album, "tracker:hasExternalReference", mb_release_id);
                        g_free (vd.mb_release_id);
                }
 
                if (vd.mb_release_group_id) {
-                       tracker_resource_set_string (album, "nmm:mbReleaseGroupID", vd.mb_release_group_id);
+                       mb_release_group_id = 
tracker_extract_new_external_reference("https://musicbrainz.org/doc/Release_Group";,
+                                                                                    vd.mb_release_group_id);
+
+                       if (mb_release_id) {
+                               tracker_resource_add_relation (album, "tracker:hasExternalReference", 
mb_release_group_id);
+
+                       } else
+                               tracker_resource_set_relation (album, "tracker:hasExternalReference", 
mb_release_group_id);
+
                        g_free (vd.mb_release_group_id);
                }
 
@@ -223,6 +239,8 @@ tracker_extract_get_metadata (TrackerExtractInfo *info)
                tracker_resource_set_relation (metadata, "nmm:musicAlbumDisc", album_disc);
 
                g_object_unref (album_disc);
+               g_object_unref (mb_release_id);
+               g_object_unref (mb_release_group_id);
        }
 
        g_free (vd.track_count);
@@ -301,13 +319,28 @@ tracker_extract_get_metadata (TrackerExtractInfo *info)
                g_free (vd.acoustid_fingerprint);
        }
 
+       TrackerResource *mb_recording_id = NULL, *mb_track_id = NULL;
+
        if (vd.mb_recording_id) {
-               tracker_resource_set_string (metadata, "nmm:mbRecordingID", vd.mb_recording_id);
+               mb_recording_id = 
tracker_extract_new_external_reference("https://musicbrainz.org/doc/Recording";,
+                                                                        vd.mb_recording_id);
+
+               tracker_resource_set_relation (metadata, "tracker:hasExternalReference", mb_recording_id);
                g_free (vd.mb_recording_id);
        }
 
        if (vd.mb_track_id) {
-               tracker_resource_set_string (metadata, "nmm:mbTrackID", vd.mb_track_id);
+               mb_track_id = tracker_extract_new_external_reference("https://musicbrainz.org/doc/Track";,
+                                                                    vd.mb_track_id);
+
+               if (mb_recording_id) {
+                       tracker_resource_add_relation (metadata, "tracker:hasExternalReference", mb_track_id);
+                       g_object_unref (mb_recording_id);
+               } else {
+                       tracker_resource_set_relation (metadata, "tracker:hasExternalReference", mb_track_id);
+               }
+
+               g_object_unref (mb_track_id);
                g_free (vd.mb_track_id);
        }
 
diff --git a/tests/functional-tests/test-extraction-data/audio/audio-test-vorbis-extractor.expected.json 
b/tests/functional-tests/test-extraction-data/audio/audio-test-vorbis-extractor.expected.json
index ef6587e16..1bcdc78d0 100644
--- a/tests/functional-tests/test-extraction-data/audio/audio-test-vorbis-extractor.expected.json
+++ b/tests/functional-tests/test-extraction-data/audio/audio-test-vorbis-extractor.expected.json
@@ -15,14 +15,45 @@
         "nmm:performer": {
             "@type": "nmm:Artist",
             "nmm:artistName": "AbBaby",
-            "nmm:mbArtistID": "234561"
+            "nfo: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"
+            "nfo: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"
+                }
+            ]
         },
+        "nfo: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]