[wiki] [sites] very simple mpd status || Thuban

From: <git_AT_suckless.org>
Date: Thu, 20 Jun 2013 14:04:03 +0200

commit 3dde5a0be4ba118a1112a2e69a4c27e9b6742ee3
Author: Thuban <thuban_AT_singularity.fr>
Date: Thu Jun 20 14:04:00 2013 +0200

    very simple mpd status

diff --git a/dwm.suckless.org/dwmstatus/index.md b/dwm.suckless.org/dwmstatus/index.md
index 3a05761..d17c6bf 100644
--- a/dwm.suckless.org/dwmstatus/index.md
+++ b/dwm.suckless.org/dwmstatus/index.md
_AT_@ -41,6 +41,7 @@ add them here as file or as code example.
   tmpinfo function. It prints line after line the content of
   /tmp/dwmbuf.
 * [Simple function to have uptime](uptime.c)
+* [Simple function to have mpd title/artist info](mpdstatus.c)
 
 Questions
 ---------
diff --git a/dwm.suckless.org/dwmstatus/mpdstatus.c b/dwm.suckless.org/dwmstatus/mpdstatus.c
new file mode 100644
index 0000000..eaaa98c
--- /dev/null
+++ b/dwm.suckless.org/dwmstatus/mpdstatus.c
_AT_@ -0,0 +1,54 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <mpd/client.h>
+
+/* add to config.mk :
+# mpd
++ MPDLIB = -lmpdclient
++ MPDFLAG = -DMPD
+
+- LIBS = -L/usr/lib -lc -L${X11LIB} -lX11
++ LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 ${MPDLIB}
+
+- CPPFLAGS = -DVERSION=\"${VERSION}\"
++ CPPFLAGS = ${MPDFLAG} -DVERSION=\"${VERSION}\"
+*/
+/* simple function to retrieve mpd status */
+char *
+getmpdstat() {
+ struct mpd_song * song = NULL;
+ const char * title = NULL;
+ const char * artist = NULL;
+ char * retstr = NULL;
+ int elapsed = 0, total = 0;
+ struct mpd_connection * conn = mpd_connection_new(NULL, 0, 30000);
+ if (mpd_connection_get_error(conn)) return("");
+
+ mpd_command_list_begin(conn, true);
+ mpd_send_status(conn);
+ mpd_send_current_song(conn);
+ mpd_command_list_end(conn);
+
+ struct mpd_status* theStatus = mpd_recv_status(conn);
+ if (!theStatus) return("");
+ else
+ if (mpd_status_get_state(theStatus) == MPD_STATE_PLAY) {
+ mpd_response_next(conn);
+ song = mpd_recv_song(conn);
+ title = smprintf("%s",mpd_song_get_tag(song, MPD_TAG_TITLE, 0));
+ artist = smprintf("%s",mpd_song_get_tag(song, MPD_TAG_ARTIST, 0));
+ elapsed = mpd_status_get_elapsed_time(theStatus);
+ total = mpd_status_get_total_time(theStatus);
+ mpd_song_free(song);
+ retstr = smprintf("%d:%d/%d:%d %s - %s",
+ elapsed/60, elapsed%60,
+ total/60, total%60,
+ artist, title);
+ }
+ else retstr = smprintf("");
+ mpd_response_finish(conn);
+ mpd_connection_free(conn);
+ return retstr;
+}
+
Received on Thu Jun 20 2013 - 14:04:03 CEST

This archive was generated by hypermail 2.3.0 : Thu Jun 20 2013 - 14:12:14 CEST