1 /*****************************************************************************
2 * loadsave.c : Playlist loading / saving functions
3 *****************************************************************************
4 * Copyright (C) 1999-2004 VideoLAN
5 * $Id: loadsave.c,v 1.4 2004/01/11 00:45:06 zorglub Exp $
7 * Authors: Samuel Hocevar <sam@zoy.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., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
23 #include <stdlib.h> /* free(), strtol() */
24 #include <stdio.h> /* sprintf() */
25 #include <string.h> /* strerror() */
31 #include "stream_control.h"
32 #include "input_ext-intf.h"
34 #include "vlc_playlist.h"
36 #define PLAYLIST_FILE_HEADER "# vlc playlist file version 0.5"
39 /*****************************************************************************
40 * playlist_Import: load a playlist file.
41 ****************************************************************************/
42 int playlist_Import( playlist_t * p_playlist, const char *psz_filename )
44 playlist_item_t *p_item;
48 msg_Dbg( p_playlist, "clearing playlist");
50 /* Create our "fake" playlist item */
51 playlist_Clear( p_playlist );
54 psz_uri = (char *)malloc(sizeof(char)*strlen(psz_filename) + 17 );
55 sprintf( psz_uri, "file/playlist://%s", psz_filename);
57 i_id = playlist_Add( p_playlist, psz_uri, psz_uri,
58 PLAYLIST_INSERT | PLAYLIST_GO , PLAYLIST_END);
60 p_item = playlist_GetItemById( p_playlist, i_id );
61 p_item->b_autodeletion = VLC_TRUE;
63 //p_playlist->i_index = 0;
68 p_playlist->p_input = input_CreateThread( p_playlist, p_item );
75 /*****************************************************************************
76 * playlist_SaveFile: Save a playlist in a file.
77 *****************************************************************************/
78 int playlist_Export( playlist_t * p_playlist, const char *psz_filename ,
83 playlist_export_t *p_export;
85 msg_Info( p_playlist, "Saving playlist to file %s", psz_filename );
87 /* Prepare the playlist_export_t structure */
88 p_export = (playlist_export_t *)malloc( sizeof(playlist_export_t) );
91 msg_Err( p_playlist, "Out of memory");
94 p_export->p_file = fopen( psz_filename, "wt" );
95 if( !p_export->p_file )
97 msg_Err( p_playlist , "Could not create playlist file %s (%s)"
98 , psz_filename, strerror(errno) );
102 p_playlist->p_private = (void *)p_export;
103 /* Lock the playlist */
104 vlc_mutex_lock( &p_playlist->object_lock );
106 /* And call the module ! All work is done now */
107 p_module = module_Need( p_playlist, "playlist export", psz_type);
110 msg_Warn( p_playlist, "Failed to export playlist" );
111 vlc_mutex_unlock( &p_playlist->object_lock );
114 module_Unneed( p_playlist , p_module );
116 fclose( p_export->p_file );
118 vlc_mutex_unlock( &p_playlist->object_lock );