module/mpd: add “file” tag

This commit is contained in:
Midgard 2022-08-31 14:45:46 +02:00 committed by Daniel Eklöf
parent 5da1cd4a38
commit d1a8029e6c
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
3 changed files with 14 additions and 1 deletions

View file

@ -26,10 +26,12 @@
`ul-speed` when `poll-interval` is set. `ul-speed` when `poll-interval` is set.
* new module: disk-io. * new module: disk-io.
* alsa: `dB` tag ([#202][202]) * alsa: `dB` tag ([#202][202])
* mpd: `file` tag ([#219][219]).
[153]: https://codeberg.org/dnkl/yambar/issues/153 [153]: https://codeberg.org/dnkl/yambar/issues/153
[159]: https://codeberg.org/dnkl/yambar/issues/159 [159]: https://codeberg.org/dnkl/yambar/issues/159
[202]: https://codeberg.org/dnkl/yambar/issues/202 [202]: https://codeberg.org/dnkl/yambar/issues/202
[219]: https://codeberg.org/dnkl/yambar/pulls/219
### Changed ### Changed

View file

@ -32,6 +32,9 @@ mpd - This module provides MPD status such as currently playing artist/album/son
| title | title
: string : string
: Title of currently playing song (also valid in *paused* state) : 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 | pos
: string : string
: *%M:%S*-formatted string describing the song's current position : *%M:%S*-formatted string describing the song's current position

View file

@ -42,6 +42,7 @@ struct private {
char *album; char *album;
char *artist; char *artist;
char *title; char *title;
char *file;
struct { struct {
uint64_t value; uint64_t value;
@ -75,6 +76,7 @@ destroy(struct module *mod)
free(m->album); free(m->album);
free(m->artist); free(m->artist);
free(m->title); free(m->title);
free(m->file);
assert(m->conn == NULL); assert(m->conn == NULL);
m->label->destroy(m->label); m->label->destroy(m->label);
@ -173,13 +175,14 @@ content(struct module *mod)
tag_new_string(mod, "album", m->album), tag_new_string(mod, "album", m->album),
tag_new_string(mod, "artist", m->artist), tag_new_string(mod, "artist", m->artist),
tag_new_string(mod, "title", m->title), tag_new_string(mod, "title", m->title),
tag_new_string(mod, "file", m->file),
tag_new_string(mod, "pos", pos), tag_new_string(mod, "pos", pos),
tag_new_string(mod, "end", end), tag_new_string(mod, "end", end),
tag_new_int(mod, "duration", m->duration), tag_new_int(mod, "duration", m->duration),
tag_new_int_realtime( tag_new_int_realtime(
mod, "elapsed", elapsed, 0, m->duration, realtime), mod, "elapsed", elapsed, 0, m->duration, realtime),
}, },
.count = 12, .count = 13,
}; };
mtx_unlock(&mod->lock); mtx_unlock(&mod->lock);
@ -354,20 +357,24 @@ update_status(struct module *mod)
free(m->album); m->album = NULL; free(m->album); m->album = NULL;
free(m->artist); m->artist = NULL; free(m->artist); m->artist = NULL;
free(m->title); m->title = NULL; free(m->title); m->title = NULL;
free(m->file); m->file = NULL;
mtx_unlock(&mod->lock); mtx_unlock(&mod->lock);
} else { } else {
const char *album = mpd_song_get_tag(song, MPD_TAG_ALBUM, 0); 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 *artist = mpd_song_get_tag(song, MPD_TAG_ARTIST, 0);
const char *title = mpd_song_get_tag(song, MPD_TAG_TITLE, 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); mtx_lock(&mod->lock);
free(m->album); free(m->album);
free(m->artist); free(m->artist);
free(m->title); free(m->title);
free(m->file);
m->album = album != NULL ? strdup(album) : NULL; m->album = album != NULL ? strdup(album) : NULL;
m->artist = artist != NULL ? strdup(artist) : NULL; m->artist = artist != NULL ? strdup(artist) : NULL;
m->title = title != NULL ? strdup(title) : NULL; m->title = title != NULL ? strdup(title) : NULL;
m->file = file != NULL ? strdup(file) : NULL;
mtx_unlock(&mod->lock); mtx_unlock(&mod->lock);
mpd_song_free(song); mpd_song_free(song);
@ -397,6 +404,7 @@ run(struct module *mod)
free(m->album); m->album = NULL; free(m->album); m->album = NULL;
free(m->artist); m->artist = NULL; free(m->artist); m->artist = NULL;
free(m->title); m->title = NULL; free(m->title); m->title = NULL;
free(m->file); m->file = NULL;
m->state = MPD_STATE_UNKNOWN; m->state = MPD_STATE_UNKNOWN;
m->elapsed.value = m->duration = 0; m->elapsed.value = m->duration = 0;
m->elapsed.when.tv_sec = m->elapsed.when.tv_nsec = 0; m->elapsed.when.tv_sec = m->elapsed.when.tv_nsec = 0;