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