Fonctionne @ home mais trop spécifique, il faut ajouter des fonctions

master
Philippe Pittoli 2011-10-27 01:18:54 +02:00
parent 0c8c6ee3ee
commit f6a280e1bb
1 changed files with 15 additions and 9 deletions

View File

@ -4,6 +4,7 @@
#include <string.h> #include <string.h>
#include <weechat/weechat-plugin.h> #include <weechat/weechat-plugin.h>
#define TAILLE_BUFFER_CURRENT_SONG 100
WEECHAT_PLUGIN_NAME("currentsong"); WEECHAT_PLUGIN_NAME("currentsong");
WEECHAT_PLUGIN_DESCRIPTION("Affiche la musique en cours en utilisant mpc"); WEECHAT_PLUGIN_DESCRIPTION("Affiche la musique en cours en utilisant mpc");
WEECHAT_PLUGIN_AUTHOR("Karchnu <kane.root@gmail.com>"); WEECHAT_PLUGIN_AUTHOR("Karchnu <kane.root@gmail.com>");
@ -22,10 +23,17 @@ int cb_currentsong_plugin(void *data, struct t_gui_buffer *buffer, int argc, cha
int p[2]; int p[2];
//char local_buffer[100]; //char local_buffer[100];
char * song; char * song;
char * cmd[] = { "mpc", "-h" , "192.168.0.100",(char *)0 }; char affichage[TAILLE_BUFFER_CURRENT_SONG + 10];
song = malloc(200*sizeof(char)); int i;
char * cmd[] = { "mpc", "-h" , "192.168.0.100","current", (char *)0 };
song = malloc(TAILLE_BUFFER_CURRENT_SONG*sizeof(char));
if(song == NULL) return WEECHAT_RC_ERROR; if(song == NULL) return WEECHAT_RC_ERROR;
for(i = 0 ; i < TAILLE_BUFFER_CURRENT_SONG ; i++)
song[i] = '\0';
for(i = 0 ; i < TAILLE_BUFFER_CURRENT_SONG + 10 ; i++)
affichage[i] = '\0';
pipe(p); pipe(p);
if(fork() == 0) if(fork() == 0)
{ {
@ -34,15 +42,13 @@ int cb_currentsong_plugin(void *data, struct t_gui_buffer *buffer, int argc, cha
dup2(p[1],1); dup2(p[1],1);
execvp("mpc", cmd); execvp("mpc", cmd);
} }
close(p[1]); close(p[1]);
read(p[0], song, 200); read(p[0], song, TAILLE_BUFFER_CURRENT_SONG);
close(p[0]); close(p[0]);
sprintf(affichage,"/me ♪ %s", song);
if(buffer) //sprintf(affichage,"/me ♪ %s%s", weechat_color ("_red"), song); // Ne s'affiche pas correctement chez les autres
weechat_printf (buffer, "J'écoute : %s %s", weechat_utf8_normalize(affichage, '?'); // Pour ne pas avoir de caractères non-lisibles
weechat_color ("yellow,red"), weechat_command(buffer,affichage);
song);
free(song); free(song);
return WEECHAT_RC_OK; return WEECHAT_RC_OK;