1 /*****************************************************************************
2 * msn.c : msn title plugin
3 *****************************************************************************
4 * Copyright (C) 2005-2010 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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
32 #include <vlc_common.h>
33 #include <vlc_plugin.h>
34 #include <vlc_interface.h>
35 #include <vlc_playlist.h> /* playlist_t */
36 #include <vlc_charset.h> /* ToWide */
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 * );
52 static int ItemChange( vlc_object_t *, const char *,
53 vlc_value_t, vlc_value_t, void * );
54 static int SendToMSN( const char * psz_msg );
56 #define MSN_MAX_LENGTH 256
58 /*****************************************************************************
60 *****************************************************************************
61 * This module should be used on windows with MSN (i think that you need to
62 * have MSN 7 or newer) to "advertise" what you are playing in VLC.
63 * You need to enable the "What I'm Listening To" option in MSN.
64 *****************************************************************************/
65 #define FORMAT_DEFAULT "{0} - {1}"
66 #define FORMAT_TEXT N_("Title format string")
67 #define FORMAT_LONGTEXT N_("Format of the string to send to MSN " \
68 "{0} Artist, {1} Title, {2} Album. Defaults to \"Artist - Title\" ({0} - {1}).")
71 set_category( CAT_INTERFACE )
72 set_subcategory( SUBCAT_INTERFACE_CONTROL )
73 set_shortname( "MSN" )
74 set_description( N_("MSN Now-Playing") )
76 add_string( "msn-format", FORMAT_DEFAULT,
77 FORMAT_TEXT, FORMAT_LONGTEXT, false )
79 set_capability( "interface", 0 )
80 set_callbacks( Open, Close )
83 /*****************************************************************************
84 * Open: initialize and create stuff
85 *****************************************************************************/
86 static int Open( vlc_object_t *p_this )
88 intf_thread_t *p_intf = (intf_thread_t *)p_this;
89 playlist_t *p_playlist;
91 p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
95 p_intf->p_sys->psz_format = var_InheritString( p_intf, "msn-format" );
96 if( !p_intf->p_sys->psz_format )
97 p_intf->p_sys->psz_format = strdup( FORMAT_DEFAULT );
99 msg_Dbg( p_intf, "using MSN format: %s", p_intf->p_sys->psz_format );
101 p_playlist = pl_Get( p_intf );
102 var_AddCallback( p_playlist, "item-change", ItemChange, p_intf );
103 var_AddCallback( p_playlist, "item-current", ItemChange, p_intf );
108 /*****************************************************************************
109 * Close: destroy interface stuff
110 *****************************************************************************/
111 static void Close( vlc_object_t *p_this )
113 intf_thread_t *p_intf = (intf_thread_t *)p_this;
114 playlist_t *p_playlist = pl_Get( p_this );
116 /* clear the MSN stuff ... else it looks like we're still playing
117 * something although VLC (or the MSN plugin) is closed */
118 SendToMSN( "\\0Music\\01\\0\\0\\0\\0\\0\\0\\0" );
120 var_DelCallback( p_playlist, "item-change", ItemChange, p_intf );
121 var_DelCallback( p_playlist, "item-current", ItemChange, p_intf );
123 /* Destroy structure */
124 free( p_intf->p_sys->psz_format );
125 free( p_intf->p_sys );
128 /*****************************************************************************
129 * ItemChange: Playlist item change callback
130 *****************************************************************************/
131 static int ItemChange( vlc_object_t *p_this, const char *psz_var,
132 vlc_value_t oldval, vlc_value_t newval, void *param )
134 (void)psz_var; (void)oldval; (void)newval;
135 intf_thread_t *p_intf = (intf_thread_t *)param;
136 char psz_tmp[MSN_MAX_LENGTH];
137 input_thread_t *p_input = playlist_CurrentInput( (playlist_t *) p_this );
139 if( !p_input ) return VLC_SUCCESS;
141 if( p_input->b_dead || !input_GetItem(p_input)->psz_name )
143 /* Not playing anything ... */
144 SendToMSN( "\\0Music\\01\\0\\0\\0\\0\\0\\0\\0" );
145 vlc_object_release( p_input );
149 /* Playing something ... */
150 char *psz_artist = input_item_GetArtist( input_GetItem( p_input ) );
151 char *psz_album = input_item_GetAlbum( input_GetItem( p_input ) );
152 char *psz_title = input_item_GetTitleFbName( input_GetItem( p_input ) );
156 "\\0Music\\01\\0%s\\0%s\\0%s\\0%s\\0\\0\\0",
157 p_intf->p_sys->psz_format,
158 psz_artist ? psz_artist : "",
159 psz_title ? psz_title : "",
165 SendToMSN( (const char*)psz_tmp );
166 vlc_object_release( p_input );
171 /*****************************************************************************
173 *****************************************************************************/
174 static int SendToMSN( const char *psz_msg )
176 COPYDATASTRUCT msndata;
179 wchar_t *wmsg = ToWide( psz_msg );
180 if( unlikely(wmsg == NULL) )
183 msndata.dwData = 0x547;
184 msndata.lpData = wmsg;
185 msndata.cbData = (wcslen(wmsg) + 1) * 2;
187 while( ( msnui = FindWindowEx( NULL, msnui, "MsnMsgrUIManager", NULL ) ) )
189 SendMessage(msnui, WM_COPYDATA, (WPARAM)NULL, (LPARAM)&msndata);