1 /*****************************************************************************
2 * loadsave.c : Playlist loading / saving functions
3 *****************************************************************************
4 * Copyright (C) 1999-2004 VLC authors and VideoLAN
7 * Authors: Samuel Hocevar <sam@zoy.org>
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU Lesser General Public License as published by
11 * the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with this program; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
28 #include <sys/types.h>
32 #include <vlc_common.h>
33 #include <vlc_playlist_legacy.h>
34 #include <vlc_events.h>
35 #include "playlist_internal.h"
36 #include "config/configuration.h"
39 #include <vlc_modules.h>
41 int playlist_Export( playlist_t
* p_playlist
, const char *psz_filename
,
42 const char *psz_type
)
44 playlist_export_t
*p_export
=
45 vlc_custom_create( p_playlist
, sizeof( *p_export
), "playlist export" );
46 if( unlikely(p_export
== NULL
) )
49 msg_Dbg( p_export
, "saving playlist to file %s", psz_filename
);
51 int ret
= VLC_EGENERIC
;
53 /* Prepare the playlist_export_t structure */
54 p_export
->base_url
= vlc_path2uri( psz_filename
, NULL
);
55 p_export
->p_file
= vlc_fopen( psz_filename
, "wt" );
56 if( p_export
->p_file
== NULL
)
58 msg_Err( p_export
, "could not create playlist file %s: %s",
59 psz_filename
, vlc_strerror_c(errno
) );
65 /* And call the module ! All work is done now */
66 playlist_Lock( p_playlist
);
67 p_export
->p_root
= p_playlist
->p_playing
;
69 p_module
= module_need( p_export
, "playlist export", psz_type
, true );
70 playlist_Unlock( p_playlist
);
72 if( p_module
!= NULL
)
74 module_unneed( p_export
, p_module
);
75 if( !ferror( p_export
->p_file
) )
78 msg_Err( p_playlist
, "could not write playlist file: %s",
79 vlc_strerror_c(errno
) );
82 msg_Err( p_playlist
, "could not export playlist" );
83 fclose( p_export
->p_file
);
85 free( p_export
->base_url
);
86 vlc_object_release( p_export
);
90 int playlist_Import( playlist_t
*p_playlist
, const char *psz_file
)
92 input_item_t
*p_input
;
93 char *psz_uri
= vlc_path2uri( psz_file
, NULL
);
98 p_input
= input_item_New( psz_uri
, psz_file
);
101 playlist_AddInput( p_playlist
, p_input
, false );
103 vlc_object_t
*dummy
= vlc_object_create( p_playlist
, sizeof (*dummy
) );
104 var_Create( dummy
, "meta-file", VLC_VAR_VOID
);
106 int ret
= input_Read( dummy
, p_input
, NULL
, NULL
);
108 vlc_object_release( dummy
);