]> git.sesse.net Git - vlc/blob - modules/demux/playlist/playlist.c
Do not apply playlist path to full URIs
[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_common.h>
32 #include <vlc_plugin.h>
33 #include <vlc_demux.h>
34 #include <vlc_url.h>
35 #ifdef WIN32
36 # include <ctype.h>
37 #endif
38
39 #include "playlist.h"
40
41 /*****************************************************************************
42  * Module descriptor
43  *****************************************************************************/
44 #define AUTOSTART_TEXT N_( "Auto start" )
45 #define AUTOSTART_LONGTEXT N_( "Automatically start playing the playlist " \
46                 "content once it's loaded." )
47
48 #define SHOW_ADULT_TEXT N_( "Show shoutcast adult content" )
49 #define SHOW_ADULT_LONGTEXT N_( "Show NC17 rated video streams when " \
50                 "using shoutcast video playlists." )
51
52 #define SKIP_ADS_TEXT N_( "Skip ads" )
53 #define SKIP_ADS_LONGTEXT N_( "Use playlist options usually used to prevent " \
54     "ads skipping to detect ads and prevent adding them to the playlist." )
55
56 vlc_module_begin ()
57     add_shortcut( "playlist" )
58     set_category( CAT_INPUT )
59     set_subcategory( SUBCAT_INPUT_DEMUX )
60
61     add_bool( "playlist-autostart", true, NULL,
62               AUTOSTART_TEXT, AUTOSTART_LONGTEXT, false )
63
64     add_integer( "parent-item", 0, NULL, NULL, NULL, true )
65         change_internal ()
66
67     add_bool( "playlist-skip-ads", true, NULL,
68               SKIP_ADS_TEXT, SKIP_ADS_LONGTEXT, false )
69
70     set_shortname( N_("Playlist") )
71     set_description( N_("Playlist") )
72     add_submodule ()
73         set_description( N_("M3U playlist import") )
74         add_shortcut( "playlist" )
75         add_shortcut( "m3u" )
76         add_shortcut( "m3u8" )
77         add_shortcut( "m3u-open" )
78         set_capability( "demux", 10 )
79         set_callbacks( Import_M3U, Close_M3U )
80     add_submodule ()
81         set_description( N_("RAM playlist import") )
82         add_shortcut( "playlist" )
83         add_shortcut( "ram-open" )
84         set_capability( "demux", 10 )
85         set_callbacks( Import_RAM, Close_RAM )
86     add_submodule ()
87         set_description( N_("PLS playlist import") )
88         add_shortcut( "playlist" )
89         add_shortcut( "pls-open" )
90         set_capability( "demux", 10 )
91         set_callbacks( Import_PLS, Close_PLS )
92     add_submodule ()
93         set_description( N_("B4S playlist import") )
94         add_shortcut( "playlist" )
95         add_shortcut( "b4s-open" )
96         add_shortcut( "shout-b4s" )
97         set_capability( "demux", 10 )
98         set_callbacks( Import_B4S, Close_B4S )
99     add_submodule ()
100         set_description( N_("DVB playlist import") )
101         add_shortcut( "playlist" )
102         add_shortcut( "dvb-open" )
103         set_capability( "demux", 10 )
104         set_callbacks( Import_DVB, Close_DVB )
105     add_submodule ()
106         set_description( N_("Podcast parser") )
107         add_shortcut( "playlist" )
108         add_shortcut( "podcast" )
109         set_capability( "demux", 10 )
110         set_callbacks( Import_podcast, Close_podcast )
111     add_submodule ()
112         set_description( N_("XSPF playlist import") )
113         add_shortcut( "playlist" )
114         add_shortcut( "xspf-open" )
115         set_capability( "demux", 10 )
116         set_callbacks( Import_xspf, Close_xspf )
117     add_submodule ()
118         set_description( N_("New winamp 5.2 shoutcast import") )
119         add_shortcut( "playlist" )
120         add_shortcut( "shout-winamp" )
121         set_capability( "demux", 10 )
122         set_callbacks( Import_Shoutcast, Close_Shoutcast )
123         add_bool( "shoutcast-show-adult", false, NULL,
124                    SHOW_ADULT_TEXT, SHOW_ADULT_LONGTEXT, false )
125     add_submodule ()
126         set_description( N_("ASX playlist import") )
127         add_shortcut( "playlist" )
128         add_shortcut( "asx-open" )
129         set_capability( "demux", 10 )
130         set_callbacks( Import_ASX, Close_ASX )
131     add_submodule ()
132         set_description( N_("Kasenna MediaBase parser") )
133         add_shortcut( "playlist" )
134         add_shortcut( "sgimb" )
135         set_capability( "demux", 10 )
136         set_callbacks( Import_SGIMB, Close_SGIMB )
137     add_submodule ()
138         set_description( N_("QuickTime Media Link importer") )
139         add_shortcut( "playlist" )
140         add_shortcut( "qtl" )
141         set_capability( "demux", 10 )
142         set_callbacks( Import_QTL, Close_QTL )
143     add_submodule ()
144         set_description( N_("Google Video Playlist importer") )
145         add_shortcut( "playlist" )
146         add_shortcut( "gvp" )
147         set_capability( "demux", 10 )
148         set_callbacks( Import_GVP, Close_GVP )
149     add_submodule ()
150         set_description( N_("Dummy ifo demux") )
151         add_shortcut( "playlist" )
152         set_capability( "demux", 12 )
153         set_callbacks( Import_IFO, Close_IFO )
154     add_submodule ()
155         set_description( N_("iTunes Music Library importer") )
156         add_shortcut( "playlist" )
157         add_shortcut( "itml" )
158         set_capability( "demux", 10 )
159         set_callbacks( Import_iTML, Close_iTML )
160     add_submodule ()
161         set_description( N_("WPL playlist import") )
162         add_shortcut( "playlist" )
163         add_shortcut( "wpl" )
164         set_capability( "demux", 10 )
165         set_callbacks( Import_WPL, Close_WPL )
166     add_submodule ()
167         set_description( N_("ZPL playlist import") )
168         add_shortcut( "playlist" )
169         add_shortcut( "zpl" )
170         set_capability( "demux", 10 )
171         set_callbacks( Import_ZPL, Close_ZPL )
172 vlc_module_end ()
173
174 input_item_t * GetCurrentItem(demux_t *p_demux)
175 {
176     input_thread_t *p_input_thread = demux_GetParentInput( p_demux );
177     input_item_t *p_current_input = input_GetItem( p_input_thread );
178     vlc_gc_incref(p_current_input);
179     vlc_object_release(p_input_thread);
180     return p_current_input;
181 }
182
183 /**
184  * Find directory part of the path to the playlist file, in case of
185  * relative paths inside
186  */
187 char *FindPrefix( demux_t *p_demux )
188 {
189     char *psz_file;
190     char *psz_prefix;
191     char *psz_path;
192     if( p_demux->psz_access )
193     {
194         if( asprintf( &psz_path,"%s://%s", p_demux->psz_access, p_demux->psz_path ) == -1 )
195             return NULL;
196     }
197     else
198     {
199         psz_path = strdup( p_demux->psz_path );
200         if( psz_path == NULL )
201             return NULL;
202     }
203
204 #ifdef WIN32
205     psz_file = strrchr( psz_path, '\\' );
206     if( !psz_file )
207 #endif
208     psz_file = strrchr( psz_path, '/' );
209
210     if( psz_file )
211         psz_prefix = strndup( psz_path, psz_file - psz_path + 1 );
212     else
213         psz_prefix = strdup( "" );
214     free( psz_path );
215
216     return psz_prefix;
217 }
218
219 /**
220  * Add the directory part of the playlist file to the start of the
221  * mrl, if the mrl is a relative file path
222  */
223 char *ProcessMRL( const char *psz_mrl, const char *psz_prefix )
224 {
225     /* Check for a protocol name.
226      * for URL, we should look for "://"
227      * for MRL (Media Resource Locator) ([[<access>][/<demux>]:][<source>]),
228      * we should look for ":", so we end up looking simply for ":"
229      * PB: on some file systems, ':' are valid characters though */
230
231     /* Simple cases first */
232     if( !psz_mrl || !*psz_mrl )
233         return NULL;
234     if( !psz_prefix || !*psz_prefix )
235         goto uri;
236
237     /* Check if the line specifies an absolute path */
238     /* FIXME: that's wrong if the playlist is not a local file */
239     if( *psz_mrl == DIR_SEP_CHAR )
240         goto uri;
241 #ifdef WIN32
242     /* Drive letter (this assumes URL scheme are not a single character) */
243     if( isalpha(psz_mrl[0]) && psz_mrl[1] == ':' )
244         goto uri;
245 #endif
246     if( strstr( psz_mrl, "://" ) )
247         return strdup( psz_mrl );
248
249     /* This a relative path, prepend the prefix */
250     char *ret;
251     char *postfix = encode_URI_component( psz_mrl );
252     /* FIXME: postfix may not be encoded correctly (esp. slashes) */
253     if( postfix == NULL
254      || asprintf( &ret, "%s%s", psz_prefix, postfix ) == -1 )
255         ret = NULL;
256     free( postfix );
257     return ret;
258
259 uri:
260     return make_URI( psz_mrl );
261 }