]> git.sesse.net Git - vlc/blob - modules/demux/playlist/playlist.c
* modules/demux/playlist/playlist.c: New --no-playlist-autostart option.
[vlc] / modules / demux / playlist / playlist.c
1 /*****************************************************************************
2  * playlist.c :  Playlist import module
3  *****************************************************************************
4  * Copyright (C) 2004 VideoLAN
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., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #include <vlc/vlc.h>
28 #include <vlc/input.h>
29 #include <vlc_playlist.h>
30
31 #include "playlist.h"
32
33 /*****************************************************************************
34  * Module descriptor
35  *****************************************************************************/
36 #define AUTOSTART_TEXT N_( "Auto start" )
37 #define AUTOSTART_LONGTEXT N_( "Automatically start the playlist when " \
38     "it's loaded.\n" )
39
40 vlc_module_begin();
41     add_shortcut( "playlist" );
42     set_category( CAT_INPUT );
43     set_subcategory( SUBCAT_INPUT_DEMUX );
44
45     add_bool( "playlist-autostart", 1, NULL, AUTOSTART_TEXT, AUTOSTART_LONGTEXT,
46               VLC_FALSE );
47
48     set_description( _("Old playlist open") );
49     add_shortcut( "old-open" );
50     set_capability( "demux2", 10 );
51     set_callbacks( E_(Import_Old), NULL );
52 #if 0
53     add_submodule();
54         set_description( _("Native playlist import") );
55         add_shortcut( "playlist" );
56         add_shortcut( "native-open" );
57         set_capability( "demux2", 10 );
58         set_callbacks( E_(Import_Native), E_(Close_Native) );
59 #endif
60     add_submodule();
61         set_description( _("M3U playlist import") );
62         add_shortcut( "m3u-open" );
63         set_capability( "demux2", 10 );
64         set_callbacks( E_(Import_M3U), E_(Close_M3U) );
65     add_submodule();
66         set_description( _("PLS playlist import") );
67         add_shortcut( "pls-open" );
68         set_capability( "demux2", 10 );
69         set_callbacks( E_(Import_PLS), E_(Close_PLS) );
70     add_submodule();
71         set_description( _("B4S playlist import") );
72         add_shortcut( "b4s-open" );
73         add_shortcut( "shout-b4s" );
74         set_capability( "demux2", 10 );
75         set_callbacks( E_(Import_B4S), E_(Close_B4S) );
76 vlc_module_end();
77
78
79 /**
80  * Find directory part of the path to the playlist file, in case of
81  * relative paths inside
82  */
83 char *E_(FindPrefix)( demux_t *p_demux )
84 {
85     char *psz_name;
86     char *psz_path = strdup( p_demux->psz_path );
87
88 #ifndef WIN32
89     psz_name = strrchr( psz_path, '/' );
90 #else
91     psz_name = strrchr( psz_path, '\\' );
92     if( !psz_name ) psz_name = strrchr( psz_path, '/' );
93 #endif
94     if( psz_name ) psz_name[1] = '\0';
95     else *psz_path = '\0';
96
97     return psz_path;
98 }
99
100 /**
101  * Add the directory part of the playlist file to the start of the
102  * mrl, if the mrl is a relative file path
103  */
104 char *E_(ProcessMRL)( char *psz_mrl, char *psz_prefix )
105 {
106     /* Check for a protocol name.
107      * for URL, we should look for "://"
108      * for MRL (Media Resource Locator) ([[<access>][/<demux>]:][<source>]),
109      * we should look for ":", so we end up looking simply for ":"
110      * PB: on some file systems, ':' are valid characters though */
111
112     /* Simple cases first */
113     if( !psz_mrl || !*psz_mrl ) return NULL;
114     if( !psz_prefix || !*psz_prefix ) return strdup( psz_mrl );
115
116     /* Check if the line specifies an absolute path */
117     if( *psz_mrl == '/' || *psz_mrl == '\\' ) return strdup( psz_mrl );
118
119     /* Check if the line specifies an mrl/url
120      * (and on win32, contains a drive letter) */
121     if( strchr( psz_mrl, ':' ) ) return strdup( psz_mrl );
122
123     /* This a relative path, prepend the prefix */
124     asprintf( &psz_mrl, "%s%s", psz_prefix, psz_mrl );
125     return psz_mrl;
126 }
127
128 vlc_bool_t E_(FindItem)( demux_t *p_demux, playlist_t *p_playlist,
129                      playlist_item_t **pp_item )
130 {
131      vlc_bool_t b_play = var_CreateGetBool( p_demux, "playlist-autostart" );
132
133      if( b_play && p_playlist->status.p_item &&
134              &p_playlist->status.p_item->input ==
135                 ((input_thread_t *)p_demux->p_parent)->input.p_item )
136      {
137          msg_Dbg( p_playlist, "starting playlist playback" );
138          *pp_item = p_playlist->status.p_item;
139          b_play = VLC_TRUE;
140      }
141      else
142      {
143          input_item_t *p_current = ( (input_thread_t*)p_demux->p_parent)->
144                                                         input.p_item;
145          *pp_item = playlist_LockItemGetByInput( p_playlist, p_current );
146          if( !*pp_item )
147          {
148              msg_Dbg( p_playlist, "unable to find item in playlist");
149          }
150          msg_Dbg( p_playlist, "not starting playlist playback");
151          b_play = VLC_FALSE;
152      }
153      return b_play;
154 }