-#include <stdlib.h> /* free(), strtol() */
-#include <stdio.h> /* sprintf() */
-#include <string.h> /* strerror() */
-#include <errno.h>
-
-#include <vlc/vlc.h>
-#include <vlc/vout.h>
-#include <vlc/sout.h>
-#include <vlc/input.h>
-
-#include "vlc_playlist.h"
-#include "charset.h"
-
-#define PLAYLIST_FILE_HEADER "# vlc playlist file version 0.5"
-
-/**
- * Import a playlist file at a given point of a given view
- * \param p_playlist the playlist to which the new items will be added
- * \param psz_filename the name of the playlistfile to import
- * \return VLC_SUCCESS on success
- */
-int playlist_Import( playlist_t * p_playlist, const char *psz_filename,
- playlist_item_t *p_root, vlc_bool_t b_only_there )
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_common.h>
+#include <vlc_playlist.h>
+#include <vlc_events.h>
+#include "playlist_internal.h"
+#include "config/configuration.h"
+#include <vlc_charset.h>
+#include <vlc_url.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+int playlist_Export( playlist_t * p_playlist, const char *psz_filename,
+ playlist_item_t *p_export_root, const char *psz_type )
+{
+ if( p_export_root == NULL ) return VLC_EGENERIC;
+
+ playlist_export_t *p_export =
+ vlc_custom_create( p_playlist, sizeof( *p_export ), VLC_OBJECT_GENERIC,
+ "playlist export" );
+ if( !p_export )
+ return VLC_ENOMEM;
+
+ vlc_object_attach( p_export, p_playlist );
+ msg_Dbg( p_export, "saving %s to file %s",
+ p_export_root->p_input->psz_name, psz_filename );
+
+ int ret = VLC_EGENERIC;
+
+ /* Prepare the playlist_export_t structure */
+ p_export->p_root = p_export_root;
+ p_export->psz_filename = psz_filename;
+ p_export->p_file = utf8_fopen( psz_filename, "wt" );
+ if( p_export->p_file == NULL )
+ msg_Err( p_export, "could not create playlist file %s (%m)",
+ psz_filename );
+ else
+ {
+ module_t *p_module;
+
+ /* And call the module ! All work is done now */
+ playlist_Lock( p_playlist );
+ p_module = module_need( p_export, "playlist export", psz_type, true );
+ playlist_Unlock( p_playlist );
+
+ if( p_module == NULL )
+ msg_Err( p_playlist, "could not export playlist" );
+ else
+ {
+ module_unneed( p_export, p_module );
+ ret = VLC_SUCCESS;
+ }
+ fclose( p_export->p_file );
+ }
+ vlc_object_release( p_export );
+ return ret;
+}
+
+int playlist_Import( playlist_t *p_playlist, const char *psz_file )