diff options
author | Spencer Williams <spnw@plexwave.org> | 2025-04-14 15:28:09 -0400 |
---|---|---|
committer | Spencer Williams <spnw@plexwave.org> | 2025-04-14 15:28:09 -0400 |
commit | 0a5872e156c316c2bb51d1d70c27be5ec0cf60c8 (patch) | |
tree | ee35d1546cf0ee77bbae68724d1fd0965d1bed40 | |
parent | adaa3396edd425312065a134aec99991bd7b9cdd (diff) |
Add mpc format string support
-rw-r--r-- | mpc-bar.m | 19 |
1 files changed, 8 insertions, 11 deletions
@@ -27,6 +27,7 @@ #include <string.h> #include "ini.h" +#include "mpc/song_format.h" #define VERSION "0.2" #define TITLE_MAX_LENGTH 96 @@ -48,6 +49,7 @@ static NSString *formatTime(unsigned int t) { struct config { char *host; + char *host, *format; unsigned port; }; @@ -59,6 +61,8 @@ static int handler(void *userdata, const char *section, const char *name, c->host = strdup(value); } else if (MATCH("connection", "port")) { c->port = atoi(value); + } else if (MATCH("display", "format")) { + c->format = strdup(value); } else { return 0; } @@ -88,6 +92,7 @@ static int handler(void *userdata, const char *section, const char *name, - (void)initConfig { config.host = NULL; config.port = 0; + config.format = "[%name%: &[[%artist%|%performer%|%composer%|%albumartist%] - ]%title%]|%name%|[[%artist%|%performer%|%composer%|%albumartist%] - ]%title%|%file%"; } - (void)readConfigFile { const char *path = [[NSHomeDirectory() @@ -202,17 +207,9 @@ static int handler(void *userdata, const char *section, const char *name, else [menuButton setImage:nil]; - const char *artist = mpd_song_get_tag(song, MPD_TAG_ARTIST, 0); - const char *title = mpd_song_get_tag(song, MPD_TAG_TITLE, 0); - - if (artist) - [output appendString:utf8String(artist)]; - if (artist && title) - [output appendString:@" - "]; - if (title) - [output appendString:utf8String(title)]; - if (!(artist || title)) - [output appendString:utf8String(mpd_song_get_uri(song))]; + char *s = format_song(song, config.format); + [output appendString:utf8String(s)]; + free(s); } else { [output setString:@"No song playing"]; [menuButton setImage:nil]; |