Skip to content

Commit

Permalink
expose musicbrainz metadata if available
Browse files Browse the repository at this point in the history
  • Loading branch information
tpeacock19 committed Aug 9, 2022
1 parent 6f07b20 commit 75db00a
Showing 1 changed file with 34 additions and 6 deletions.
40 changes: 34 additions & 6 deletions mpris.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,14 @@ static void add_metadata_item_int(mpv_handle *mpv, GVariantDict *dict,
}

static void add_metadata_item_string_list(mpv_handle *mpv, GVariantDict *dict,
const char *property, const char *tag)
const char *property, const char *tag,
const char *sep)
{
char *temp = mpv_get_property_string(mpv, property);

if (temp) {
GVariantBuilder builder;
char **list = g_strsplit(temp, ", ", 0);
char **list = g_strsplit(temp, sep, 0);
char **iter = list;
g_variant_builder_init(&builder, G_VARIANT_TYPE("as"));

Expand All @@ -149,6 +150,28 @@ static void add_metadata_item_string_list(mpv_handle *mpv, GVariantDict *dict,
}
}

static void add_metadata_mb(mpv_handle *mpv, GVariantDict *dict,
const char *property, const char *tag)
{
char *temp = mpv_get_property_string(mpv, property);

if (temp) {
/* Check for multi-value ID3 v2.3 tag (forward slash as separator) */
if (strchr(temp, '/') != NULL) {
add_metadata_item_string_list(mpv, dict, property, tag, "/");
}
/* Check for multi-value ID3 v2.4 tag (semicolon as separator) */
else if (strchr(temp, ';') != NULL) {
add_metadata_item_string_list(mpv, dict, property, tag, ";");
}
/* Default to single value */
else {
add_metadata_item_string(mpv, dict, property, tag);
}
mpv_free(temp);
}
}

static gchar *path_to_uri(mpv_handle *mpv, char *path)
{
#if GLIB_CHECK_VERSION(2, 58, 0)
Expand Down Expand Up @@ -360,10 +383,15 @@ static GVariant *create_metadata(UserData *ud)
add_metadata_item_string(ud->mpv, &dict, "metadata/by-key/Album", "xesam:album");
add_metadata_item_string(ud->mpv, &dict, "metadata/by-key/Genre", "xesam:genre");

add_metadata_item_string_list(ud->mpv, &dict, "metadata/by-key/uploader", "xesam:artist");
add_metadata_item_string_list(ud->mpv, &dict, "metadata/by-key/Artist", "xesam:artist");
add_metadata_item_string_list(ud->mpv, &dict, "metadata/by-key/Album_Artist", "xesam:albumArtist");
add_metadata_item_string_list(ud->mpv, &dict, "metadata/by-key/Composer", "xesam:composer");
add_metadata_item_string_list(ud->mpv, &dict, "metadata/by-key/uploader", "xesam:artist", ", ");
add_metadata_item_string_list(ud->mpv, &dict, "metadata/by-key/Artist", "xesam:artist", ", ");
add_metadata_item_string_list(ud->mpv, &dict, "metadata/by-key/Album_Artist", "xesam:albumArtist", ", ");
add_metadata_item_string_list(ud->mpv, &dict, "metadata/by-key/Composer", "xesam:composer", ", ");

add_metadata_mb(ud->mpv, &dict, "metadata/by-key/MusicBrainz Release Track Id", "mb:trackId");
add_metadata_mb(ud->mpv, &dict, "metadata/by-key/MusicBrainz Album Id", "mb:albumId");
add_metadata_mb(ud->mpv, &dict, "metadata/by-key/MusicBrainz Artist Id", "mb:artistId");
add_metadata_mb(ud->mpv, &dict, "metadata/by-key/MusicBrainz Album Artist Id", "mb:albumartistId");

add_metadata_item_int(ud->mpv, &dict, "metadata/by-key/Track", "xesam:trackNumber");
add_metadata_item_int(ud->mpv, &dict, "metadata/by-key/Disc", "xesam:discNumber");
Expand Down

0 comments on commit 75db00a

Please sign in to comment.