1 /*****************************************************************************
2 * loadsave.c : Playlist loading / saving functions
3 *****************************************************************************
4 * Copyright (C) 1999-2004 the VideoLAN team
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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 #include <vlc_playlist.h>
25 #include "playlist_internal.h"
26 #include "modules/configuration.h"
27 #include <vlc_charset.h>
31 int playlist_Export( playlist_t * p_playlist, const char *psz_filename ,
32 playlist_item_t *p_export_root,const char *psz_type )
35 playlist_export_t *p_export;
37 if( p_export_root == NULL ) return VLC_EGENERIC;
39 msg_Info( p_playlist, "saving %s to file %s",
40 p_export_root->p_input->psz_name, psz_filename );
42 /* Prepare the playlist_export_t structure */
43 p_export = (playlist_export_t *)malloc( sizeof(playlist_export_t) );
46 msg_Err( p_playlist, "out of memory" );
49 p_export->psz_filename = NULL;
51 p_export->psz_filename = strdup( psz_filename );
52 p_export->p_file = utf8_fopen( psz_filename, "wt" );
53 if( !p_export->p_file )
55 msg_Err( p_playlist , "could not create playlist file %s"
56 " (%s)", psz_filename, strerror(errno) );
60 p_export->p_root = p_export_root;
62 /* Lock the playlist */
63 vlc_mutex_lock( &p_playlist->object_lock );
64 p_playlist->p_private = (void *)p_export;
66 /* And call the module ! All work is done now */
67 p_module = module_Need( p_playlist, "playlist export", psz_type, VLC_TRUE);
70 msg_Warn( p_playlist, "exporting playlist failed" );
71 vlc_mutex_unlock( &p_playlist->object_lock );
74 module_Unneed( p_playlist , p_module );
77 fclose( p_export->p_file );
78 if ( p_export->psz_filename )
79 free( p_export->psz_filename );
81 p_playlist->p_private = NULL;
82 vlc_mutex_unlock( &p_playlist->object_lock );
87 int playlist_MLLoad( playlist_t *p_playlist )
90 FIXME: this code breaks streaming output (or streaming output breaks this,
91 whichever you prefer).
93 const char *psz_homedir = p_playlist->p_libvlc->psz_homedir;
95 input_item_t *p_input;
97 if( !config_GetInt( p_playlist, "media-library") ) return VLC_SUCCESS;
100 msg_Err( p_playlist, "no home directory, cannot load media library") ;
104 if( asprintf( &psz_uri, "file/xspf-open://%s" DIR_SEP CONFIG_DIR DIR_SEP
105 "ml.xsp", psz_homedir ) == -1 )
111 p_input = input_ItemNewExt( p_playlist, psz_uri,
112 _("Media Library"), 0, NULL, -1 );
113 if( p_input == NULL )
116 p_playlist->p_ml_onelevel->p_input =
117 p_playlist->p_ml_category->p_input = p_input;
119 p_playlist->b_doing_ml = VLC_TRUE;
120 stats_TimerStart( p_playlist, "ML Load", STATS_TIMER_ML_LOAD );
121 input_Read( p_playlist, p_input, VLC_TRUE );
122 stats_TimerStop( p_playlist,STATS_TIMER_ML_LOAD );
123 p_playlist->b_doing_ml = VLC_FALSE;
132 msg_Err( p_playlist, "Reloading playlist not implemented." );
137 int playlist_MLDump( playlist_t *p_playlist )
139 char *psz_uri, *psz_homedir = p_playlist->p_libvlc->psz_homedir;
140 if( !config_GetInt( p_playlist, "media-library") ) return VLC_SUCCESS;
143 msg_Err( p_playlist, "no home directory, cannot save media library") ;
147 char psz_dirname[ strlen( psz_homedir ) + sizeof( DIR_SEP CONFIG_DIR ) ];
148 sprintf( psz_dirname, "%s" DIR_SEP CONFIG_DIR, psz_homedir );
149 if( config_CreateDir( (vlc_object_t *)p_playlist, psz_dirname ) )
154 asprintf( &psz_uri, "%s" DIR_SEP "%s", psz_dirname, "ml.xsp" );
155 stats_TimerStart( p_playlist, "ML Dump", STATS_TIMER_ML_DUMP );
156 playlist_Export( p_playlist, psz_uri, p_playlist->p_ml_category,
158 stats_TimerStop( p_playlist, STATS_TIMER_ML_DUMP );