1 /**********************************************************
3 # By Msdark (msdark@archilinux.us)
5 # Copyright (C) 2008 Matías Hernández
8 # Licensed under the GNU General Public License Version 3
10 **********************************************************/
12 #include "libmpdclient.h"
18 mpd_Connection
* conn
;
19 int reconectar(char *hostname
,char *port
){
20 printf("Desconectando....\n");
21 mpd_closeConnection(conn
);
23 printf("Reconectando...\n");
25 conn
= mpd_newConnection(hostname
,atoi(port
),10);
27 mpd_closeConnection(conn
);
30 printf("Conectado a MPD\n");
34 int conectar(char *hostname
,char *port
){
36 conn
= mpd_newConnection(hostname
,atoi(port
),10);
38 mpd_closeConnection(conn
);
46 char info
[500]="NULL",notify
[41]="/usr/bin/notify-send -t 2000 -u normal ";
47 char instruccion
[1000];
48 hostname
= getenv("MPD_HOST");
49 port
= getenv("MPD_PORT");
53 conectar(hostname
,port
);
55 mpd_sendCommandListOkBegin(conn
);
56 mpd_sendStatusCommand(conn
);
57 mpd_sendCurrentSongCommand(conn
);
58 mpd_sendCommandListEnd(conn
);
60 if((status
= mpd_getStatus(conn
))==NULL
){
61 mpd_finishCommand(conn
);
62 reconectar(hostname
,port
);
63 printf("\tMPD Stopped\n");
66 if(status
->state
==MPD_STATUS_STATE_PAUSE
){
67 printf("Esta pausado\n");
70 if(status
->state
!=MPD_STATUS_STATE_PLAY
){
71 printf("Esta detenido\n");
75 mpd_freeStatus(status
);
76 mpd_nextListOkCommand(conn
);
77 mpd_InfoEntity
*entity
;
78 entity
= mpd_getNextInfoEntity(conn
);
79 mpd_Song
*song
= entity
->info
.song
;
80 if(entity
->type
!=MPD_INFO_ENTITY_TYPE_SONG
){
81 mpd_freeInfoEntity(entity
);
84 if(song
->id
!= last_id
){
85 if(song
->artist
&& song
->title
){
87 strcat(info
,song
->artist
);
90 strcat(info
,"Album: ");
91 strcat(info
,song
->album
);
94 strcat(info
,"Tema: ");
95 strcat(info
,song
->title
);
97 strcpy(instruccion
,notify
);
98 strcat(instruccion
,info
);
102 strcpy(instruccion
,notify
);
103 strcat(instruccion
,"\"");
104 strcat(instruccion
,song
->file
);
105 strcat(instruccion
,"\"");
110 mpd_freeInfoEntity(entity
);
111 mpd_finishCommand(conn
);
114 mpd_closeConnection(conn
);