]> git.sesse.net Git - vlc/blob - modules/demux/playlist/playlist.c
modules: use the new add_shortcut capability (add multiple shortcuts at a time).
[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_obsolete_integer( "parent-item" ) /* removed since 1.1.0 */
65
66     add_bool( "playlist-skip-ads", true, NULL,
67               SKIP_ADS_TEXT, SKIP_ADS_LONGTEXT, false )
68
69     set_shortname( N_("Playlist") )
70     set_description( N_("Playlist") )
71     add_submodule ()
72         set_description( N_("M3U playlist import") )
73         add_shortcut( "playlist", "m3u", "m3u8", "m3u-open" )
74         set_capability( "demux", 10 )
75         set_callbacks( Import_M3U, Close_M3U )
76     add_submodule ()
77         set_description( N_("RAM playlist import") )
78         add_shortcut( "playlist", "ram-open" )
79         set_capability( "demux", 10 )
80         set_callbacks( Import_RAM, Close_RAM )
81     add_submodule ()
82         set_description( N_("PLS playlist import") )
83         add_shortcut( "playlist", "pls-open" )
84         set_capability( "demux", 10 )
85         set_callbacks( Import_PLS, Close_PLS )
86     add_submodule ()
87         set_description( N_("B4S playlist import") )
88         add_shortcut( "playlist", "b4s-open", "shout-b4s" )
89         set_capability( "demux", 10 )
90         set_callbacks( Import_B4S, Close_B4S )
91     add_submodule ()
92         set_description( N_("DVB playlist import") )
93         add_shortcut( "playlist", "dvb-open" )
94         set_capability( "demux", 10 )
95         set_callbacks( Import_DVB, Close_DVB )
96     add_submodule ()
97         set_description( N_("Podcast parser") )
98         add_shortcut( "playlist", "podcast" )
99         set_capability( "demux", 10 )
100         set_callbacks( Import_podcast, Close_podcast )
101     add_submodule ()
102         set_description( N_("XSPF playlist import") )
103         add_shortcut( "playlist", "xspf-open" )
104         set_capability( "demux", 10 )
105         set_callbacks( Import_xspf, Close_xspf )
106     add_submodule ()
107         set_description( N_("New winamp 5.2 shoutcast import") )
108         add_shortcut( "playlist", "shout-winamp" )
109         set_capability( "demux", 10 )
110         set_callbacks( Import_Shoutcast, Close_Shoutcast )
111         add_bool( "shoutcast-show-adult", false, NULL,
112                    SHOW_ADULT_TEXT, SHOW_ADULT_LONGTEXT, false )
113     add_submodule ()
114         set_description( N_("ASX playlist import") )
115         add_shortcut( "playlist", "asx-open" )
116         set_capability( "demux", 10 )
117         set_callbacks( Import_ASX, Close_ASX )
118     add_submodule ()
119         set_description( N_("Kasenna MediaBase parser") )
120         add_shortcut( "playlist", "sgimb" )
121         set_capability( "demux", 10 )
122         set_callbacks( Import_SGIMB, Close_SGIMB )
123     add_submodule ()
124         set_description( N_("QuickTime Media Link importer") )
125         add_shortcut( "playlist", "qtl" )
126         set_capability( "demux", 10 )
127         set_callbacks( Import_QTL, Close_QTL )
128     add_submodule ()
129         set_description( N_("Google Video Playlist importer") )
130         add_shortcut( "playlist", "gvp" )
131         set_capability( "demux", 10 )
132         set_callbacks( Import_GVP, Close_GVP )
133     add_submodule ()
134         set_description( N_("Dummy ifo demux") )
135         add_shortcut( "playlist" )
136         set_capability( "demux", 12 )
137         set_callbacks( Import_IFO, Close_IFO )
138     add_submodule ()
139         set_description( N_("iTunes Music Library importer") )
140         add_shortcut( "playlist", "itml" )
141         set_capability( "demux", 10 )
142         set_callbacks( Import_iTML, Close_iTML )
143     add_submodule ()
144         set_description( N_("WPL playlist import") )
145         add_shortcut( "playlist", "wpl" )
146         set_capability( "demux", 10 )
147         set_callbacks( Import_WPL, Close_WPL )
148     add_submodule ()
149         set_description( N_("ZPL playlist import") )
150         add_shortcut( "playlist", "zpl" )
151         set_capability( "demux", 10 )
152         set_callbacks( Import_ZPL, Close_ZPL )
153 vlc_module_end ()
154
155 input_item_t * GetCurrentItem(demux_t *p_demux)
156 {
157     input_thread_t *p_input_thread = demux_GetParentInput( p_demux );
158     input_item_t *p_current_input = input_GetItem( p_input_thread );
159     vlc_gc_incref(p_current_input);
160     vlc_object_release(p_input_thread);
161     return p_current_input;
162 }
163
164 /**
165  * Find directory part of the path to the playlist file, in case of
166  * relative paths inside
167  */
168 char *FindPrefix( demux_t *p_demux )
169 {
170     char *psz_file;
171     char *psz_prefix;
172     char *psz_path;
173     if( p_demux->psz_access )
174     {
175         if( asprintf( &psz_path,"%s://%s", p_demux->psz_access, p_demux->psz_path ) == -1 )
176             return NULL;
177     }
178     else
179     {
180         psz_path = strdup( p_demux->psz_path );
181         if( psz_path == NULL )
182             return NULL;
183     }
184
185 #ifdef WIN32
186     psz_file = strrchr( psz_path, '\\' );
187     if( !psz_file )
188 #endif
189     psz_file = strrchr( psz_path, '/' );
190
191     if( psz_file )
192         psz_prefix = strndup( psz_path, psz_file - psz_path + 1 );
193     else
194         psz_prefix = strdup( "" );
195     free( psz_path );
196
197     return psz_prefix;
198 }
199
200 /**
201  * Add the directory part of the playlist file to the start of the
202  * mrl, if the mrl is a relative file path
203  */
204 char *ProcessMRL( const char *psz_mrl, const char *psz_prefix )
205 {
206     /* Check for a protocol name.
207      * for URL, we should look for "://"
208      * for MRL (Media Resource Locator) ([[<access>][/<demux>]:][<source>]),
209      * we should look for ":", so we end up looking simply for ":"
210      * PB: on some file systems, ':' are valid characters though */
211
212     /* Simple cases first */
213     if( !psz_mrl || !*psz_mrl )
214         return NULL;
215     if( !psz_prefix || !*psz_prefix )
216         goto uri;
217
218     /* Check if the line specifies an absolute path */
219     /* FIXME: that's wrong if the playlist is not a local file */
220     if( *psz_mrl == DIR_SEP_CHAR )
221         goto uri;
222 #ifdef WIN32
223     /* Drive letter (this assumes URL scheme are not a single character) */
224     if( isalpha(psz_mrl[0]) && psz_mrl[1] == ':' )
225         goto uri;
226 #endif
227     if( strstr( psz_mrl, "://" ) )
228         return strdup( psz_mrl );
229
230     /* This a relative path, prepend the prefix */
231     char *ret;
232     char *postfix = encode_URI_component( psz_mrl );
233     /* FIXME: postfix may not be encoded correctly (esp. slashes) */
234     if( postfix == NULL
235      || asprintf( &ret, "%s%s", psz_prefix, postfix ) == -1 )
236         ret = NULL;
237     free( postfix );
238     return ret;
239
240 uri:
241     return make_URI( psz_mrl );
242 }