1 /*****************************************************************************
2 * msn.c : msn title plugin
3 *****************************************************************************
4 * Copyright (C) 2005 the VideoLAN team
7 * Authors: Antoine Cellerier <dionoea -at- videolan -dot- org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
27 #include <stdlib.h> /* malloc(), free() */
30 #include <errno.h> /* ENOMEM */
38 /*****************************************************************************
39 * intf_sys_t: description and status of log interface
40 *****************************************************************************/
46 /*****************************************************************************
48 *****************************************************************************/
49 static int Open ( vlc_object_t * );
50 static void Close ( vlc_object_t * );
51 static void Run ( intf_thread_t * );
53 static int ItemChange( vlc_object_t *, const char *,
54 vlc_value_t, vlc_value_t, void * );
55 static int SendToMSN( char * psz_msg );
57 #define MSN_MAX_LENGTH 256
59 /*****************************************************************************
61 *****************************************************************************
62 * This module should be used on windows with MSN (i think that you need to
63 * have MSN 7 or newer) to "advertise" what you are playing in VLC.
64 * You need to enable the "What I'm Listening To" option in MSN.
65 *****************************************************************************/
66 #define FORMAT_DEFAULT "{0} - {1}"
67 #define FORMAT_TEXT N_("MSN Title format string")
68 #define FORMAT_LONGTEXT N_("MSN Title format string. " \
69 "{0} artist, {1} title, {2} album")
72 set_category( CAT_INTERFACE );
73 set_subcategory( SUBCAT_INTERFACE_CONTROL );
74 set_shortname( N_( "MSN" ) );
75 set_description( _("MSN Title Plugin") );
77 add_string( "msn-format", FORMAT_DEFAULT, NULL,
78 FORMAT_TEXT, FORMAT_LONGTEXT, VLC_FALSE );
80 set_capability( "interface", 0 );
81 set_callbacks( Open, Close );
84 /*****************************************************************************
85 * Open: initialize and create stuff
86 *****************************************************************************/
87 static int Open( vlc_object_t *p_this )
89 intf_thread_t *p_intf = (intf_thread_t *)p_this;
90 playlist_t *p_playlist;
92 /* Allocate instance and initialize some members */
93 p_intf->p_sys = (intf_sys_t *)malloc( sizeof( intf_sys_t ) );
94 if( p_intf->p_sys == NULL )
96 msg_Err( p_intf, "out of memory" );
100 p_playlist = (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
104 p_intf->p_sys->psz_format = config_GetPsz( p_intf, "msn-format" );
105 if( !p_intf->p_sys->psz_format )
107 msg_Dbg( p_intf, "no format provided" );
108 p_intf->p_sys->psz_format = strdup( FORMAT_DEFAULT );
110 msg_Dbg( p_intf, "using format: %s", p_intf->p_sys->psz_format );
114 msg_Err( p_intf, "could not find playlist object" );
115 free( p_intf->p_sys->psz_format );
116 free( p_intf->p_sys );
120 var_AddCallback( p_playlist, "item-change", ItemChange, p_intf );
121 vlc_object_release( p_playlist );
123 p_intf->pf_run = Run;
128 /*****************************************************************************
129 * Close: destroy interface stuff
130 *****************************************************************************/
131 static void Close( vlc_object_t *p_this )
133 intf_thread_t *p_intf = (intf_thread_t *)p_this;
135 /* clear the MSN stuff ... else it looks like we're still playing
136 * something although VLC (or the MSN plugin) is closed */
137 SendToMSN( "\\0Music\\01\\0\\0\\0\\0\\0\\0\\0" );
139 /* Destroy structure */
140 free( p_intf->p_sys->psz_format );
141 free( p_intf->p_sys );
144 /*****************************************************************************
146 *****************************************************************************/
147 static void Run( intf_thread_t *p_intf )
149 msleep( INTF_IDLE_SLEEP );
152 /*****************************************************************************
153 * ItemChange: Playlist item change callback
154 *****************************************************************************/
155 static int ItemChange( vlc_object_t *p_this, const char *psz_var,
156 vlc_value_t oldval, vlc_value_t newval, void *param )
158 intf_thread_t *p_intf = (intf_thread_t *)param;
160 char psz_tmp[MSN_MAX_LENGTH];
161 char *psz_title = NULL;
162 char *psz_artist = NULL;
163 char *psz_album = NULL;
167 if( !p_intf->p_sys ) return VLC_SUCCESS;
169 input_thread_t *p_input =
170 (input_thread_t *)vlc_object_find( p_this, VLC_OBJECT_INPUT,
172 if( !p_input || p_input->b_dead || !p_input->input.p_item->psz_name )
174 /* Not playing anything ... */
175 SendToMSN( "\\0Music\\01\\0\\0\\0\\0\\0\\0\\0" );
179 /* Playing something ... */
180 for( i = 0; i < p_input->input.p_item->i_categories; i++ )
182 info_category_t *p_cat = p_input->input.p_item->pp_categories[i];
183 for( j = 0; j < p_cat->i_infos; j++ )
185 info_t *p_info = p_cat->pp_infos[j];
187 if( !strcmp( p_info->psz_name, VLC_META_ARTIST ) )
189 psz_artist = strdup( p_info->psz_value );
191 else if( !strcmp( p_info->psz_name, "Album/movie/show title" ) )
193 psz_album = strdup( p_info->psz_value );
197 psz_title = strdup( p_input->input.p_item->psz_name );
198 if( psz_title == NULL ) psz_title = strdup( N_("(no title)") );
199 if( psz_artist == NULL ) psz_artist = strdup( N_("(no artist)") );
200 if( psz_album == NULL ) psz_album = strdup( N_("(no album)") );
203 "\\0Music\\01\\0%s\\0%s\\0%s\\0%s\\0\\0\\0",
204 p_intf->p_sys->psz_format,
213 SendToMSN( psz_tmp );
218 /*****************************************************************************
220 *****************************************************************************/
221 static int SendToMSN( char *psz_msg )
223 COPYDATASTRUCT msndata;
226 wchar_t buffer[MSN_MAX_LENGTH];
228 mbstowcs( buffer, psz_msg, MSN_MAX_LENGTH );
230 msndata.dwData = 0x547;
231 msndata.lpData = &buffer;
232 msndata.cbData = (lstrlenW(buffer)*2)+2;
234 while( ( msnui = FindWindowEx( NULL, msnui, "MsnMsgrUIManager", NULL ) ) )
236 SendMessage(msnui, WM_COPYDATA, (WPARAM)NULL, (LPARAM)&msndata);