]> git.sesse.net Git - vlc/blob - modules/demux/playlist/playlist.c
One more removing session. (useless test before a free())
[vlc] / modules / demux / playlist / playlist.c
1 /*****************************************************************************
2  * playlist.c :  Playlist import module
3  *****************************************************************************
4  * Copyright (C) 2004 the VideoLAN team
5  * $Id$
6  *
7  * Authors: ClĂ©ment Stenac <zorglub@videolan.org>
8  *
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.
13  *
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.
18  *
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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #ifdef HAVE_CONFIG_H
28 # include "config.h"
29 #endif
30
31 #include <vlc/vlc.h>
32 #include <vlc_demux.h>
33 #include <vlc_playlist.h>
34
35 #include "playlist.h"
36
37 /*****************************************************************************
38  * Module descriptor
39  *****************************************************************************/
40 #define AUTOSTART_TEXT N_( "Auto start" )
41 #define AUTOSTART_LONGTEXT N_( "Automatically start playing the playlist " \
42                 "content once it's loaded." )
43
44 #define SHOW_ADULT_TEXT N_( "Show shoutcast adult content" )
45 #define SHOW_ADULT_LONGTEXT N_( "Show NC17 rated video streams when " \
46                 "using shoutcast video playlists." )
47
48 #define SKIP_ADS_TEXT N_( "Skip ads" )
49 #define SKIP_ADS_LONGTEXT N_( "Use playlist options usually used to prevent " \
50     "ads skipping to detect ads and prevent adding them to the playlist." )
51
52 #define EXTVLCOPT_TEXT N_( "Enable parsing of EXTVLCOPT: options" )
53 #define EXTVLCOPT_LONGTEXT N_( "Enable parsing of EXTVLCOPT: options in m3u " \
54     "playlists. This option is default disabled to prevent untrusted sources " \
55     "using VLC options without the user's knowledge." )
56
57 vlc_module_begin();
58     add_shortcut( "playlist" );
59     set_category( CAT_INPUT );
60     set_subcategory( SUBCAT_INPUT_DEMUX );
61
62     add_bool( "playlist-autostart", 1, NULL,
63               AUTOSTART_TEXT, AUTOSTART_LONGTEXT, VLC_FALSE );
64
65     add_integer( "parent-item", 0, NULL, NULL, NULL, VLC_TRUE );
66         change_internal();
67
68     add_bool( "playlist-skip-ads", 1, NULL,
69               SKIP_ADS_TEXT, SKIP_ADS_LONGTEXT, VLC_FALSE );
70
71     set_shortname( _("Playlist") );
72     set_description( _("Playlist") );
73     add_submodule();
74         set_description( _("M3U playlist import") );
75         add_shortcut( "m3u-open" );
76         set_capability( "demux2", 10 );
77         add_bool( "m3u-extvlcopt", VLC_FALSE, NULL,
78                   EXTVLCOPT_TEXT, EXTVLCOPT_LONGTEXT, VLC_FALSE );
79         set_callbacks( E_(Import_M3U), E_(Close_M3U) );
80     add_submodule();
81         set_description( _("PLS playlist import") );
82         add_shortcut( "pls-open" );
83         set_capability( "demux2", 10 );
84         set_callbacks( E_(Import_PLS), E_(Close_PLS) );
85     add_submodule();
86         set_description( _("B4S playlist import") );
87         add_shortcut( "b4s-open" );
88         add_shortcut( "shout-b4s" );
89         set_capability( "demux2", 10 );
90         set_callbacks( E_(Import_B4S), E_(Close_B4S) );
91     add_submodule();
92         set_description( _("DVB playlist import") );
93         add_shortcut( "dvb-open" );
94         set_capability( "demux2", 10 );
95         set_callbacks( E_(Import_DVB), E_(Close_DVB) );
96     add_submodule();
97         set_description( _("Podcast parser") );
98         add_shortcut( "podcast" );
99         set_capability( "demux2", 10 );
100         set_callbacks( E_(Import_podcast), E_(Close_podcast) );
101     add_submodule();
102         set_description( _("XSPF playlist import") );
103         add_shortcut( "xspf-open" );
104         set_capability( "demux2", 10 );
105         set_callbacks( E_(Import_xspf),E_(Close_xspf) );
106     add_submodule();
107         set_description( _("New winamp 5.2 shoutcast import") );
108         add_shortcut( "shout-winamp" );
109         set_capability( "demux2", 10 );
110         set_callbacks( E_(Import_Shoutcast), E_(Close_Shoutcast) );
111         add_bool( "shoutcast-show-adult", VLC_FALSE, NULL,
112                    SHOW_ADULT_TEXT, SHOW_ADULT_LONGTEXT, VLC_FALSE );
113     add_submodule();
114         set_description( _("ASX playlist import") );
115         add_shortcut( "asx-open" );
116         set_capability( "demux2", 10 );
117         set_callbacks( E_(Import_ASX), E_(Close_ASX) );
118     add_submodule();
119         set_description( _("Kasenna MediaBase parser") );
120         add_shortcut( "sgimb" );
121         set_capability( "demux2", 10 );
122         set_callbacks( E_(Import_SGIMB), E_(Close_SGIMB) );
123     add_submodule();
124         set_description( _("QuickTime Media Link importer") );
125         add_shortcut( "qtl" );
126         set_capability( "demux2", 10 );
127         set_callbacks( E_(Import_QTL), E_(Close_QTL) );
128     add_submodule();
129         set_description( _("Google Video Playlist importer") );
130         add_shortcut( "gvp" );
131         set_capability( "demux2", 10 );
132         set_callbacks( E_(Import_GVP), E_(Close_GVP) );
133     add_submodule();
134         set_description( _("Dummy ifo demux") );
135         set_capability( "demux2", 12 );
136         set_callbacks( E_(Import_IFO), E_(Close_IFO) );
137     add_submodule();
138         set_description( _("iTunes Music Library importer") );
139         add_shortcut( "itml" );
140         set_capability( "demux2", 10 );
141         set_callbacks( E_(Import_iTML), E_(Close_iTML) );
142 vlc_module_end();
143
144
145 /**
146  * Find directory part of the path to the playlist file, in case of
147  * relative paths inside
148  */
149 char *E_(FindPrefix)( demux_t *p_demux )
150 {
151     char *psz_name;
152     char *psz_path = strdup( p_demux->psz_path );
153
154 #ifndef WIN32
155     psz_name = strrchr( psz_path, '/' );
156 #else
157     psz_name = strrchr( psz_path, '\\' );
158     if( !psz_name ) psz_name = strrchr( psz_path, '/' );
159 #endif
160     if( psz_name ) psz_name[1] = '\0';
161     else *psz_path = '\0';
162
163     return psz_path;
164 }
165
166 /**
167  * Add the directory part of the playlist file to the start of the
168  * mrl, if the mrl is a relative file path
169  */
170 char *E_(ProcessMRL)( char *psz_mrl, char *psz_prefix )
171 {
172     /* Check for a protocol name.
173      * for URL, we should look for "://"
174      * for MRL (Media Resource Locator) ([[<access>][/<demux>]:][<source>]),
175      * we should look for ":", so we end up looking simply for ":"
176      * PB: on some file systems, ':' are valid characters though */
177
178     /* Simple cases first */
179     if( !psz_mrl || !*psz_mrl ) return NULL;
180     if( !psz_prefix || !*psz_prefix ) return strdup( psz_mrl );
181
182     /* Check if the line specifies an absolute path */
183     if( *psz_mrl == '/' || *psz_mrl == '\\' ) return strdup( psz_mrl );
184
185     /* Check if the line specifies an mrl/url
186      * (and on win32, contains a drive letter) */
187     if( strchr( psz_mrl, ':' ) ) return strdup( psz_mrl );
188
189     /* This a relative path, prepend the prefix */
190     asprintf( &psz_mrl, "%s%s", psz_prefix, psz_mrl );
191     return psz_mrl;
192 }