diff options
| author | ivan-boikov <ik.boikov.public@protonmail.com> | 2024-01-13 19:52:01 +0100 |
|---|---|---|
| committer | ivan-boikov <ik.boikov.public@protonmail.com> | 2024-01-13 19:52:01 +0100 |
| commit | 8b8363eaa2633c8a7392521416f45549ff10c164 (patch) | |
| tree | c503f910abdc6b280895fa28e008bec8edd637e1 /components/mpd.c | |
| parent | f68f49273e70b3767b30c549dda04ddd4d25fc91 (diff) | |
My initial changes
Diffstat (limited to 'components/mpd.c')
| -rw-r--r-- | components/mpd.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/components/mpd.c b/components/mpd.c new file mode 100644 index 0000000..b32706e --- /dev/null +++ b/components/mpd.c @@ -0,0 +1,38 @@ +/* See LICENSE file for copyright and license details. */ +#include <stdint.h> +#include <stdio.h> +#include <string.h> + +#include "../slstatus.h" +#include "../util.h" + +const char * +mpd_track(const char *path) +{ + FILE *fp; + const unsigned short N = 128; + char track[N]; + char state[16]; + + if (!(fp = fopen(path, "r"))) + return NULL; + + if (fgets(track, N, fp) == NULL || fscanf(fp, "%s", state) != 1) + { + fclose(fp); + return NULL; + } + + fclose(fp); + + // otherwise statusbar will show a weird symbol + track[strlen(track)-1] = '\0'; + + if (strcmp(state, "[playing]") == 0) + return bprintf("%s ", track); + + if (strcmp(state, "[paused]") == 0) + return bprintf("%s ", track); + + return NULL; +} |
