]> git.sesse.net Git - vlc/blob - src/playlist/loadsave.c
* src/playlist/loadsave.c: errno.h related fixes.
[vlc] / src / playlist / loadsave.c
1 /*****************************************************************************
2  * loadsave.c : Playlist loading / saving functions
3  *****************************************************************************
4  * Copyright (C) 1999-2004 VideoLAN
5  * $Id: loadsave.c,v 1.6 2004/01/22 19:35:14 gbazin Exp $
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
27 #include <vlc/vlc.h>
28 #include <vlc/vout.h>
29 #include <vlc/sout.h>
30
31 #ifdef HAVE_ERRNO_H
32 #   include <errno.h>
33 #endif
34
35 #include "stream_control.h"
36 #include "input_ext-intf.h"
37
38 #include "vlc_playlist.h"
39
40 #define PLAYLIST_FILE_HEADER  "# vlc playlist file version 0.5"
41
42
43 /**
44  * Import a playlist file
45  *
46  * Import a certain playlist file into the playlist
47  * \param p_playlist the playlist to which the new items will be added
48  * \param psz_filename the name of the playlistfile to import
49  * \return 0 on succes
50  */
51 int playlist_Import( playlist_t * p_playlist, const char *psz_filename )
52 {
53     playlist_item_t *p_item;
54     char *psz_uri;
55     int i_id;
56
57     msg_Dbg( p_playlist, "clearing playlist");
58
59     /* Create our "fake" playlist item */
60     playlist_Clear( p_playlist );
61
62
63     psz_uri = (char *)malloc(sizeof(char)*strlen(psz_filename) + 17 );
64     sprintf( psz_uri, "file/playlist://%s", psz_filename);
65
66     i_id = playlist_Add( p_playlist, psz_uri, psz_uri,
67                   PLAYLIST_INSERT | PLAYLIST_GO , PLAYLIST_END);
68
69     p_item = playlist_GetItemById( p_playlist, i_id );
70     p_item->b_autodeletion = VLC_TRUE;
71
72     //p_playlist->i_index = 0;
73
74 /*
75  *     if( p_item )
76     {
77         p_playlist->p_input = input_CreateThread( p_playlist, p_item );
78     }
79     */
80
81     return VLC_SUCCESS;
82 }
83
84 /**
85  * Export a playlist to a file
86  *
87  * Export a playlist to a certain type of playlistfile
88  * \param p_playlist the playlist to export
89  * \param psz_filename the location where the exported file will be saved
90  * \param psz_type the type of playlist file to create.
91  * \return 0 on succes
92  */
93 int playlist_Export( playlist_t * p_playlist, const char *psz_filename ,
94                      const char *psz_type)
95 {
96     module_t *p_module;
97     playlist_export_t *p_export;
98
99     msg_Info( p_playlist, "Saving playlist to file %s", psz_filename );
100
101     /* Prepare the playlist_export_t structure */
102     p_export = (playlist_export_t *)malloc( sizeof(playlist_export_t) );
103     if( !p_export)
104     {
105         msg_Err( p_playlist, "Out of memory");
106         return VLC_ENOMEM;
107     }
108     p_export->p_file = fopen( psz_filename, "wt" );
109     if( !p_export->p_file )
110     {
111         msg_Err( p_playlist , "Could not create playlist file %s"
112 #ifdef HAVE_ERRNO_H
113                  " (%s)", psz_filename, strerror(errno) );
114 #else
115                  , psz_filename );
116 #endif
117         return VLC_EGENERIC;
118     }
119
120     p_playlist->p_private = (void *)p_export;
121     /* Lock the playlist */
122     vlc_mutex_lock( &p_playlist->object_lock );
123
124     /* And call the module ! All work is done now */
125     p_module = module_Need( p_playlist, "playlist export",  psz_type);
126     if( !p_module )
127     {
128         msg_Warn( p_playlist, "Failed to export playlist" );
129         vlc_mutex_unlock( &p_playlist->object_lock );
130         return VLC_ENOOBJ;
131     }
132     module_Unneed( p_playlist , p_module );
133
134     fclose( p_export->p_file );
135
136     vlc_mutex_unlock( &p_playlist->object_lock );
137
138     return VLC_SUCCESS;
139 }