From d1a8029e6cfc6854b226f0d42a5e77baed441058 Mon Sep 17 00:00:00 2001 From: Midgard Date: Wed, 31 Aug 2022 14:45:46 +0200 Subject: [PATCH] =?UTF-8?q?module/mpd:=20add=20=E2=80=9Cfile=E2=80=9D=20ta?= =?UTF-8?q?g?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 2 ++ doc/yambar-modules-mpd.5.scd | 3 +++ modules/mpd.c | 10 +++++++++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cafee73..06e8b58 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,10 +26,12 @@ `ul-speed` when `poll-interval` is set. * new module: disk-io. * alsa: `dB` tag ([#202][202]) +* mpd: `file` tag ([#219][219]). [153]: https://codeberg.org/dnkl/yambar/issues/153 [159]: https://codeberg.org/dnkl/yambar/issues/159 [202]: https://codeberg.org/dnkl/yambar/issues/202 +[219]: https://codeberg.org/dnkl/yambar/pulls/219 ### Changed diff --git a/doc/yambar-modules-mpd.5.scd b/doc/yambar-modules-mpd.5.scd index 93e776b..ccc5d85 100644 --- a/doc/yambar-modules-mpd.5.scd +++ b/doc/yambar-modules-mpd.5.scd @@ -32,6 +32,9 @@ mpd - This module provides MPD status such as currently playing artist/album/son | title : string : Title of currently playing song (also valid in *paused* state) +| file +: string +: Filename or URL of currently playing song (also valid in *paused* state) | pos : string : *%M:%S*-formatted string describing the song's current position diff --git a/modules/mpd.c b/modules/mpd.c index 27992d3..05edd7b 100644 --- a/modules/mpd.c +++ b/modules/mpd.c @@ -42,6 +42,7 @@ struct private { char *album; char *artist; char *title; + char *file; struct { uint64_t value; @@ -75,6 +76,7 @@ destroy(struct module *mod) free(m->album); free(m->artist); free(m->title); + free(m->file); assert(m->conn == NULL); m->label->destroy(m->label); @@ -173,13 +175,14 @@ content(struct module *mod) tag_new_string(mod, "album", m->album), tag_new_string(mod, "artist", m->artist), tag_new_string(mod, "title", m->title), + tag_new_string(mod, "file", m->file), tag_new_string(mod, "pos", pos), tag_new_string(mod, "end", end), tag_new_int(mod, "duration", m->duration), tag_new_int_realtime( mod, "elapsed", elapsed, 0, m->duration, realtime), }, - .count = 12, + .count = 13, }; mtx_unlock(&mod->lock); @@ -354,20 +357,24 @@ update_status(struct module *mod) free(m->album); m->album = NULL; free(m->artist); m->artist = NULL; free(m->title); m->title = NULL; + free(m->file); m->file = NULL; mtx_unlock(&mod->lock); } else { const char *album = mpd_song_get_tag(song, MPD_TAG_ALBUM, 0); const char *artist = mpd_song_get_tag(song, MPD_TAG_ARTIST, 0); const char *title = mpd_song_get_tag(song, MPD_TAG_TITLE, 0); + const char *file = mpd_song_get_uri(song); mtx_lock(&mod->lock); free(m->album); free(m->artist); free(m->title); + free(m->file); m->album = album != NULL ? strdup(album) : NULL; m->artist = artist != NULL ? strdup(artist) : NULL; m->title = title != NULL ? strdup(title) : NULL; + m->file = file != NULL ? strdup(file) : NULL; mtx_unlock(&mod->lock); mpd_song_free(song); @@ -397,6 +404,7 @@ run(struct module *mod) free(m->album); m->album = NULL; free(m->artist); m->artist = NULL; free(m->title); m->title = NULL; + free(m->file); m->file = NULL; m->state = MPD_STATE_UNKNOWN; m->elapsed.value = m->duration = 0; m->elapsed.when.tv_sec = m->elapsed.when.tv_nsec = 0;