]> git.sesse.net Git - vlc/blob - src/playlist/loadsave.c
Reduce the global verbosity
[vlc] / src / playlist / loadsave.c
1 /*****************************************************************************
2  * loadsave.c : Playlist loading / saving functions
3  *****************************************************************************
4  * Copyright (C) 1999-2004 VideoLAN
5  * $Id$
6  *
7  * Authors: Samuel Hocevar <sam@zoy.org>
8  *
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.
13  *
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.
18  *
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() */
26 #include <errno.h>
27
28 #include <vlc/vlc.h>
29 #include <vlc/vout.h>
30 #include <vlc/sout.h>
31 #include <vlc/input.h>
32
33 #include "vlc_playlist.h"
34
35 #define PLAYLIST_FILE_HEADER  "# vlc playlist file version 0.5"
36
37 /**
38  * Import a certain playlist file into the library
39  * This file will get inserted as a new category
40  *
41  * XXX: TODO
42  * \param p_playlist the playlist to which the new items will be added
43  * \param psz_filename the name of the playlistfile to import
44  * \return VLC_SUCCESS on success
45  */
46 int playlist_Import( playlist_t * p_playlist, const char *psz_filename )
47 {
48     playlist_item_t *p_item;
49     char *psz_uri;
50     int i_id;
51
52     msg_Info( p_playlist, "clearing playlist");
53     playlist_Clear( p_playlist );
54
55
56     psz_uri = (char *)malloc(sizeof(char)*strlen(psz_filename) + 17 );
57     sprintf( psz_uri, "file/playlist://%s", psz_filename);
58
59     i_id = playlist_Add( p_playlist, psz_uri, psz_uri,
60                   PLAYLIST_INSERT  , PLAYLIST_END);
61
62     vlc_mutex_lock( &p_playlist->object_lock );
63     p_item = playlist_ItemGetById( p_playlist, i_id );
64     p_item->b_autodeletion = VLC_TRUE;
65     vlc_mutex_unlock( &p_playlist->object_lock );
66
67     playlist_Play(p_playlist);
68
69     return VLC_SUCCESS;
70 }
71
72 /**
73  * Load a certain playlist file into the playlist
74  * This file will replace the contents of the "current" view
75  *
76  * \param p_playlist the playlist to which the new items will be added
77  * \param psz_filename the name of the playlistfile to import
78  * \return VLC_SUCCESS on success
79  */
80 int playlist_Load( playlist_t * p_playlist, const char *psz_filename )
81 {
82     playlist_item_t *p_item;
83     char *psz_uri;
84     int i_id;
85
86     msg_Info( p_playlist, "clearing playlist");
87     playlist_Clear( p_playlist );
88
89
90     psz_uri = (char *)malloc(sizeof(char)*strlen(psz_filename) + 17 );
91     sprintf( psz_uri, "file/playlist://%s", psz_filename);
92
93     i_id = playlist_Add( p_playlist, psz_uri, psz_uri,
94                   PLAYLIST_INSERT  , PLAYLIST_END);
95
96     vlc_mutex_lock( &p_playlist->object_lock );
97     p_item = playlist_ItemGetById( p_playlist, i_id );
98     p_item->b_autodeletion = VLC_TRUE;
99     vlc_mutex_unlock( &p_playlist->object_lock );
100
101     playlist_Play(p_playlist);
102
103     return VLC_SUCCESS;
104 }
105
106 /**
107  * Export a playlist to a certain type of playlistfile
108  *
109  * \param p_playlist the playlist to export
110  * \param psz_filename the location where the exported file will be saved
111  * \param psz_type the type of playlist file to create.
112  * \return VLC_SUCCESS on success
113  */
114 int playlist_Export( playlist_t * p_playlist, const char *psz_filename ,
115                      const char *psz_type)
116 {
117     module_t *p_module;
118     playlist_export_t *p_export;
119
120     msg_Info( p_playlist, "saving playlist to file %s", psz_filename );
121
122     /* Prepare the playlist_export_t structure */
123     p_export = (playlist_export_t *)malloc( sizeof(playlist_export_t) );
124     if( !p_export)
125     {
126         msg_Err( p_playlist, "out of memory");
127         return VLC_ENOMEM;
128     }
129     p_export->p_file = fopen( psz_filename, "wt" );
130     if( !p_export->p_file )
131     {
132         msg_Err( p_playlist , "could not create playlist file %s"
133                  " (%s)", psz_filename, strerror(errno) );
134         return VLC_EGENERIC;
135     }
136
137     p_playlist->p_private = (void *)p_export;
138     /* Lock the playlist */
139     vlc_mutex_lock( &p_playlist->object_lock );
140
141     /* And call the module ! All work is done now */
142     p_module = module_Need( p_playlist, "playlist export", psz_type, VLC_TRUE);
143     if( !p_module )
144     {
145         msg_Warn( p_playlist, "failed to export playlist" );
146         vlc_mutex_unlock( &p_playlist->object_lock );
147         return VLC_ENOOBJ;
148     }
149     module_Unneed( p_playlist , p_module );
150
151     fclose( p_export->p_file );
152
153     vlc_mutex_unlock( &p_playlist->object_lock );
154
155     return VLC_SUCCESS;
156 }