| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
#ifdef HAVE_CONFIG_H |
|---|
| 29 |
# include "config.h" |
|---|
| 30 |
#endif |
|---|
| 31 |
|
|---|
| 32 |
#include <vlc_common.h> |
|---|
| 33 |
#include <vlc_plugin.h> |
|---|
| 34 |
#include <vlc_interface.h> |
|---|
| 35 |
#include <vlc_meta.h> |
|---|
| 36 |
#include <vlc_playlist.h> |
|---|
| 37 |
#include <vlc_strings.h> |
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 |
|
|---|
| 41 |
|
|---|
| 42 |
struct intf_sys_t |
|---|
| 43 |
{ |
|---|
| 44 |
char *psz_format; |
|---|
| 45 |
}; |
|---|
| 46 |
|
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 |
|
|---|
| 50 |
static int Open ( vlc_object_t * ); |
|---|
| 51 |
static void Close ( vlc_object_t * ); |
|---|
| 52 |
|
|---|
| 53 |
static int ItemChange( vlc_object_t *, const char *, |
|---|
| 54 |
vlc_value_t, vlc_value_t, void * ); |
|---|
| 55 |
static int SendToMSN( const char * psz_msg ); |
|---|
| 56 |
|
|---|
| 57 |
#define MSN_MAX_LENGTH 256 |
|---|
| 58 |
|
|---|
| 59 |
|
|---|
| 60 |
|
|---|
| 61 |
|
|---|
| 62 |
|
|---|
| 63 |
|
|---|
| 64 |
|
|---|
| 65 |
|
|---|
| 66 |
#define FORMAT_DEFAULT "{0} - {1}" |
|---|
| 67 |
#define FORMAT_TEXT N_("Title format string") |
|---|
| 68 |
#define FORMAT_LONGTEXT N_("Format of the string to send to MSN " \ |
|---|
| 69 |
"{0} Artist, {1} Title, {2} Album. Defaults to \"Artist - Title\" ({0} - {1}).") |
|---|
| 70 |
|
|---|
| 71 |
vlc_module_begin(); |
|---|
| 72 |
set_category( CAT_INTERFACE ); |
|---|
| 73 |
set_subcategory( SUBCAT_INTERFACE_CONTROL ); |
|---|
| 74 |
set_shortname( "MSN" ); |
|---|
| 75 |
set_description( N_("MSN Now-Playing") ); |
|---|
| 76 |
|
|---|
| 77 |
add_string( "msn-format", FORMAT_DEFAULT, NULL, |
|---|
| 78 |
FORMAT_TEXT, FORMAT_LONGTEXT, false ); |
|---|
| 79 |
|
|---|
| 80 |
set_capability( "interface", 0 ); |
|---|
| 81 |
set_callbacks( Open, Close ); |
|---|
| 82 |
vlc_module_end(); |
|---|
| 83 |
|
|---|
| 84 |
|
|---|
| 85 |
|
|---|
| 86 |
|
|---|
| 87 |
static int Open( vlc_object_t *p_this ) |
|---|
| 88 |
{ |
|---|
| 89 |
intf_thread_t *p_intf = (intf_thread_t *)p_this; |
|---|
| 90 |
playlist_t *p_playlist; |
|---|
| 91 |
|
|---|
| 92 |
MALLOC_ERR( p_intf->p_sys, intf_sys_t ); |
|---|
| 93 |
|
|---|
| 94 |
p_intf->p_sys->psz_format = config_GetPsz( p_intf, "msn-format" ); |
|---|
| 95 |
if( !p_intf->p_sys->psz_format ) |
|---|
| 96 |
{ |
|---|
| 97 |
msg_Dbg( p_intf, "no format provided" ); |
|---|
| 98 |
p_intf->p_sys->psz_format = strdup( FORMAT_DEFAULT ); |
|---|
| 99 |
} |
|---|
| 100 |
msg_Dbg( p_intf, "using format: %s", p_intf->p_sys->psz_format ); |
|---|
| 101 |
|
|---|
| 102 |
p_playlist = pl_Hold( p_intf ); |
|---|
| 103 |
var_AddCallback( p_playlist, "item-change", ItemChange, p_intf ); |
|---|
| 104 |
var_AddCallback( p_playlist, "playlist-current", ItemChange, p_intf ); |
|---|
| 105 |
pl_Release( p_intf ); |
|---|
| 106 |
|
|---|
| 107 |
return VLC_SUCCESS; |
|---|
| 108 |
} |
|---|
| 109 |
|
|---|
| 110 |
|
|---|
| 111 |
|
|---|
| 112 |
|
|---|
| 113 |
static void Close( vlc_object_t *p_this ) |
|---|
| 114 |
{ |
|---|
| 115 |
intf_thread_t *p_intf = (intf_thread_t *)p_this; |
|---|
| 116 |
playlist_t *p_playlist = pl_Hold( p_this ); |
|---|
| 117 |
|
|---|
| 118 |
|
|---|
| 119 |
|
|---|
| 120 |
SendToMSN( "\\0Music\\01\\0\\0\\0\\0\\0\\0\\0" ); |
|---|
| 121 |
|
|---|
| 122 |
var_DelCallback( p_playlist, "item-change", ItemChange, p_intf ); |
|---|
| 123 |
var_DelCallback( p_playlist, "playlist-current", ItemChange, p_intf ); |
|---|
| 124 |
pl_Release( p_this ); |
|---|
| 125 |
|
|---|
| 126 |
|
|---|
| 127 |
free( p_intf->p_sys->psz_format ); |
|---|
| 128 |
free( p_intf->p_sys ); |
|---|
| 129 |
} |
|---|
| 130 |
|
|---|
| 131 |
|
|---|
| 132 |
|
|---|
| 133 |
|
|---|
| 134 |
static int ItemChange( vlc_object_t *p_this, const char *psz_var, |
|---|
| 135 |
vlc_value_t oldval, vlc_value_t newval, void *param ) |
|---|
| 136 |
{ |
|---|
| 137 |
(void)psz_var; (void)oldval; (void)newval; |
|---|
| 138 |
intf_thread_t *p_intf = (intf_thread_t *)param; |
|---|
| 139 |
char psz_tmp[MSN_MAX_LENGTH]; |
|---|
| 140 |
char *psz_title = NULL; |
|---|
| 141 |
char *psz_artist = NULL; |
|---|
| 142 |
char *psz_album = NULL; |
|---|
| 143 |
char *psz_buf = NULL; |
|---|
| 144 |
input_thread_t *p_input; |
|---|
| 145 |
playlist_t *p_playlist = pl_Hold( p_this ); |
|---|
| 146 |
|
|---|
| 147 |
p_input = p_playlist->p_input; |
|---|
| 148 |
pl_Release( p_this ); |
|---|
| 149 |
|
|---|
| 150 |
if( !p_input ) return VLC_SUCCESS; |
|---|
| 151 |
vlc_object_hold( p_input ); |
|---|
| 152 |
|
|---|
| 153 |
if( p_input->b_dead || !input_GetItem(p_input)->psz_name ) |
|---|
| 154 |
{ |
|---|
| 155 |
|
|---|
| 156 |
SendToMSN( "\\0Music\\01\\0\\0\\0\\0\\0\\0\\0" ); |
|---|
| 157 |
vlc_object_release( p_input ); |
|---|
| 158 |
return VLC_SUCCESS; |
|---|
| 159 |
} |
|---|
| 160 |
|
|---|
| 161 |
|
|---|
| 162 |
psz_artist = input_item_GetArtist( input_GetItem( p_input ) ); |
|---|
| 163 |
psz_album = input_item_GetAlbum( input_GetItem( p_input ) ); |
|---|
| 164 |
psz_title = input_item_GetTitle( input_GetItem( p_input ) ); |
|---|
| 165 |
if( !psz_artist ) psz_artist = strdup( "" ); |
|---|
| 166 |
if( !psz_album ) psz_artist = strdup( "" ); |
|---|
| 167 |
if( !psz_title ) |
|---|
| 168 |
psz_title = input_item_GetName( input_GetItem( p_input ) ); |
|---|
| 169 |
|
|---|
| 170 |
psz_buf = str_format_meta( p_this, p_intf->p_sys->psz_format ); |
|---|
| 171 |
|
|---|
| 172 |
snprintf( psz_tmp, |
|---|
| 173 |
MSN_MAX_LENGTH, |
|---|
| 174 |
"\\0Music\\01\\0%s\\0%s\\0%s\\0%s\\0\\0\\0", |
|---|
| 175 |
psz_buf, |
|---|
| 176 |
psz_artist, |
|---|
| 177 |
psz_title, |
|---|
| 178 |
psz_album ); |
|---|
| 179 |
free( psz_buf ); |
|---|
| 180 |
free( psz_title ); |
|---|
| 181 |
free( psz_artist ); |
|---|
| 182 |
free( psz_album ); |
|---|
| 183 |
|
|---|
| 184 |
SendToMSN( (const char*)psz_tmp ); |
|---|
| 185 |
vlc_object_release( p_input ); |
|---|
| 186 |
|
|---|
| 187 |
return VLC_SUCCESS; |
|---|
| 188 |
} |
|---|
| 189 |
|
|---|
| 190 |
|
|---|
| 191 |
|
|---|
| 192 |
|
|---|
| 193 |
static int SendToMSN( const char *psz_msg ) |
|---|
| 194 |
{ |
|---|
| 195 |
COPYDATASTRUCT msndata; |
|---|
| 196 |
HWND msnui = NULL; |
|---|
| 197 |
|
|---|
| 198 |
wchar_t buffer[MSN_MAX_LENGTH]; |
|---|
| 199 |
|
|---|
| 200 |
mbstowcs( buffer, psz_msg, MSN_MAX_LENGTH ); |
|---|
| 201 |
|
|---|
| 202 |
msndata.dwData = 0x547; |
|---|
| 203 |
msndata.lpData = &buffer; |
|---|
| 204 |
msndata.cbData = (lstrlenW(buffer)*2)+2; |
|---|
| 205 |
|
|---|
| 206 |
while( ( msnui = FindWindowEx( NULL, msnui, "MsnMsgrUIManager", NULL ) ) ) |
|---|
| 207 |
{ |
|---|
| 208 |
SendMessage(msnui, WM_COPYDATA, (WPARAM)NULL, (LPARAM)&msndata); |
|---|
| 209 |
} |
|---|
| 210 |
|
|---|
| 211 |
return VLC_SUCCESS; |
|---|
| 212 |
} |
|---|