1 /*****************************************************************************
2 * old.c : Old playlist format import
3 *****************************************************************************
4 * Copyright (C) 2004 VideoLAN
7 * Authors: Clément Stenac <zorglub@videolan.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., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
27 #include <stdlib.h> /* malloc(), free() */
30 #include <vlc/input.h>
33 #include <errno.h> /* ENOMEM */
35 #define PLAYLIST_FILE_HEADER "# vlc playlist file version 0.5"
37 /*****************************************************************************
39 *****************************************************************************/
40 int Import_Old ( vlc_object_t * );
41 static int Demux( demux_t *p_demux);
42 static int Control( demux_t *p_demux, int i_query, va_list args );
44 /*****************************************************************************
45 * Import_Old : main import function
46 *****************************************************************************/
47 int Import_Old( vlc_object_t *p_this )
49 demux_t *p_demux = (demux_t *)p_this;
52 if( stream_Peek( p_demux->s, &p_peek, 31 ) < 31 ) return VLC_EGENERIC;
54 if( strncmp( p_peek, PLAYLIST_FILE_HEADER , 31 ) ) return VLC_EGENERIC;
56 msg_Dbg( p_demux, "found valid old playlist file");
58 p_demux->pf_control = Control;
59 p_demux->pf_demux = Demux;
64 static int Demux( demux_t *p_demux)
67 /* Attach playlist and start reading data */
68 playlist_t *p_playlist;
70 p_playlist = (playlist_t*)vlc_object_find( p_demux,
71 VLC_OBJECT_PLAYLIST, FIND_PARENT );
74 msg_Err( p_demux, "cannot attach playlist" );
78 p_playlist->pp_items[p_playlist->i_index]->b_autodeletion = VLC_TRUE;
79 while( ( psz_line = stream_ReadLine( p_demux->s) ) != NULL )
81 if( ( psz_line[0] == '#' ) || (psz_line[0] == '\r') ||
82 ( psz_line[0] == '\n') || (psz_line[0] == (char)0) )
86 /* Remove end of line */
87 if( psz_line[strlen(psz_line) -1 ] == '\n' ||
88 psz_line[strlen(psz_line) -1 ] == '\r' )
90 psz_line[ strlen(psz_line) -1 ] = (char)0;
91 if( psz_line[strlen(psz_line) - 1 ] == '\r' )
92 psz_line[strlen(psz_line) - 1 ] = (char)0;
94 playlist_Add( p_playlist, psz_line, psz_line, PLAYLIST_APPEND,
100 p_demux->b_die = VLC_TRUE;
101 vlc_object_release( p_playlist );
105 static int Control( demux_t *p_demux, int i_query, va_list args )