[tracker-miners/wip/carlosg/writeback-musicbrainz] tracker-writeback: Support musicbrainz tags in gstreamer module
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker-miners/wip/carlosg/writeback-musicbrainz] tracker-writeback: Support musicbrainz tags in gstreamer module
- Date: Sun, 28 Jun 2020 18:36:45 +0000 (UTC)
commit 654ccd04e546fb0b64068861f463a0db88ee514b
Author: Carlos Garnacho <carlosg gnome org>
Date: Sun Jun 28 20:34:20 2020 +0200
tracker-writeback: Support musicbrainz tags in gstreamer module
.../tracker-writeback-gstreamer.c | 85 ++++++++++++++++++++++
1 file changed, 85 insertions(+)
---
diff --git a/src/tracker-writeback/tracker-writeback-gstreamer.c
b/src/tracker-writeback/tracker-writeback-gstreamer.c
index fbe8983d0..20155b7e6 100644
--- a/src/tracker-writeback/tracker-writeback-gstreamer.c
+++ b/src/tracker-writeback/tracker-writeback-gstreamer.c
@@ -576,6 +576,63 @@ writeback_gstreamer_set (TagElements *element,
return TRUE;
}
+static void
+handle_musicbrainz_tags (TrackerResource *resource,
+ const gchar *prop,
+ TagElements *element,
+ const gchar * const *allowed_tags)
+{
+ GList *references, *r;
+
+ references = tracker_resource_get_values (resource, prop);
+
+ for (r = references; r; r = r->next) {
+ TrackerResource *ref;
+ GValue *value, val = G_VALUE_INIT;
+ const gchar *source, *identifier;
+
+ value = r->data;
+
+ if (!G_VALUE_HOLDS (value, TRACKER_TYPE_RESOURCE))
+ continue;
+
+ ref = g_value_get_object (value);
+
+ source = tracker_resource_get_first_uri (ref, "tracker:referenceSource");
+ identifier = tracker_resource_get_first_string (ref, "tracker:referenceIdentifier");
+
+ if (!source || !g_strv_contains (allowed_tags, source))
+ continue;
+
+ if (g_strcmp0 (source, "https://musicbrainz.org/doc/Recording") == 0) {
+ g_value_init (&val, G_TYPE_STRING);
+ g_value_set_string (&val, identifier);
+ writeback_gstreamer_set (element, GST_TAG_MUSICBRAINZ_TRACKID, &val);
+ g_value_unset (&val);
+ } else if (g_strcmp0 (source, "https://musicbrainz.org/doc/Track") == 0) {
+ g_value_init (&val, G_TYPE_STRING);
+ g_value_set_string (&val, identifier);
+ writeback_gstreamer_set (element, GST_TAG_MUSICBRAINZ_RELEASETRACKID, &val);
+ g_value_unset (&val);
+ } else if (g_strcmp0 (source, "https://musicbrainz.org/doc/Release") == 0) {
+ g_value_init (&val, G_TYPE_STRING);
+ g_value_set_string (&val, identifier);
+ writeback_gstreamer_set (element, GST_TAG_MUSICBRAINZ_ALBUMID, &val);
+ g_value_unset (&val);
+ } else if (g_strcmp0 (source, "https://musicbrainz.org/doc/Release_Group") == 0) {
+ g_value_init (&val, G_TYPE_STRING);
+ g_value_set_string (&val, identifier);
+ writeback_gstreamer_set (element, GST_TAG_MUSICBRAINZ_RELEASEGROUPID, &val);
+ g_value_unset (&val);
+ } else if (g_strcmp0 (source, "https://musicbrainz.org/doc/Artist") == 0) {
+ g_value_init (&val, G_TYPE_STRING);
+ g_value_set_string (&val, identifier);
+ writeback_gstreamer_set (element, GST_TAG_MUSICBRAINZ_ARTISTID, &val);
+ g_value_unset (&val);
+ }
+ }
+}
+
static gboolean
writeback_gstreamer_write_file_metadata (TrackerWritebackFile *writeback,
GFile *file,
@@ -640,12 +697,20 @@ writeback_gstreamer_write_file_metadata (TrackerWritebackFile *writeback,
if (g_strcmp0 (prop, "nmm:performer") == 0) {
TrackerResource *performer;
const gchar *name = NULL;
+ const gchar *mb_tags[] = {
+ "https://musicbrainz.org/doc/Artist",
+ NULL,
+ };
performer = tracker_resource_get_first_relation (resource, prop);
if (performer) {
name = tracker_resource_get_first_string (performer,
"nmm:artistName");
+
+ handle_musicbrainz_tags (performer,
+ "tracker:hasExternalReference",
+ element, mb_tags);
}
if (name) {
@@ -790,12 +855,22 @@ writeback_gstreamer_write_file_metadata (TrackerWritebackFile *writeback,
disc = tracker_resource_get_first_relation (resource, prop);
if (disc) {
+ const gchar *mb_tags[] = {
+ "https://musicbrainz.org/doc/Release",
+ "https://musicbrainz.org/doc/Release_Group",
+ NULL,
+ };
+
number = tracker_resource_get_first_int (disc,
"nmm:setNumber");
g_value_init (&val, G_TYPE_INT);
g_value_set_int (&val, number);
writeback_gstreamer_set (element, GST_TAG_ALBUM_VOLUME_NUMBER, &val);
g_value_unset (&val);
+
+ handle_musicbrainz_tags (disc,
+ "tracker:hasExternalReference",
+ element, mb_tags);
}
}
@@ -859,6 +934,16 @@ writeback_gstreamer_write_file_metadata (TrackerWritebackFile *writeback,
g_string_free (keyword_str, TRUE);
g_list_free (keywords);
}
+
+ if (g_strcmp0 (prop, "tracker:hasExternalReference") == 0) {
+ const gchar *mb_tags[] = {
+ "https://musicbrainz.org/doc/Recording",
+ "https://musicbrainz.org/doc/Track",
+ NULL,
+ };
+
+ handle_musicbrainz_tags (resource, prop, element, mb_tags);
+ }
}
writeback_gstreamer_save (element, file, error);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]