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