scripts

misc scripts and tools
git clone git://git.2f30.org/scripts.git
Log | Files | Refs

commit 98374f4d68aee1a66e258a13950c94f992512c24
parent 2dd9e17a901ecc1b5c06dd3fea0f156d2079c81e
Author: sin <sin@2f30.org>
Date:   Thu Jun 27 17:52:40 +0100

Add mpdlen

Diffstat:
mpdlen/Makefile | 7+++++++
mpdlen/mpdlen.c | 32++++++++++++++++++++++++++++++++
2 files changed, 39 insertions(+), 0 deletions(-)
diff --git a/mpdlen/Makefile b/mpdlen/Makefile @@ -0,0 +1,7 @@ +LDLIBS=-lmpdclient + +BIN=mpdlen +all: $(BIN) + +clean: + rm -f $(BIN) diff --git a/mpdlen/mpdlen.c b/mpdlen/mpdlen.c @@ -0,0 +1,32 @@ +#include <stdio.h> + +#include <mpd/client.h> + +/* usage: mpdlen [list] */ + +int +main(int argc, char *argv[]) +{ + struct mpd_connection *conn; + struct mpd_song *song; + unsigned secs = 0; + char *list = argv[1]; + + conn = mpd_connection_new(NULL, 0, 0); + + if (list != NULL) + mpd_send_list_playlist_meta(conn, list); + else + mpd_send_list_queue_meta(conn); + + while ((song = mpd_recv_song(conn)) != NULL) { + secs += mpd_song_get_duration(song); + mpd_song_free(song); + } + + mpd_connection_free(conn); + + printf("%02u:%02u:%02u\n", secs / 3600, secs % 3600 / 60, secs % 60); + + return 0; +}