stream: replace input_thread_t by input_item_t
[vlc.git] / modules / demux / playlist / playlist.c
blob28e3453c5983e867ea3bdc3b5a7a281e1b7af638
1 /*****************************************************************************
2 * playlist.c : Playlist import module
3 *****************************************************************************
4 * Copyright (C) 2004 VLC authors and VideoLAN
5 * $Id$
7 * Authors: Clément Stenac <zorglub@videolan.org>
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU Lesser General Public License as published by
11 * the Free Software Foundation; either version 2.1 of the License, or
12 * (at your option) any later version.
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 Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with this program; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 /*****************************************************************************
25 * Preamble
26 *****************************************************************************/
27 #ifdef HAVE_CONFIG_H
28 # include "config.h"
29 #endif
31 #include <vlc_common.h>
32 #include <vlc_plugin.h>
33 #include <vlc_demux.h>
34 #include <vlc_url.h>
36 #if defined( _WIN32 ) || defined( __OS2__ )
37 # include <ctype.h> /* isalpha */
38 #endif
39 #include <assert.h>
41 #include "playlist.h"
43 /*****************************************************************************
44 * Module descriptor
45 *****************************************************************************/
46 #define SHOW_ADULT_TEXT N_( "Show shoutcast adult content" )
47 #define SHOW_ADULT_LONGTEXT N_( "Show NC17 rated video streams when " \
48 "using shoutcast video playlists." )
50 #define SKIP_ADS_TEXT N_( "Skip ads" )
51 #define SKIP_ADS_LONGTEXT N_( "Use playlist options usually used to prevent " \
52 "ads skipping to detect ads and prevent adding them to the playlist." )
54 vlc_module_begin ()
55 add_shortcut( "playlist" )
56 set_category( CAT_INPUT )
57 set_subcategory( SUBCAT_INPUT_DEMUX )
59 add_obsolete_integer( "parent-item" ) /* removed since 1.1.0 */
61 add_bool( "playlist-skip-ads", true,
62 SKIP_ADS_TEXT, SKIP_ADS_LONGTEXT, false )
64 set_shortname( N_("Playlist") )
65 set_description( N_("Playlist") )
66 add_submodule ()
67 set_description( N_("M3U playlist import") )
68 add_shortcut( "m3u", "m3u8" )
69 set_capability( "stream_filter", 310 )
70 set_callbacks( Import_M3U, NULL )
71 add_submodule ()
72 set_description( N_("RAM playlist import") )
73 set_capability( "stream_filter", 310 )
74 set_callbacks( Import_RAM, NULL )
75 add_submodule ()
76 set_description( N_("PLS playlist import") )
77 set_capability( "stream_filter", 310 )
78 set_callbacks( Import_PLS, NULL )
79 add_submodule ()
80 set_description( N_("B4S playlist import") )
81 add_shortcut( "shout-b4s" )
82 set_capability( "stream_filter", 310 )
83 set_callbacks( Import_B4S, NULL )
84 add_submodule ()
85 set_description( N_("DVB playlist import") )
86 add_shortcut( "dvb" )
87 set_capability( "stream_filter", 310 )
88 set_callbacks( Import_DVB, NULL )
89 add_submodule ()
90 set_description( N_("Podcast parser") )
91 add_shortcut( "podcast" )
92 set_capability( "stream_filter", 310 )
93 set_callbacks( Import_podcast, NULL )
94 add_submodule ()
95 set_description( N_("XSPF playlist import") )
96 set_capability( "stream_filter", 310 )
97 set_callbacks( Import_xspf, Close_xspf )
98 add_submodule ()
99 set_description( N_("ASX playlist import") )
100 set_capability( "stream_filter", 310 )
101 set_callbacks( Import_ASX, NULL )
102 add_submodule ()
103 set_description( N_("Kasenna MediaBase parser") )
104 add_shortcut( "sgimb" )
105 set_capability( "stream_filter", 310 )
106 set_callbacks( Import_SGIMB, Close_SGIMB )
107 add_submodule ()
108 set_description( N_("QuickTime Media Link importer") )
109 add_shortcut( "qtl" )
110 set_capability( "stream_filter", 310 )
111 set_callbacks( Import_QTL, NULL )
112 add_submodule ()
113 set_description( N_("Dummy IFO demux") )
114 set_capability( "stream_filter", 312 )
115 set_callbacks( Import_IFO, NULL )
116 add_submodule ()
117 set_description( N_("Dummy BDMV demux") )
118 set_capability( "stream_filter", 312 )
119 set_callbacks( Import_BDMV, NULL )
120 add_submodule ()
121 set_description( N_("iTunes Music Library importer") )
122 add_shortcut( "itml" )
123 set_capability( "stream_filter", 310 )
124 set_callbacks( Import_iTML, NULL )
125 add_submodule ()
126 set_description( N_("WPL playlist import") )
127 add_shortcut( "wpl" )
128 set_capability( "stream_filter", 310 )
129 set_callbacks( Import_WPL, Close_WPL )
130 vlc_module_end ()
133 * Resolves a playlist location.
135 * Resolves a resource location within the playlist relative to the playlist
136 * base URL.
138 char *ProcessMRL(const char *str, const char *base)
140 char const* orig = str;
142 if (str == NULL)
143 return NULL;
145 #if (DIR_SEP_CHAR == '\\')
146 /* UNC path prefix? */
147 if (strncmp(str, "\\\\", 2) == 0
148 /* Drive letter prefix? */
149 || (isalpha((unsigned char)str[0]) && str[1] == ':'))
150 /* Assume this an absolute file path - usually true */
151 return vlc_path2uri(str, NULL);
152 /* TODO: drive-relative path: if (str[0] == '\\') */
153 #endif
155 /* The base URL is always an URL: it is the URL of the playlist.
157 * However it is not always known if the input string is a valid URL, a
158 * broken URL or a local file path. As a rule, if it looks like a valid
159 * URL, it must be treated as such, since most playlist formats use URLs.
161 * There are a few corner cases file paths that look like an URL but whose
162 * URL representation does not match, notably when they contain a
163 * percentage sign, a colon, a hash or a question mark. Luckily, they are
164 * rather exceptional (and can be encoded as URL to make the playlist
165 * work properly).
167 * If the input is not a valid URL, then we try to fix it up. It works in
168 * all cases for URLs with incorrectly encoded segments, such as URLs with
169 * white spaces or non-ASCII Unicode code points. It also works in most
170 * cases where the input is a Unix-style file path, but not all.
171 * It fails miserably if the playlist character encoding is misdetected.
173 char *rel = vlc_uri_fixup(str);
174 if (rel != NULL)
175 str = rel;
177 char *abs = vlc_uri_resolve(base, str);
178 free(rel);
180 if (abs == NULL)
182 /** If the input is not a valid URL, see if there is a scheme:// where
183 * the scheme itself consists solely of valid scheme-characters
184 * (including the VLC's scheme-extension). If it does, fall back to
185 * allowing the URI in order to not break back-compatibility.
187 char const* scheme_end = strstr( orig, "://" );
188 char const* valid_chars = "abcdefghijklmnopqrstuvwxyz"
189 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
190 "0123456789" "+-./";
191 if (scheme_end &&
192 strspn (orig, valid_chars) == (size_t)(scheme_end - orig))
194 abs = strdup (orig);
198 return abs;