From dcdc795b2a8a4854f54bd958594ff386c5e9ac52 Mon Sep 17 00:00:00 2001 From: depsterr Date: Sun, 24 Jan 2021 02:38:51 +0100 Subject: [PATCH] initial commit --- .gitignore | 2 ++ .mpdart.c.swp | Bin 0 -> 12288 bytes Makefile | 11 ++++++ configure.sh | 7 ++++ mpdart.c | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 115 insertions(+) create mode 100644 .gitignore create mode 100644 .mpdart.c.swp create mode 100644 Makefile create mode 100755 configure.sh create mode 100644 mpdart.c diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b8ac3a9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +config.mk +mpdart diff --git a/.mpdart.c.swp b/.mpdart.c.swp new file mode 100644 index 0000000000000000000000000000000000000000..872bd28ae27739337e6a3367c917df8494a47fa4 GIT binary patch literal 12288 zcmeI2&u<$=6vrnBRSl$2+Fm#@an;6l>^KgWs%a`kZGH+sTqdPVa9I!F!sjDkuOHnRmNNqhFjFX$EOkWMYP8p8h%?Ftc6kV zX3eQ}L)VT}`j~S5!+JBtC}0$LOa*$XRXufxy*N{!CJV<40Iz^DD1oEk z2>AOM#{L4og73gB@Ci_$3F_b&_~Q^`-+~=*2W$fm*x+^01Z!Xh)Ib3|34R;HIX8yK+mthP4Ff77<>e-f-69QdGI_K1Eb&|(0SO0b!1#N z3K#{90!D%TsK7OR0bOIGqoc7WL|CksX7SSRNKf$MIQ~)3iiERiN!JraC-8mYC>i(_ zUN4m}kH%x+yL#N}+VRHFq>D@Et;O>f7ObTU^RF!|!*t)4>NIvtRtA3CYDGd6W3(`e z{=kDp>X$B`<7rEeXeX0}?z-j5sKWL3G`TI5)r(|eM@N8whDMd$)}s|pPBrFVvgVf? ziz|%^pDtB6Hr{(dW3h2zA)6mY(pRlw;pL#uL(krle)}|^I1x|q^{wRDih?e+YUo_^ z3l-X>R_2XM=P&UHs)>lpuH6>AT*HuTaqS^RK0e2DLXs8ZBQ%st zzh0v~r2=t!5kgivx5JYtG8Oe4y`dg2>uo9NX&u%R1)z6c7VKTEBSh-X70Mtl=aOno z;?c2)XcLly7$wY4xKsLvGBfDBJl)LN^;~hrf7tM7f>Iz=LL?f1n-J&5N+{R5a~k59Og+<)8f&!lMN=@W$zEl=!?FN zrW3>}Ip|>!r7b19BIqd!I=QudC-o@RmV~`&7`w{oEFmlzQv75=#9SY8)e#(3&Vv@0ijFgCcP}xQa2{j9 z<4`!VwWUv6w--x?<7&e#ORDyz>hP+Y*D#BOG)&{yS6!+KoV8UTi{;5lJ8Ez0D1?WN zlH;o)ryCZ_G=u|RRfQ5id6LuX<$9B@bZv{Y{(pwThZ~~w!BFZ9W#rMmbPD=AMLUqB zVtD04190`C^qv^ROv)ftp&cP^#1`w6P%gW+^o!I$uT$Yp$BxQn9lkC}{hq4@IDpKv z-2If*Y?){6WM0pYW!uMvLrKcg0SiMTskrFQwo7%Q&5ldo@p`V{XJDr0coNs/dev/null 2>&1; then + printf '%s\n' "CONFIG=$(pkg-config libmpdclient --libs --cflags)" > config.mk +else + printf '%s\n' "CONFIG=-lmpdclient" > config.mk +fi diff --git a/mpdart.c b/mpdart.c new file mode 100644 index 0000000..d9280c0 --- /dev/null +++ b/mpdart.c @@ -0,0 +1,95 @@ +#include +#include +#include + +#include + +#include + +char* mpd_host = 0; +unsigned mpd_port = 0; +unsigned mpd_timeout = 0; +struct mpd_connection* connection = 0; + +char* mpd_db_dir = 0; + +int main(int argc, char** argv) { + + /* parse args */ + while (*++argv) { + if (!strcmp(*argv, "-d")) + mpd_db_dir = *++argv; + else if (!strcmp(*argv, "-h")) + mpd_host = *++argv; + else if (!strcmp(*argv, "-p") && argv[1]) + mpd_port = atoi(*++argv); + else if (!strcmp(*argv, "-t") && argv[1]) + mpd_timeout = atoi(*++argv); + } + + if (!mpd_db_dir) { + fprintf(stderr, "Please specify mpd music directory with -d\n"); + exit(1); + } + + + /* strip all '/'es from the end of it */ + { + int i = 0; + for (; mpd_db_dir[i]; i++); + while (mpd_db_dir[--i] == '/'); + mpd_db_dir[i+1] = '\0'; + } + + connection = mpd_connection_new(mpd_host, mpd_port, mpd_timeout); + + if (!connection) { + fprintf(stderr, "Unable to allocate memory for mpd_connection struct\n"); + exit(1); + } + + if (mpd_connection_get_error(connection) != MPD_ERROR_SUCCESS) { + fprintf(stderr, "%s\n", mpd_connection_get_error_message(connection)); + exit(1); + } + + const int* version = mpd_connection_get_server_version(connection); + printf("Connected to mpd server version %d.%d.%d\n", version[0], version[1], version[2]); + + int song_id; + int old_song_id = -1; + + while (1) { + + struct mpd_song* song; + + mpd_send_current_song(connection); + song = mpd_recv_song(connection); + + if (!song) { + fprintf(stderr, "failed to get mpd song\n"); + /* TODO clear image */ + goto wait; + } + + song_id = mpd_song_get_id(song); + + if (song_id != old_song_id) { + /* TODO render image */ + printf("Now playing: '%s' by '%s' from '%s/%s'\n", + mpd_song_get_tag(song, MPD_TAG_TITLE, 0), + mpd_song_get_tag(song, MPD_TAG_ARTIST, 0), + mpd_db_dir, mpd_song_get_uri(song)); + } + + old_song_id = song_id; + + mpd_song_free(song); + +wait: + mpd_send_idle_mask(connection, MPD_IDLE_PLAYER); + while (!mpd_recv_idle(connection, 1)) + sleep(1); + } + +}