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 *****************************************************************************/
28 #include <vlc/input.h>
29 #include <vlc_playlist.h>
33 /*****************************************************************************
35 *****************************************************************************/
36 #define AUTOSTART_TEXT N_( "Auto start" )
37 /// \bug [String] Why \n ?
38 #define AUTOSTART_LONGTEXT N_( "Automatically start playing the playlist " \
39 "content once it's loaded.\n" )
42 add_shortcut( "playlist" );
43 set_category( CAT_INPUT );
44 set_subcategory( SUBCAT_INPUT_DEMUX );
46 add_bool( "playlist-autostart", 1, NULL,
47 AUTOSTART_TEXT, AUTOSTART_LONGTEXT, VLC_FALSE );
49 set_shortname( _("Playlist") );
50 set_description( _("Playlist") );
51 add_shortcut( "old-open" );
52 set_capability( "demux2", 10 );
53 set_callbacks( E_(Import_Old), NULL );
56 set_description( _("Native playlist import") );
57 add_shortcut( "playlist" );
58 add_shortcut( "native-open" );
59 set_capability( "demux2", 10 );
60 set_callbacks( E_(Import_Native), E_(Close_Native) );
63 set_description( _("M3U playlist import") );
64 add_shortcut( "m3u-open" );
65 set_capability( "demux2", 10 );
66 set_callbacks( E_(Import_M3U), E_(Close_M3U) );
68 set_description( _("PLS playlist import") );
69 add_shortcut( "pls-open" );
70 set_capability( "demux2", 10 );
71 set_callbacks( E_(Import_PLS), E_(Close_PLS) );
73 set_description( _("B4S playlist import") );
74 add_shortcut( "b4s-open" );
75 add_shortcut( "shout-b4s" );
76 set_capability( "demux2", 10 );
77 set_callbacks( E_(Import_B4S), E_(Close_B4S) );
79 set_description( _("DVB playlist import") );
80 add_shortcut( "dvb-open" );
81 set_capability( "demux2", 10 );
82 set_callbacks( E_(Import_DVB), E_(Close_DVB) );
84 set_description( _("Podcast parser") );
85 add_shortcut( "podcast" );
86 set_capability( "demux2", 10 );
87 set_callbacks( E_(Import_podcast), E_(Close_podcast) );
89 set_description( _("XSPF playlist import") );
90 add_shortcut( "xspf-open" );
91 set_capability( "demux2", 10 );
92 set_callbacks( E_(xspf_import_Activate), NULL );
97 * Find directory part of the path to the playlist file, in case of
98 * relative paths inside
100 char *E_(FindPrefix)( demux_t *p_demux )
103 char *psz_path = strdup( p_demux->psz_path );
106 psz_name = strrchr( psz_path, '/' );
108 psz_name = strrchr( psz_path, '\\' );
109 if( !psz_name ) psz_name = strrchr( psz_path, '/' );
111 if( psz_name ) psz_name[1] = '\0';
112 else *psz_path = '\0';
118 * Add the directory part of the playlist file to the start of the
119 * mrl, if the mrl is a relative file path
121 char *E_(ProcessMRL)( char *psz_mrl, char *psz_prefix )
123 /* Check for a protocol name.
124 * for URL, we should look for "://"
125 * for MRL (Media Resource Locator) ([[<access>][/<demux>]:][<source>]),
126 * we should look for ":", so we end up looking simply for ":"
127 * PB: on some file systems, ':' are valid characters though */
129 /* Simple cases first */
130 if( !psz_mrl || !*psz_mrl ) return NULL;
131 if( !psz_prefix || !*psz_prefix ) return strdup( psz_mrl );
133 /* Check if the line specifies an absolute path */
134 if( *psz_mrl == '/' || *psz_mrl == '\\' ) return strdup( psz_mrl );
136 /* Check if the line specifies an mrl/url
137 * (and on win32, contains a drive letter) */
138 if( strchr( psz_mrl, ':' ) ) return strdup( psz_mrl );
140 /* This a relative path, prepend the prefix */
141 asprintf( &psz_mrl, "%s%s", psz_prefix, psz_mrl );
145 vlc_bool_t E_(FindItem)( demux_t *p_demux, playlist_t *p_playlist,
146 playlist_item_t **pp_item )
148 vlc_bool_t b_play = var_CreateGetBool( p_demux, "playlist-autostart" );
150 if( b_play && p_playlist->status.p_item &&
151 &p_playlist->status.p_item->input ==
152 ((input_thread_t *)p_demux->p_parent)->input.p_item )
154 msg_Dbg( p_playlist, "starting playlist playback" );
155 *pp_item = p_playlist->status.p_item;
160 input_item_t *p_current = ( (input_thread_t*)p_demux->p_parent)->
162 *pp_item = playlist_LockItemGetByInput( p_playlist, p_current );
165 msg_Dbg( p_playlist, "unable to find item in playlist");
167 msg_Dbg( p_playlist, "not starting playlist playback");