00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include <stdlib.h>
00028
00029 #include <vlc/vlc.h>
00030 #include <vlc/input.h>
00031 #include <vlc/intf.h>
00032
00033 #include <errno.h>
00034
00035 #define PLAYLIST_FILE_HEADER "# vlc playlist file version 0.5"
00036
00037
00038
00039
00040 static int Demux( demux_t *p_demux);
00041 static int Control( demux_t *p_demux, int i_query, va_list args );
00042
00043
00044
00045
00046 int E_(Import_Old)( vlc_object_t *p_this )
00047 {
00048 demux_t *p_demux = (demux_t *)p_this;
00049 uint8_t *p_peek;
00050
00051 if( stream_Peek( p_demux->s, &p_peek, 31 ) < 31 ) return VLC_EGENERIC;
00052
00053 if( strncmp( (char *)p_peek, PLAYLIST_FILE_HEADER , 31 ) ) return VLC_EGENERIC;
00054
00055 msg_Dbg( p_demux, "found valid old playlist file");
00056
00057 p_demux->pf_control = Control;
00058 p_demux->pf_demux = Demux;
00059
00060 return VLC_SUCCESS;
00061 }
00062
00063 static int Demux( demux_t *p_demux)
00064 {
00065 char *psz_line;
00066
00067 playlist_t *p_playlist;
00068
00069 p_playlist = (playlist_t*)vlc_object_find( p_demux,
00070 VLC_OBJECT_PLAYLIST, FIND_PARENT );
00071 if( !p_playlist )
00072 {
00073 msg_Err( p_demux, "cannot attach playlist" );
00074 return VLC_EGENERIC;
00075 }
00076
00077 p_playlist->pp_items[p_playlist->i_index]->b_autodeletion = VLC_TRUE;
00078 while( ( psz_line = stream_ReadLine( p_demux->s) ) != NULL )
00079 {
00080 char *psz_unicode;
00081
00082 if( ( psz_line[0] == '#' ) || (psz_line[0] == '\r') ||
00083 ( psz_line[0] == '\n') || (psz_line[0] == (char)0) )
00084 {
00085 continue;
00086 }
00087
00088 if( psz_line[strlen(psz_line) -1 ] == '\n' ||
00089 psz_line[strlen(psz_line) -1 ] == '\r' )
00090 {
00091 psz_line[ strlen(psz_line) -1 ] = (char)0;
00092 if( psz_line[strlen(psz_line) - 1 ] == '\r' )
00093 psz_line[strlen(psz_line) - 1 ] = (char)0;
00094 }
00095
00096 psz_unicode = FromLocale( psz_line );
00097 playlist_Add( p_playlist, psz_unicode, psz_unicode, PLAYLIST_APPEND,
00098 PLAYLIST_END );
00099
00100 free( psz_line );
00101 LocaleFree( psz_line );
00102 }
00103
00104 p_demux->b_die = VLC_TRUE;
00105 vlc_object_release( p_playlist );
00106 return VLC_SUCCESS;
00107 }
00108
00109 static int Control( demux_t *p_demux, int i_query, va_list args )
00110 {
00111 return VLC_EGENERIC;
00112 }