diff options
author | Christian Hesse <mail@eworm.de> | 2024-06-19 21:35:11 +0200 |
---|---|---|
committer | Christian Hesse <mail@eworm.de> | 2024-06-19 21:42:47 +0200 |
commit | 8a60c98ecb161df1040ccca3259750b1aeb1d2e7 (patch) | |
tree | e4b85012df533770dd2416e63fd5305be1589d9e /mpd-notification.c | |
parent | b92cf4af44d7132f9a0e93a42068b87d0f2de614 (diff) | |
download | mpd-notification-8a60c98ecb161df1040ccca3259750b1aeb1d2e7.tar.gz mpd-notification-8a60c98ecb161df1040ccca3259750b1aeb1d2e7.tar.zst |
add a format specifier for duration
Diffstat (limited to 'mpd-notification.c')
-rw-r--r-- | mpd-notification.c | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/mpd-notification.c b/mpd-notification.c index f455e0f..7e7f302 100644 --- a/mpd-notification.c +++ b/mpd-notification.c @@ -213,7 +213,7 @@ done: } /*** format_text ***/ -char * format_text(const char* format, const char* title, const char* artist, const char* album) { +char * format_text(const char* format, const char* title, const char* artist, const char* album, unsigned int duration) { char * formatted, * tmp = NULL; size_t len; @@ -236,6 +236,13 @@ char * format_text(const char* format, const char* title, const char* artist, co tmp = g_markup_escape_text(album, -1); break; + case 'd': + size_t size; + size = snprintf(tmp, 0, "%d:%02d", duration / 60, duration % 60) + 1; + tmp = malloc(size); + snprintf(tmp, size, "%d:%02d", duration / 60, duration % 60); + break; + case 't': tmp = g_markup_escape_text(title, -1); break; @@ -285,7 +292,7 @@ int main(int argc, char ** argv) { * text_play = TEXT_PLAY, * text_pause = TEXT_PAUSE, * text_stop = TEXT_STOP, * uri = NULL; unsigned mpd_port = MPD_PORT, mpd_timeout = MPD_TIMEOUT, notification_timeout = NOTIFICATION_TIMEOUT; struct mpd_song * song = NULL; - unsigned int i, version = 0, help = 0, scale = 0, file_workaround = 0; + unsigned int i, version = 0, help = 0, scale = 0, file_workaround = 0, duration; int rc = EXIT_FAILURE; program = argv[0]; @@ -475,6 +482,7 @@ int main(int argc, char ** argv) { title = mpd_song_get_tag(song, MPD_TAG_TITLE, 0); artist = mpd_song_get_tag(song, MPD_TAG_ARTIST, 0); album = mpd_song_get_tag(song, MPD_TAG_ALBUM, 0); + duration = mpd_song_get_duration(song); /* ignore if we have no title */ if (title == NULL) @@ -486,7 +494,7 @@ int main(int argc, char ** argv) { /* get the formatted notification string */ notifystr = format_text(state == MPD_STATE_PLAY ? text_play : text_pause, - title, artist ? artist : "unknown artist", album ? album : "unknown album"); + title, artist ? artist : "unknown artist", album ? album : "unknown album", duration); uri = mpd_song_get_uri(song); |