+ char *psz_datadir;
+ char *psz_uri = NULL;
+ input_item_t *p_input;
+
+ if( !config_GetInt( p_playlist, "media-library") )
+ return VLC_SUCCESS;
+
+ psz_datadir = config_GetUserDir( VLC_DATA_DIR );
+
+ if( !psz_datadir ) /* XXX: This should never happen */
+ {
+ msg_Err( p_playlist, "no data directory, cannot load media library") ;
+ return VLC_EGENERIC;
+ }
+
+ if( asprintf( &psz_uri, "%s" DIR_SEP "ml.xspf", psz_datadir ) != -1 )
+ { /* loosy check for media library file */
+ struct stat st;
+ int ret = utf8_stat( psz_uri , &st );
+ free( psz_uri );
+ if( ret )
+ {
+ free( psz_datadir );
+ return VLC_EGENERIC;
+ }
+ }
+
+ psz_uri = make_URI( psz_datadir );
+ free( psz_datadir );
+ psz_datadir = psz_uri;
+ if( psz_datadir == NULL )
+ return VLC_EGENERIC;
+
+ /* Force XSPF demux (psz_datadir was a path, now it is a file URI) */
+ if( asprintf( &psz_uri, "file/xspf-open%s/ml.xspf", psz_datadir+4 ) == -1 )
+ psz_uri = NULL;
+ free( psz_datadir );
+ psz_datadir = NULL;
+ if( psz_uri == NULL )
+ return VLC_ENOMEM;
+
+ const char *const options[1] = { "meta-file", };
+ /* that option has to be cleaned in input_item_subitem_added() */
+ /* vlc_gc_decref() in the same function */
+ p_input = input_item_NewExt( p_playlist, psz_uri, _("Media Library"),
+ 1, options, VLC_INPUT_OPTION_TRUSTED, -1 );
+ free( psz_uri );
+ if( p_input == NULL )
+ return VLC_EGENERIC;