Commit 569259fe authored by Sam Thursfield's avatar Sam Thursfield

Merge branch 'wip/jfelder/tracker-extract-musicbrainz-external-resources' into 'master'

Use ExternalReference to store MusicBrainz identifiers

See merge request GNOME/tracker-miners!91
parents 54897caf 88589ce5
...@@ -140,6 +140,39 @@ tracker_extract_new_equipment (const char *make, ...@@ -140,6 +140,39 @@ tracker_extract_new_equipment (const char *make,
return equipment; 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: * tracker_extract_new_location:
* @street_address: (allow none): main part of postal address, or %NULL * @street_address: (allow none): main part of postal address, or %NULL
......
...@@ -32,6 +32,7 @@ G_BEGIN_DECLS ...@@ -32,6 +32,7 @@ G_BEGIN_DECLS
TrackerResource *tracker_extract_new_artist (const char *name); TrackerResource *tracker_extract_new_artist (const char *name);
TrackerResource *tracker_extract_new_contact (const char *fullname); TrackerResource *tracker_extract_new_contact (const char *fullname);
TrackerResource *tracker_extract_new_equipment (const char *make, const char *model); 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_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_music_album_disc (const char *album_title, TrackerResource *album_artist, int disc_number, const char *date);
TrackerResource *tracker_extract_new_tag (const char *label); TrackerResource *tracker_extract_new_tag (const char *label);
......
...@@ -2714,6 +2714,7 @@ tracker_extract_get_metadata (TrackerExtractInfo *info) ...@@ -2714,6 +2714,7 @@ tracker_extract_get_metadata (TrackerExtractInfo *info)
if (md.album_name) { if (md.album_name) {
TrackerResource *album_disc = NULL, *album_artist = NULL; TrackerResource *album_disc = NULL, *album_artist = NULL;
TrackerResource *mb_release_id = NULL, *mb_release_group_id = NULL;
if (md.album_artist_name) if (md.album_artist_name)
album_artist = tracker_extract_new_artist (md.album_artist_name); album_artist = tracker_extract_new_artist (md.album_artist_name);
...@@ -2729,12 +2730,20 @@ tracker_extract_get_metadata (TrackerExtractInfo *info) ...@@ -2729,12 +2730,20 @@ tracker_extract_get_metadata (TrackerExtractInfo *info)
tracker_resource_set_relation (main_resource, "nmm:musicAlbumDisc", album_disc); tracker_resource_set_relation (main_resource, "nmm:musicAlbumDisc", album_disc);
if (md.mb_release_id) { 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) { if (md.mb_release_group_id) {
tracker_resource_set_string (md.album, "nmm:mbReleaseGroupID", mb_release_group_id = tracker_extract_new_external_reference("https://musicbrainz.org/doc/Release_Group",
md.mb_release_group_id); 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) { if (md.track_count > 0) {
...@@ -2743,6 +2752,8 @@ tracker_extract_get_metadata (TrackerExtractInfo *info) ...@@ -2743,6 +2752,8 @@ tracker_extract_get_metadata (TrackerExtractInfo *info)
g_object_unref (album_disc); g_object_unref (album_disc);
g_clear_object (&album_artist); 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"); tracker_resource_add_uri (main_resource, "rdf:type", "nmm:MusicPiece");
...@@ -2762,7 +2773,11 @@ tracker_extract_get_metadata (TrackerExtractInfo *info) ...@@ -2762,7 +2773,11 @@ tracker_extract_get_metadata (TrackerExtractInfo *info)
if (md.performer) { if (md.performer) {
tracker_resource_set_relation (main_resource, "nmm:performer", md.performer); tracker_resource_set_relation (main_resource, "nmm:performer", md.performer);
if (md.mb_artist_id) { 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) ...@@ -2806,11 +2821,24 @@ tracker_extract_get_metadata (TrackerExtractInfo *info)
} }
if (md.mb_recording_id) { 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) { 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) { if (md.acoustid_fingerprint) {
......
...@@ -171,7 +171,11 @@ tracker_extract_get_metadata (TrackerExtractInfo *info) ...@@ -171,7 +171,11 @@ tracker_extract_get_metadata (TrackerExtractInfo *info)
md.creator = tracker_extract_new_artist (md.creator_name); md.creator = tracker_extract_new_artist (md.creator_name);
if (vd.mb_artist_id) { 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); g_free (vd.mb_artist_id);
} }
...@@ -180,6 +184,7 @@ tracker_extract_get_metadata (TrackerExtractInfo *info) ...@@ -180,6 +184,7 @@ tracker_extract_get_metadata (TrackerExtractInfo *info)
if (vd.album) { if (vd.album) {
TrackerResource *album, *album_disc, *album_artist; TrackerResource *album, *album_disc, *album_artist;
TrackerResource *mb_release_id = NULL, *mb_release_group_id = NULL;
if (vd.album_artist) { if (vd.album_artist) {
album_artist = tracker_extract_new_artist (vd.album_artist); album_artist = tracker_extract_new_artist (vd.album_artist);
...@@ -210,12 +215,23 @@ tracker_extract_get_metadata (TrackerExtractInfo *info) ...@@ -210,12 +215,23 @@ tracker_extract_get_metadata (TrackerExtractInfo *info)
} }
if (vd.mb_release_id) { 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); g_free (vd.mb_release_id);
} }
if (vd.mb_release_group_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); g_free (vd.mb_release_group_id);
} }
...@@ -223,6 +239,8 @@ tracker_extract_get_metadata (TrackerExtractInfo *info) ...@@ -223,6 +239,8 @@ tracker_extract_get_metadata (TrackerExtractInfo *info)
tracker_resource_set_relation (metadata, "nmm:musicAlbumDisc", album_disc); tracker_resource_set_relation (metadata, "nmm:musicAlbumDisc", album_disc);
g_object_unref (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); g_free (vd.track_count);
...@@ -301,13 +319,28 @@ tracker_extract_get_metadata (TrackerExtractInfo *info) ...@@ -301,13 +319,28 @@ tracker_extract_get_metadata (TrackerExtractInfo *info)
g_free (vd.acoustid_fingerprint); g_free (vd.acoustid_fingerprint);
} }
TrackerResource *mb_recording_id = NULL, *mb_track_id = NULL;
if (vd.mb_recording_id) { 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); g_free (vd.mb_recording_id);
} }
if (vd.mb_track_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); g_free (vd.mb_track_id);
} }
......
...@@ -16,19 +16,48 @@ ...@@ -16,19 +16,48 @@
"nfo:duration": "15", "nfo:duration": "15",
"nfo:sampleRate": "22050", "nfo:sampleRate": "22050",
"nfo:averageBitrate": "32000", "nfo:averageBitrate": "32000",
"nmm:mbTrackID": "123456",
"nmm:mbRecordingID": "456123",
"nmm:performer": { "nmm:performer": {
"@type": "nmm:Artist", "@type": "nmm:Artist",
"nmm:artistName": "AbBaby", "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": { "nmm:musicAlbum": {
"@type": "nmm:MusicAlbum", "@type": "nmm:MusicAlbum",
"nie:title": "SinCos", "nie:title": "SinCos",
"nmm:mbReleaseGroupID": "561234", "tracker:hasExternalReference": [
"nmm:mbReleaseID": "345612" {
"@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": { "nfo:hasHash": {
"@type": "nfo:hasHash", "@type": "nfo:hasHash",
"nfo:hashAlgorithm": "chromaprint", "nfo:hashAlgorithm": "chromaprint",
......
...@@ -14,18 +14,47 @@ ...@@ -14,18 +14,47 @@
"nfo:channels": "2", "nfo:channels": "2",
"nfo:sampleRate": "44100", "nfo:sampleRate": "44100",
"nfo:averageBitrate": "256000", "nfo:averageBitrate": "256000",
"nmm:mbTrackID": "123456",
"nmm:mbRecordingID": "456123",
"nmm:performer": { "nmm:performer": {
"@type": "nmm:Artist", "@type": "nmm:Artist",
"nmm:artistName": "Anna Abreu", "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": { "nmm:musicAlbum": {
"@type": "nmm:MusicAlbum", "@type": "nmm:MusicAlbum",
"nmm:mbReleaseGroupID": "561234", "tracker:hasExternalReference": [
"nmm:mbReleaseID": "345612" {
"@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": { "nfo:hasHash": {
"@type": "nfo:hasHash", "@type": "nfo:hasHash",
"nfo:hashAlgorithm": "chromaprint", "nfo:hashAlgorithm": "chromaprint",
......
...@@ -15,14 +15,45 @@ ...@@ -15,14 +15,45 @@
"nmm:performer": { "nmm:performer": {
"@type": "nmm:Artist", "@type": "nmm:Artist",
"nmm:artistName": "AbBaby", "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": { "nmm:musicAlbum": {
"@type": "nmm:MusicAlbum", "@type": "nmm:MusicAlbum",
"nie:title": "SinCos", "nie:title": "SinCos",
"nmm:mbReleaseGroupID": "561234", "tracker:hasExternalReference": [
"nmm:mbReleaseID": "345612" {
"@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": { "nfo:hasHash": {
"@type": "nfo:hasHash", "@type": "nfo:hasHash",
"nfo:hashAlgorithm": "chromaprint", "nfo:hashAlgorithm": "chromaprint",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment