00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include <stdlib.h>
00024 #include <stdio.h>
00025 #include <string.h>
00026 #include <errno.h>
00027
00028 #include <vlc/vlc.h>
00029 #include <vlc/vout.h>
00030 #include <vlc/sout.h>
00031 #include <vlc/input.h>
00032
00033 #include "vlc_playlist.h"
00034
00035 #define PLAYLIST_FILE_HEADER "# vlc playlist file version 0.5"
00036
00046 int playlist_Import( playlist_t * p_playlist, const char *psz_filename )
00047 {
00048 playlist_item_t *p_item;
00049 char *psz_uri;
00050 int i_id;
00051
00052 msg_Info( p_playlist, "clearing playlist");
00053 playlist_Clear( p_playlist );
00054
00055
00056 psz_uri = (char *)malloc(sizeof(char)*strlen(psz_filename) + 17 );
00057 sprintf( psz_uri, "file/playlist://%s", psz_filename);
00058
00059 i_id = playlist_Add( p_playlist, psz_uri, psz_uri,
00060 PLAYLIST_INSERT , PLAYLIST_END);
00061
00062 vlc_mutex_lock( &p_playlist->object_lock );
00063 p_item = playlist_ItemGetById( p_playlist, i_id );
00064 p_item->b_autodeletion = VLC_TRUE;
00065 vlc_mutex_unlock( &p_playlist->object_lock );
00066
00067 playlist_Play(p_playlist);
00068
00069 return VLC_SUCCESS;
00070 }
00071
00080 int playlist_Load( playlist_t * p_playlist, const char *psz_filename )
00081 {
00082 playlist_item_t *p_item;
00083 char *psz_uri;
00084 int i_id;
00085
00086 msg_Info( p_playlist, "clearing playlist");
00087 playlist_Clear( p_playlist );
00088
00089
00090 psz_uri = (char *)malloc(sizeof(char)*strlen(psz_filename) + 17 );
00091 sprintf( psz_uri, "file/playlist://%s", psz_filename);
00092
00093 i_id = playlist_Add( p_playlist, psz_uri, psz_uri,
00094 PLAYLIST_INSERT , PLAYLIST_END);
00095
00096 vlc_mutex_lock( &p_playlist->object_lock );
00097 p_item = playlist_ItemGetById( p_playlist, i_id );
00098 p_item->b_autodeletion = VLC_TRUE;
00099 vlc_mutex_unlock( &p_playlist->object_lock );
00100
00101 playlist_Play(p_playlist);
00102
00103 return VLC_SUCCESS;
00104 }
00105
00114 int playlist_Export( playlist_t * p_playlist, const char *psz_filename ,
00115 const char *psz_type)
00116 {
00117 module_t *p_module;
00118 playlist_export_t *p_export;
00119
00120 msg_Info( p_playlist, "saving playlist to file %s", psz_filename );
00121
00122
00123 p_export = (playlist_export_t *)malloc( sizeof(playlist_export_t) );
00124 if( !p_export)
00125 {
00126 msg_Err( p_playlist, "out of memory");
00127 return VLC_ENOMEM;
00128 }
00129 p_export->p_file = fopen( psz_filename, "wt" );
00130 if( !p_export->p_file )
00131 {
00132 msg_Err( p_playlist , "could not create playlist file %s"
00133 " (%s)", psz_filename, strerror(errno) );
00134 return VLC_EGENERIC;
00135 }
00136
00137 p_playlist->p_private = (void *)p_export;
00138
00139 vlc_mutex_lock( &p_playlist->object_lock );
00140
00141
00142 p_module = module_Need( p_playlist, "playlist export", psz_type, VLC_TRUE);
00143 if( !p_module )
00144 {
00145 msg_Warn( p_playlist, "failed to export playlist" );
00146 vlc_mutex_unlock( &p_playlist->object_lock );
00147 return VLC_ENOOBJ;
00148 }
00149 module_Unneed( p_playlist , p_module );
00150
00151 fclose( p_export->p_file );
00152
00153 vlc_mutex_unlock( &p_playlist->object_lock );
00154
00155 return VLC_SUCCESS;
00156 }