1 /*****************************************************************************
2 * wpl.c : WPL playlist format import
3 *****************************************************************************
4 * Copyright (C) 2009 the VideoLAN team
6 * Authors: Su Heaven <suheaven@gmail.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
21 *****************************************************************************/
23 /*****************************************************************************
25 *****************************************************************************/
31 #include <vlc_common.h>
32 #include <vlc_demux.h>
41 /*****************************************************************************
43 *****************************************************************************/
44 static int Demux( demux_t *p_demux);
46 /*****************************************************************************
47 * Import_WPL: main import function
48 *****************************************************************************/
49 int Import_WPL( vlc_object_t *p_this )
51 demux_t *p_demux = (demux_t *)p_this;
53 if(! ( demux_IsPathExtension( p_demux, ".wpl" ) || demux_IsForced( p_demux, "wpl" )))
56 STANDARD_DEMUX_INIT_MSG( "found valid WPL playlist" );
57 p_demux->p_sys->psz_prefix = FindPrefix( p_demux );
64 /*****************************************************************************
65 * Deactivate: frees unused data
66 *****************************************************************************/
67 void Close_WPL( vlc_object_t *p_this )
69 demux_t *p_demux = (demux_t *)p_this;
70 free( p_demux->p_sys->psz_prefix );
71 free( p_demux->p_sys );
74 static int Demux( demux_t *p_demux )
77 input_item_t *p_current_input = GetCurrentItem(p_demux);
79 input_item_node_t *p_subitems = input_item_node_Create( p_current_input );
81 while( (psz_line = stream_ReadLine( p_demux->s )) )
83 char *psz_parse = psz_line;
84 /* Skip leading tabs and spaces */
85 while( *psz_parse == ' ' || *psz_parse == '\t' ||
86 *psz_parse == '\n' || *psz_parse == '\r' )
89 /* if the line is the uri of the media item */
90 if( !strncasecmp( psz_parse, "<media src=\"", strlen( "<media src=\"" ) ) )
92 char *psz_uri = psz_parse + strlen( "<media src=\"" );
94 psz_parse = strchr( psz_uri, '"' );
95 if( psz_parse != NULL )
97 input_item_t *p_input;
100 psz_uri = ProcessMRL( psz_uri, p_demux->p_sys->psz_prefix );
101 p_input = input_item_NewExt( psz_uri, psz_uri,
103 input_item_node_AppendItem( p_subitems, p_input );
104 vlc_gc_decref( p_input );
108 /* Fetch another line */
113 input_item_node_PostAndDelete( p_subitems );
115 vlc_gc_decref(p_current_input);
116 var_Destroy( p_demux, "wpl-extvlcopt" );
117 return 0; /* Needed for correct operation of go back */