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., 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>
36 #include <vlc_playlist.h>
37 #include <vlc_strings.h>
39 /*****************************************************************************
40 * intf_sys_t: description and status of log interface
41 *****************************************************************************/
47 /*****************************************************************************
49 *****************************************************************************/
50 static int Open ( vlc_object_t * );
51 static void Close ( vlc_object_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_("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}).")
72 set_category( CAT_INTERFACE );
73 set_subcategory( SUBCAT_INTERFACE_CONTROL );
74 set_shortname( "MSN" );
75 set_description( N_("MSN Now-Playing") );
77 add_string( "msn-format", FORMAT_DEFAULT, NULL,
78 FORMAT_TEXT, FORMAT_LONGTEXT, 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 MALLOC_ERR( p_intf->p_sys, intf_sys_t );
94 p_intf->p_sys->psz_format = config_GetPsz( p_intf, "msn-format" );
95 if( !p_intf->p_sys->psz_format )
97 msg_Dbg( p_intf, "no format provided" );
98 p_intf->p_sys->psz_format = strdup( FORMAT_DEFAULT );
100 msg_Dbg( p_intf, "using format: %s", p_intf->p_sys->psz_format );
102 p_playlist = pl_Yield( 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 );
110 /*****************************************************************************
111 * Close: destroy interface stuff
112 *****************************************************************************/
113 static void Close( vlc_object_t *p_this )
115 intf_thread_t *p_intf = (intf_thread_t *)p_this;
116 playlist_t *p_playlist = pl_Yield( p_this );
118 /* clear the MSN stuff ... else it looks like we're still playing
119 * something although VLC (or the MSN plugin) is closed */
120 SendToMSN( "\\0Music\\01\\0\\0\\0\\0\\0\\0\\0" );
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 );
126 /* Destroy structure */
127 free( p_intf->p_sys->psz_format );
128 free( p_intf->p_sys );
131 /*****************************************************************************
132 * ItemChange: Playlist item change callback
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 )
137 intf_thread_t *p_intf = (intf_thread_t *)param;
138 char psz_tmp[MSN_MAX_LENGTH];
139 char *psz_title = NULL;
140 char *psz_artist = NULL;
141 char *psz_album = NULL;
142 char *psz_buf = NULL;
143 input_thread_t *p_input;
144 playlist_t *p_playlist = pl_Yield( p_this );
146 p_input = p_playlist->p_input;
147 pl_Release( p_this );
149 if( !p_input ) return VLC_SUCCESS;
150 vlc_object_yield( p_input );
152 if( p_input->b_dead || !input_GetItem(p_input)->psz_name )
154 /* Not playing anything ... */
155 SendToMSN( "\\0Music\\01\\0\\0\\0\\0\\0\\0\\0" );
156 vlc_object_release( p_input );
160 /* Playing something ... */
161 psz_artist = input_item_GetArtist( input_GetItem( p_input ) );
162 psz_album = input_item_GetAlbum( input_GetItem( p_input ) );
163 psz_title = input_item_GetTitle( input_GetItem( p_input ) );
164 if( !psz_artist ) psz_artist = strdup( "" );
165 if( !psz_album ) psz_artist = strdup( "" );
167 psz_title = input_item_GetName( input_GetItem( p_input ) );
169 psz_buf = str_format_meta( p_this, p_intf->p_sys->psz_format );
173 "\\0Music\\01\\0%s\\0%s\\0%s\\0%s\\0\\0\\0",
183 SendToMSN( psz_tmp );
184 vlc_object_release( p_input );
189 /*****************************************************************************
191 *****************************************************************************/
192 static int SendToMSN( char *psz_msg )
194 COPYDATASTRUCT msndata;
197 wchar_t buffer[MSN_MAX_LENGTH];
199 mbstowcs( buffer, psz_msg, MSN_MAX_LENGTH );
201 msndata.dwData = 0x547;
202 msndata.lpData = &buffer;
203 msndata.cbData = (lstrlenW(buffer)*2)+2;
205 while( ( msnui = FindWindowEx( NULL, msnui, "MsnMsgrUIManager", NULL ) ) )
207 SendMessage(msnui, WM_COPYDATA, (WPARAM)NULL, (LPARAM)&msndata);