1 /*****************************************************************************
2 * playlist.c : Playlist import module
3 *****************************************************************************
4 * Copyright (C) 2004 the VideoLAN team
7 * Authors: Clément Stenac <zorglub@videolan.org>
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.
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.
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 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
31 #include <vlc_common.h>
32 #include <vlc_plugin.h>
33 #include <vlc_demux.h>
41 /*****************************************************************************
43 *****************************************************************************/
44 #define AUTOSTART_TEXT N_( "Auto start" )
45 #define AUTOSTART_LONGTEXT N_( "Automatically start playing the playlist " \
46 "content once it's loaded." )
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." )
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." )
57 add_shortcut( "playlist" )
58 set_category( CAT_INPUT )
59 set_subcategory( SUBCAT_INPUT_DEMUX )
61 add_bool( "playlist-autostart", true, NULL,
62 AUTOSTART_TEXT, AUTOSTART_LONGTEXT, false )
64 add_obsolete_integer( "parent-item" ) /* removed since 1.1.0 */
66 add_bool( "playlist-skip-ads", true, NULL,
67 SKIP_ADS_TEXT, SKIP_ADS_LONGTEXT, false )
69 set_shortname( N_("Playlist") )
70 set_description( N_("Playlist") )
72 set_description( N_("M3U playlist import") )
73 add_shortcut( "playlist" )
75 add_shortcut( "m3u8" )
76 add_shortcut( "m3u-open" )
77 set_capability( "demux", 10 )
78 set_callbacks( Import_M3U, Close_M3U )
80 set_description( N_("RAM playlist import") )
81 add_shortcut( "playlist" )
82 add_shortcut( "ram-open" )
83 set_capability( "demux", 10 )
84 set_callbacks( Import_RAM, Close_RAM )
86 set_description( N_("PLS playlist import") )
87 add_shortcut( "playlist" )
88 add_shortcut( "pls-open" )
89 set_capability( "demux", 10 )
90 set_callbacks( Import_PLS, Close_PLS )
92 set_description( N_("B4S playlist import") )
93 add_shortcut( "playlist" )
94 add_shortcut( "b4s-open" )
95 add_shortcut( "shout-b4s" )
96 set_capability( "demux", 10 )
97 set_callbacks( Import_B4S, Close_B4S )
99 set_description( N_("DVB playlist import") )
100 add_shortcut( "playlist" )
101 add_shortcut( "dvb-open" )
102 set_capability( "demux", 10 )
103 set_callbacks( Import_DVB, Close_DVB )
105 set_description( N_("Podcast parser") )
106 add_shortcut( "playlist" )
107 add_shortcut( "podcast" )
108 set_capability( "demux", 10 )
109 set_callbacks( Import_podcast, Close_podcast )
111 set_description( N_("XSPF playlist import") )
112 add_shortcut( "playlist" )
113 add_shortcut( "xspf-open" )
114 set_capability( "demux", 10 )
115 set_callbacks( Import_xspf, Close_xspf )
117 set_description( N_("New winamp 5.2 shoutcast import") )
118 add_shortcut( "playlist" )
119 add_shortcut( "shout-winamp" )
120 set_capability( "demux", 10 )
121 set_callbacks( Import_Shoutcast, Close_Shoutcast )
122 add_bool( "shoutcast-show-adult", false, NULL,
123 SHOW_ADULT_TEXT, SHOW_ADULT_LONGTEXT, false )
125 set_description( N_("ASX playlist import") )
126 add_shortcut( "playlist" )
127 add_shortcut( "asx-open" )
128 set_capability( "demux", 10 )
129 set_callbacks( Import_ASX, Close_ASX )
131 set_description( N_("Kasenna MediaBase parser") )
132 add_shortcut( "playlist" )
133 add_shortcut( "sgimb" )
134 set_capability( "demux", 10 )
135 set_callbacks( Import_SGIMB, Close_SGIMB )
137 set_description( N_("QuickTime Media Link importer") )
138 add_shortcut( "playlist" )
139 add_shortcut( "qtl" )
140 set_capability( "demux", 10 )
141 set_callbacks( Import_QTL, Close_QTL )
143 set_description( N_("Google Video Playlist importer") )
144 add_shortcut( "playlist" )
145 add_shortcut( "gvp" )
146 set_capability( "demux", 10 )
147 set_callbacks( Import_GVP, Close_GVP )
149 set_description( N_("Dummy ifo demux") )
150 add_shortcut( "playlist" )
151 set_capability( "demux", 12 )
152 set_callbacks( Import_IFO, Close_IFO )
154 set_description( N_("iTunes Music Library importer") )
155 add_shortcut( "playlist" )
156 add_shortcut( "itml" )
157 set_capability( "demux", 10 )
158 set_callbacks( Import_iTML, Close_iTML )
160 set_description( N_("WPL playlist import") )
161 add_shortcut( "playlist" )
162 add_shortcut( "wpl" )
163 set_capability( "demux", 10 )
164 set_callbacks( Import_WPL, Close_WPL )
166 set_description( N_("ZPL playlist import") )
167 add_shortcut( "playlist" )
168 add_shortcut( "zpl" )
169 set_capability( "demux", 10 )
170 set_callbacks( Import_ZPL, Close_ZPL )
173 input_item_t * GetCurrentItem(demux_t *p_demux)
175 input_thread_t *p_input_thread = demux_GetParentInput( p_demux );
176 input_item_t *p_current_input = input_GetItem( p_input_thread );
177 vlc_gc_incref(p_current_input);
178 vlc_object_release(p_input_thread);
179 return p_current_input;
183 * Find directory part of the path to the playlist file, in case of
184 * relative paths inside
186 char *FindPrefix( demux_t *p_demux )
191 if( p_demux->psz_access )
193 if( asprintf( &psz_path,"%s://%s", p_demux->psz_access, p_demux->psz_path ) == -1 )
198 psz_path = strdup( p_demux->psz_path );
199 if( psz_path == NULL )
204 psz_file = strrchr( psz_path, '\\' );
207 psz_file = strrchr( psz_path, '/' );
210 psz_prefix = strndup( psz_path, psz_file - psz_path + 1 );
212 psz_prefix = strdup( "" );
219 * Add the directory part of the playlist file to the start of the
220 * mrl, if the mrl is a relative file path
222 char *ProcessMRL( const char *psz_mrl, const char *psz_prefix )
224 /* Check for a protocol name.
225 * for URL, we should look for "://"
226 * for MRL (Media Resource Locator) ([[<access>][/<demux>]:][<source>]),
227 * we should look for ":", so we end up looking simply for ":"
228 * PB: on some file systems, ':' are valid characters though */
230 /* Simple cases first */
231 if( !psz_mrl || !*psz_mrl )
233 if( !psz_prefix || !*psz_prefix )
236 /* Check if the line specifies an absolute path */
237 /* FIXME: that's wrong if the playlist is not a local file */
238 if( *psz_mrl == DIR_SEP_CHAR )
241 /* Drive letter (this assumes URL scheme are not a single character) */
242 if( isalpha(psz_mrl[0]) && psz_mrl[1] == ':' )
245 if( strstr( psz_mrl, "://" ) )
246 return strdup( psz_mrl );
248 /* This a relative path, prepend the prefix */
250 char *postfix = encode_URI_component( psz_mrl );
251 /* FIXME: postfix may not be encoded correctly (esp. slashes) */
253 || asprintf( &ret, "%s%s", psz_prefix, postfix ) == -1 )
259 return make_URI( psz_mrl );