aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSpencer Williams <spnw@plexwave.org>2025-04-14 15:28:09 -0400
committerSpencer Williams <spnw@plexwave.org>2025-04-14 15:28:09 -0400
commit0a5872e156c316c2bb51d1d70c27be5ec0cf60c8 (patch)
treeee35d1546cf0ee77bbae68724d1fd0965d1bed40
parentadaa3396edd425312065a134aec99991bd7b9cdd (diff)
Add mpc format string support
-rw-r--r--mpc-bar.m19
1 files changed, 8 insertions, 11 deletions
diff --git a/mpc-bar.m b/mpc-bar.m
index 3363d1d..90ff0e3 100644
--- a/mpc-bar.m
+++ b/mpc-bar.m
@@ -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];