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>
33 #include <vlc_charset.h>
42 /*****************************************************************************
44 *****************************************************************************/
45 static int Demux( demux_t *p_demux);
46 static int Control( demux_t *p_demux, int i_query, va_list args );
47 static char* ParseUriValue(char* psz_string);
49 /*****************************************************************************
50 * Import_WPL: main import function
51 *****************************************************************************/
52 int Import_WPL( vlc_object_t *p_this )
54 demux_t *p_demux = (demux_t *)p_this;
55 const uint8_t *p_peek;
56 CHECK_PEEK( p_peek, 8 );
58 if(! ( demux_IsPathExtension( p_demux, ".wpl" ) || demux_IsForced( p_demux, "wpl" )))
61 STANDARD_DEMUX_INIT_MSG( "found valid WPL playlist" );
62 p_demux->p_sys->psz_prefix = FindPrefix( p_demux );
69 /*****************************************************************************
70 * Deactivate: frees unused data
71 *****************************************************************************/
72 void Close_WPL( vlc_object_t *p_this )
74 demux_t *p_demux = (demux_t *)p_this;
75 free( p_demux->p_sys->psz_prefix );
76 free( p_demux->p_sys );
79 static inline void MaybeFromLocaleRep (char **str)
81 char *const orig_str = *str;
83 if ((orig_str != NULL) && !IsUTF8 (orig_str))
85 *str = FromLocaleDup (orig_str);
91 static int Demux( demux_t *p_demux )
96 input_item_t *p_input;
100 psz_line = stream_ReadLine( p_demux->s );
103 psz_parse = psz_line;
105 /* Skip leading tabs and spaces */
106 while( *psz_parse == ' ' || *psz_parse == '\t' ||
107 *psz_parse == '\n' || *psz_parse == '\r' ) psz_parse++;
109 if( !strncasecmp( psz_parse, "<media src=\"", sizeof( "<media src=\"" ) - 1 ) )/*if the line is uri of media item*/
112 psz_uri = ParseUriValue( psz_parse );
113 if( psz_uri && *psz_uri )
115 psz_uri = ProcessMRL( psz_uri, p_demux->p_sys->psz_prefix );
116 MaybeFromLocaleRep( &psz_uri );
117 p_input = input_item_NewExt( p_demux, psz_uri, psz_uri,
119 input_item_AddSubItem( p_current_input, p_input );
128 /* Fetch another line */
129 psz_line = stream_ReadLine( p_demux->s );
132 HANDLE_PLAY_AND_RELEASE;
133 var_Destroy( p_demux, "wpl-extvlcopt" );
134 return 0; /* Needed for correct operation of go back */
137 static int Control( demux_t *p_demux, int i_query, va_list args )
139 VLC_UNUSED(p_demux); VLC_UNUSED(i_query); VLC_UNUSED(args);
143 static char* ParseUriValue(char* psz_string)
145 int i_len = strlen( psz_string );
148 char* psz_value = (char *)malloc( i_len );
151 memset( psz_value, 0, i_len );
152 sscanf( psz_string,"%*[^=]=\"%[^\0\r\t\n\"]", psz_value );
154 if( strlen( psz_value ) )