]> git.sesse.net Git - vlc/blob - modules/demux/playlist/wpl.c
98e8ef3960f760ecdf62e3f094534f821bfee78d
[vlc] / modules / demux / playlist / wpl.c
1 /*****************************************************************************
2  * wpl.c : WPL playlist format import
3  *****************************************************************************
4  * Copyright (C) 2009 the VideoLAN team
5  *
6  * Authors: Su Heaven <suheaven@gmail.com>
7  *
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.
12  *
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.
17  *
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  *****************************************************************************/
22
23 /*****************************************************************************
24  * Preamble
25  *****************************************************************************/
26
27 #ifdef HAVE_CONFIG_H
28 # include "config.h"
29 #endif
30
31 #include <vlc_common.h>
32 #include <vlc_demux.h>
33 #include <vlc_charset.h>
34
35 #include "playlist.h"
36
37 struct demux_sys_t
38 {
39     char *psz_prefix;
40 };
41
42 /*****************************************************************************
43  * Local prototypes
44  *****************************************************************************/
45 static int Demux( demux_t *p_demux);
46 static int Control( demux_t *p_demux, int i_query, va_list args );
47
48 /*****************************************************************************
49  * Import_WPL: main import function
50  *****************************************************************************/
51 int Import_WPL( vlc_object_t *p_this )
52 {
53     demux_t *p_demux = (demux_t *)p_this;
54
55     if(! ( demux_IsPathExtension( p_demux, ".wpl" ) || demux_IsForced( p_demux,  "wpl" )))
56         return VLC_EGENERIC;
57
58     STANDARD_DEMUX_INIT_MSG( "found valid WPL playlist" );
59     p_demux->p_sys->psz_prefix = FindPrefix( p_demux );
60
61     return VLC_SUCCESS;
62 }
63
64
65
66 /*****************************************************************************
67  * Deactivate: frees unused data
68  *****************************************************************************/
69 void Close_WPL( vlc_object_t *p_this )
70 {
71     demux_t *p_demux = (demux_t *)p_this;
72     free( p_demux->p_sys->psz_prefix );
73     free( p_demux->p_sys );
74 }
75
76 static int Demux( demux_t *p_demux )
77 {
78     char       *psz_line;
79     input_item_t *p_current_input = GetCurrentItem(p_demux);
80
81     input_item_node_t *p_subitems = input_item_node_Create( p_current_input );
82
83     while( (psz_line = stream_ReadLine( p_demux->s )) )
84     {
85         char *psz_parse = psz_line;
86         /* Skip leading tabs and spaces */
87         while( *psz_parse == ' '  || *psz_parse == '\t' ||
88                *psz_parse == '\n' || *psz_parse == '\r' )
89             psz_parse++;
90
91         /* if the line is the uri of the media item */
92         if( !strncasecmp( psz_parse, "<media src=\"", strlen( "<media src=\"" ) ) )
93         {
94             char *psz_uri = psz_parse + strlen( "<media src=\"" );
95
96             psz_parse = strchr( psz_uri, '"' );
97             if( psz_parse != NULL )
98             {
99                 input_item_t *p_input;
100
101                 *psz_parse = '\0';
102                 psz_uri = ProcessMRL( psz_uri, p_demux->p_sys->psz_prefix );
103                 p_input = input_item_NewExt( p_demux, psz_uri, psz_uri,
104                                         0, NULL, 0, -1 );
105                 input_item_AddSubItem( p_current_input, p_input );
106                 input_item_node_AppendItem( p_subitems, p_input );
107                 vlc_gc_decref( p_input );
108             }
109         }
110
111         /* Fetch another line */
112         free( psz_line );
113
114     }
115
116     input_item_AddSubItemTree( p_subitems );
117     input_item_node_Delete( p_subitems );
118
119     vlc_gc_decref(p_current_input);
120     var_Destroy( p_demux, "wpl-extvlcopt" );
121     return 0; /* Needed for correct operation of go back */
122 }
123
124 static int Control( demux_t *p_demux, int i_query, va_list args )
125 {
126     VLC_UNUSED(p_demux); VLC_UNUSED(i_query); VLC_UNUSED(args);
127     return VLC_EGENERIC;
128 }