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