1 /*****************************************************************************
2 * playlist.c : Playlist import module
3 *****************************************************************************
4 * Copyright (C) 2004 VideoLAN
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., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
28 #include <vlc/input.h>
29 #include <vlc_playlist.h>
33 /*****************************************************************************
35 *****************************************************************************/
37 add_shortcut( "playlist" );
38 set_category( CAT_INPUT );
39 set_subcategory( SUBCAT_INPUT_DEMUX );
41 set_description( _("Old playlist open") );
42 add_shortcut( "old-open" );
43 set_capability( "demux2" , 10 );
44 set_callbacks( Import_Old , NULL );
47 set_description( _("Native playlist import") );
48 add_shortcut( "playlist" );
49 add_shortcut( "native-open" );
50 set_capability( "demux2" , 10 );
51 set_callbacks( Import_Native , Close_Native );
53 set_description( _("M3U playlist import") );
54 add_shortcut( "m3u-open" );
55 set_capability( "demux2" , 10 );
56 set_callbacks( Import_M3U , Close_M3U );
58 set_description( _("PLS playlist import") );
59 add_shortcut( "pls-open" );
60 set_capability( "demux2" , 10 );
61 set_callbacks( Import_PLS , Close_PLS );
66 * Find directory part of the path to the playlist file, in case of
67 * relative paths inside
69 char *FindPrefix( demux_t *p_demux )
72 char *psz_path = strdup( p_demux->psz_path );
75 psz_name = strrchr( psz_path, '/' );
77 psz_name = strrchr( psz_path, '\\' );
78 if( !psz_name ) psz_name = strrchr( psz_path, '/' );
80 if( psz_name ) psz_name[1] = '\0';
81 else *psz_path = '\0';
87 * Add the directory part of the playlist file to the start of the
88 * mrl, if the mrl is a relative file path
90 char *ProcessMRL( char *psz_mrl, char *psz_prefix )
92 /* Check for a protocol name.
93 * for URL, we should look for "://"
94 * for MRL (Media Resource Locator) ([[<access>][/<demux>]:][<source>]),
95 * we should look for ":", so we end up looking simply for ":"
96 * PB: on some file systems, ':' are valid characters though */
98 /* Simple cases first */
99 if( !psz_mrl || !*psz_mrl ) return NULL;
100 if( !psz_prefix || !*psz_prefix ) return strdup( psz_mrl );
102 /* Check if the line specifies an absolute path */
103 if( *psz_mrl == '/' || *psz_mrl == '\\' ) return strdup( psz_mrl );
105 /* Check if the line specifies an mrl/url
106 * (and on win32, contains a drive letter) */
107 if( strchr( psz_mrl, ':' ) ) return strdup( psz_mrl );
109 /* This a relative path, prepend the prefix */
110 asprintf( &psz_mrl, "%s%s", psz_prefix, psz_mrl );
114 vlc_bool_t FindItem( demux_t *p_demux, playlist_t *p_playlist,
115 playlist_item_t **pp_item )
118 if( &p_playlist->status.p_item->input ==
119 ((input_thread_t *)p_demux->p_parent)->input.p_item )
121 msg_Dbg( p_playlist, "starting playlist playback" );
122 *pp_item = p_playlist->status.p_item;
127 input_item_t *p_current = ( (input_thread_t*)p_demux->p_parent)->
129 *pp_item = playlist_ItemGetByInput( p_playlist, p_current );
132 msg_Dbg( p_playlist, "unable to find item in playlist");
134 msg_Dbg( p_playlist, "not starting playlist playback");