2011-02-28 12:59:32 -05:00
/********************* Winamp Plugin 0.3******************************
*
* Distribution : GPL
*
* Originally written by : Leo - leo . nard @ free . fr
* Modified by : SilvereX - SilvereX @ karklas . mif . vu . lt
* Modified again by : Derek Buitenhuis - daemon404 @ gmail . com
* Modified yet again by : Berke Viktor - berkeviktor @ aol . com
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
# include "windows.h"
# include <stdio.h>
# include <stdlib.h>
# include <string.h>
2015-04-13 16:15:07 -04:00
# include <glib.h>
2011-02-28 12:59:32 -05:00
2012-10-24 15:33:02 -04:00
# include "hexchat-plugin.h"
2011-02-28 12:59:32 -05:00
# define PLAYING 1
# define PAUSED 3
2012-10-30 03:42:48 -04:00
static hexchat_plugin * ph ; /* plugin handle */
2011-02-28 12:59:32 -05:00
BOOL winamp_found = FALSE ;
int status = 0 ;
/* Slightly modified from X-Chat's log_escape_strcpy */
static char *
song_strcpy ( char * dest , char * src )
{
while ( * src )
{
* dest = * src ;
dest + + ;
src + + ;
if ( * src = = ' % ' )
{
dest [ 0 ] = ' % ' ;
dest + + ;
}
}
dest [ 0 ] = 0 ;
return dest - 1 ;
}
static int
winamp ( char * word [ ] , char * word_eol [ ] , void * userdata )
{
2015-04-13 16:15:07 -04:00
wchar_t wcurrent_play [ 2048 ] ;
char * current_play , * p ;
2011-02-28 12:59:32 -05:00
char p_esc [ 2048 ] ;
char cur_esc [ 2048 ] ;
char truc [ 2048 ] ;
2015-04-13 16:15:07 -04:00
HWND hwndWinamp = FindWindowW ( L " Winamp v1.x " , NULL ) ;
2011-02-28 12:59:32 -05:00
if ( hwndWinamp )
{
{
if ( ! stricmp ( " PAUSE " , word [ 2 ] ) )
{
if ( SendMessage ( hwndWinamp , WM_USER , 0 , 104 ) )
{
SendMessage ( hwndWinamp , WM_COMMAND , 40046 , 0 ) ;
if ( SendMessage ( hwndWinamp , WM_USER , 0 , 104 ) = = PLAYING )
2012-10-30 03:42:48 -04:00
hexchat_printf ( ph , " Winamp: playing " ) ;
2011-02-28 12:59:32 -05:00
else
2012-10-30 03:42:48 -04:00
hexchat_printf ( ph , " Winamp: paused " ) ;
2011-02-28 12:59:32 -05:00
}
}
else
if ( ! stricmp ( " STOP " , word [ 2 ] ) )
{
SendMessage ( hwndWinamp , WM_COMMAND , 40047 , 0 ) ;
2012-10-30 03:42:48 -04:00
hexchat_printf ( ph , " Winamp: stopped " ) ;
2011-02-28 12:59:32 -05:00
}
else
if ( ! stricmp ( " PLAY " , word [ 2 ] ) )
{
SendMessage ( hwndWinamp , WM_COMMAND , 40045 , 0 ) ;
2012-10-30 03:42:48 -04:00
hexchat_printf ( ph , " Winamp: playing " ) ;
2011-02-28 12:59:32 -05:00
}
else
if ( ! stricmp ( " NEXT " , word [ 2 ] ) )
{
SendMessage ( hwndWinamp , WM_COMMAND , 40048 , 0 ) ;
2012-10-30 03:42:48 -04:00
hexchat_printf ( ph , " Winamp: next playlist entry " ) ;
2011-02-28 12:59:32 -05:00
}
else
if ( ! stricmp ( " PREV " , word [ 2 ] ) )
{
SendMessage ( hwndWinamp , WM_COMMAND , 40044 , 0 ) ;
2012-10-30 03:42:48 -04:00
hexchat_printf ( ph , " Winamp: previous playlist entry " ) ;
2011-02-28 12:59:32 -05:00
}
else
if ( ! stricmp ( " START " , word [ 2 ] ) )
{
SendMessage ( hwndWinamp , WM_COMMAND , 40154 , 0 ) ;
2012-10-30 03:42:48 -04:00
hexchat_printf ( ph , " Winamp: playlist start " ) ;
2011-02-28 12:59:32 -05:00
}
else
if ( ! word_eol [ 2 ] [ 0 ] )
{
2015-04-13 16:15:07 -04:00
int len = GetWindowTextW ( hwndWinamp , wcurrent_play , sizeof ( wcurrent_play ) ) ;
current_play = g_utf16_to_utf8 ( wcurrent_play , len , NULL , NULL , NULL ) ;
if ( ! current_play )
{
hexchat_print ( ph , " Winamp: Error getting song information. " ) ;
return HEXCHAT_EAT_ALL ;
}
2011-02-28 12:59:32 -05:00
if ( strchr ( current_play , ' - ' ) )
{
p = current_play + strlen ( current_play ) - 8 ;
while ( p > = current_play )
{
if ( ! strnicmp ( p , " - Winamp " , 8 ) ) break ;
p - - ;
}
if ( p > = current_play ) p - - ;
while ( p > = current_play & & * p = = ' ' ) p - - ;
* + + p = 0 ;
p = strchr ( current_play , ' . ' ) + 1 ;
song_strcpy ( p_esc , p ) ;
song_strcpy ( cur_esc , current_play ) ;
if ( p )
{
sprintf ( truc , " me is now playing:%s " , p_esc ) ;
}
else
{
sprintf ( truc , " me is now playing:%s " , cur_esc ) ;
}
2012-10-30 03:42:48 -04:00
hexchat_commandf ( ph , truc ) ;
2015-04-13 16:15:07 -04:00
g_free ( current_play ) ;
2011-02-28 12:59:32 -05:00
}
2012-10-30 03:42:48 -04:00
else hexchat_print ( ph , " Winamp: Nothing being played. " ) ;
2011-02-28 12:59:32 -05:00
}
else
2012-10-30 03:42:48 -04:00
hexchat_printf ( ph , " Usage: /WINAMP [PAUSE|PLAY|STOP|NEXT|PREV|START] \n " ) ;
2011-02-28 12:59:32 -05:00
}
}
else
{
2012-10-30 03:42:48 -04:00
hexchat_print ( ph , " Winamp not found. \n " ) ;
2011-02-28 12:59:32 -05:00
}
2012-10-30 02:40:37 -04:00
return HEXCHAT_EAT_ALL ;
2011-02-28 12:59:32 -05:00
}
int
2012-10-30 03:42:48 -04:00
hexchat_plugin_init ( hexchat_plugin * plugin_handle ,
2011-02-28 12:59:32 -05:00
char * * plugin_name ,
char * * plugin_desc ,
char * * plugin_version ,
char * arg )
{
2012-10-30 06:47:12 -04:00
/* we need to save this for use with any hexchat_* functions */
2011-02-28 12:59:32 -05:00
ph = plugin_handle ;
* plugin_name = " Winamp " ;
2012-07-13 17:21:44 -04:00
* plugin_desc = " Winamp plugin for HexChat " ;
2015-04-13 16:15:07 -04:00
* plugin_version = " 0.6 " ;
2011-02-28 12:59:32 -05:00
2012-10-30 03:42:48 -04:00
hexchat_hook_command ( ph , " WINAMP " , HEXCHAT_PRI_NORM , winamp , " Usage: /WINAMP [PAUSE|PLAY|STOP|NEXT|PREV|START] - control Winamp or show what's currently playing " , 0 ) ;
2013-04-14 04:14:17 -04:00
hexchat_command ( ph , " MENU -ishare \\ music.png ADD \" Window/Display Current Song (Winamp) \" \" WINAMP \" " ) ;
2011-02-28 12:59:32 -05:00
2012-10-30 03:42:48 -04:00
hexchat_print ( ph , " Winamp plugin loaded \n " ) ;
2011-02-28 12:59:32 -05:00
return 1 ; /* return 1 for success */
}
int
2012-10-30 03:42:48 -04:00
hexchat_plugin_deinit ( void )
2011-02-28 12:59:32 -05:00
{
2012-10-30 03:42:48 -04:00
hexchat_command ( ph , " MENU DEL \" Window/Display Current Song (Winamp) \" " ) ;
hexchat_print ( ph , " Winamp plugin unloaded \n " ) ;
2011-02-28 12:59:32 -05:00
return 1 ;
}