]> git.sesse.net Git - vlc/blobdiff - modules/misc/msn.c
Merge back branch 0.8.6-playlist-vlm to trunk.
[vlc] / modules / misc / msn.c
index c1f803eb7bab176c16779fa7eac788923f238b52..9d4423964b4cf0533e41b3ff4f74fbd71e58a8e5 100644 (file)
@@ -60,15 +60,16 @@ static int SendToMSN( char * psz_msg );
  * You need to enable the "What I'm Listening To" option in MSN.
  *****************************************************************************/
 #define FORMAT_DEFAULT "{0} - {1}"
+/// \bug [String] MSN is useless
 #define FORMAT_TEXT N_("MSN Title format string")
-#define FORMAT_LONGTEXT N_("MSN Title format string. " \
-"{0} artist, {1} title, {2} album")
+#define FORMAT_LONGTEXT N_("Format of the string to send to MSN " \
+"{0} Artist, {1} Title, {2} Album. Defaults to \"Artist - Title\" ({0} - {1}).")
 
 vlc_module_begin();
     set_category( CAT_INTERFACE );
     set_subcategory( SUBCAT_INTERFACE_CONTROL );
     set_shortname( N_( "MSN" ) );
-    set_description( _("MSN Title Plugin") );
+    set_description( _("MSN Now-Playing") );
 
     add_string( "msn-format", FORMAT_DEFAULT, NULL,
                 FORMAT_TEXT, FORMAT_LONGTEXT, VLC_FALSE );
@@ -93,10 +94,6 @@ static int Open( vlc_object_t *p_this )
         return -1;
     }
 
-    p_playlist = (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
-                                                FIND_ANYWHERE );
-
-
     p_intf->p_sys->psz_format = config_GetPsz( p_intf, "msn-format" );
     if( !p_intf->p_sys->psz_format )
     {
@@ -105,20 +102,26 @@ static int Open( vlc_object_t *p_this )
     }
     msg_Dbg( p_intf, "using format: %s", p_intf->p_sys->psz_format );
 
+    p_playlist = (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
+                                                FIND_ANYWHERE );
+
     if( !p_playlist )
     {
         msg_Err( p_intf, "could not find playlist object" );
         free( p_intf->p_sys->psz_format );
         free( p_intf->p_sys );
-        return -1;
+        return VLC_ENOOBJ;
     }
 
+    /* Item's info changes */
     var_AddCallback( p_playlist, "item-change", ItemChange, p_intf );
+    /* We're playing a new item */
+    var_AddCallback( p_playlist, "playlist-current", ItemChange, p_intf );
     vlc_object_release( p_playlist );
 
     p_intf->pf_run = Run;
 
-    return 0;
+    return VLC_SUCCESS;
 }
 
 /*****************************************************************************
@@ -127,11 +130,20 @@ static int Open( vlc_object_t *p_this )
 static void Close( vlc_object_t *p_this )
 {
     intf_thread_t *p_intf = (intf_thread_t *)p_this;
+    playlist_t *p_playlist = (playlist_t *)vlc_object_find(
+                      p_this, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
 
     /* clear the MSN stuff ... else it looks like we're still playing
      * something although VLC (or the MSN plugin) is closed */
     SendToMSN( "\\0Music\\01\\0\\0\\0\\0\\0\\0\\0" );
 
+    if( p_playlist )
+    {
+        var_DelCallback( p_playlist, "item-change", ItemChange, p_intf );
+        var_DelCallback( p_playlist, "playlist-current", ItemChange, p_intf );
+    }
+
+
     /* Destroy structure */
     free( p_intf->p_sys->psz_format );
     free( p_intf->p_sys );
@@ -152,33 +164,40 @@ static int ItemChange( vlc_object_t *p_this, const char *psz_var,
                        vlc_value_t oldval, vlc_value_t newval, void *param )
 {
     intf_thread_t *p_intf = (intf_thread_t *)param;
-
+    playlist_t *p_playlist;
     char psz_tmp[MSN_MAX_LENGTH];
     char *psz_title = NULL;
     char *psz_artist = NULL;
     char *psz_album = NULL;
-
-    int i,j;
+    input_thread_t *p_input;
 
     if( !p_intf->p_sys ) return VLC_SUCCESS;
 
-    input_thread_t *p_input =
-        (input_thread_t *)vlc_object_find( p_this, VLC_OBJECT_INPUT,
-                                           FIND_ANYWHERE );
-    if( !p_input || p_input->b_dead || !p_input->input.p_item->psz_name )
+    p_playlist = (playlist_t *)vlc_object_find( p_this, VLC_OBJECT_PLAYLIST,
+                                                 FIND_ANYWHERE );
+
+    if( !p_playlist ) return VLC_EGENERIC;
+
+    p_input = p_playlist->p_input;
+    vlc_object_release( p_playlist );
+    if( !p_input ) return VLC_SUCCESS;
+    vlc_object_yield( p_input );
+
+    if( p_input->b_dead || !p_input->input.p_item->psz_name )
     {
         /* Not playing anything ... */
         SendToMSN( "\\0Music\\01\\0\\0\\0\\0\\0\\0\\0" );
+        vlc_object_release( p_input );
         return VLC_SUCCESS;
     }
 
     /* Playing something ... */
-    psz_artist = vlc_input_item_GetInfo( p_input->input.p_item,
-                                         _("Meta-information"),
-                                         VLC_META_ARTIST);
-    psz_album = vlc_input_item_GetInfo( p_input->input.p_item,
-                                         _("Meta-information"),
-                                         _("Album/movie/show title" ) );
+    psz_artist = p_input->input.p_item->p_meta->psz_artist ?
+                  strdup( p_input->input.p_item->p_meta->psz_artist ) :
+                  strdup( "" );
+    psz_album = p_input->input.p_item->p_meta->psz_album ?
+                  strdup( p_input->input.p_item->p_meta->psz_album ) :
+                  strdup( "" );
     psz_title = strdup( p_input->input.p_item->psz_name );
     if( psz_title == NULL ) psz_title = strdup( N_("(no title)") );
     if( psz_artist == NULL ) psz_artist = strdup( N_("(no artist)") );
@@ -187,7 +206,6 @@ static int ItemChange( vlc_object_t *p_this, const char *psz_var,
               MSN_MAX_LENGTH,
               "\\0Music\\01\\0%s\\0%s\\0%s\\0%s\\0\\0\\0",
               p_intf->p_sys->psz_format,
-              //FORMAT_DEFAULT,
               psz_title,
               psz_artist,
               psz_album );