]> git.sesse.net Git - vlc/blob - modules/demux/playlist/playlist.c
Stop playback if --no-playlist-autostart (Closes:#718)
[vlc] / modules / demux / playlist / playlist.c
1 /*****************************************************************************
2  * playlist.c :  Playlist import module
3  *****************************************************************************
4  * Copyright (C) 2004 the VideoLAN team
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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, 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 /// \bug [String] Why \n ?
38 #define AUTOSTART_LONGTEXT N_( "Automatically start playing the playlist " \
39                 "content once it's loaded.\n" )
40
41 #define SHOW_ADULT_TEXT N_( "Show shoutcast adult content" )
42 #define SHOW_ADULT_LONGTEXT N_( "Show NC17 rated video streams when " \
43                 "using shoutcast video playlists." )
44
45 vlc_module_begin();
46     add_shortcut( "playlist" );
47     set_category( CAT_INPUT );
48     set_subcategory( SUBCAT_INPUT_DEMUX );
49
50     add_bool( "playlist-autostart", 1, NULL,
51               AUTOSTART_TEXT, AUTOSTART_LONGTEXT, VLC_FALSE );
52
53     add_integer( "parent-item", 0, NULL, NULL, NULL, VLC_TRUE );
54         change_internal();
55
56     set_shortname( _("Playlist") );
57     set_description( _("Playlist") );
58     add_submodule();
59         set_description( _("M3U playlist import") );
60         add_shortcut( "m3u-open" );
61         set_capability( "demux2", 10 );
62         set_callbacks( E_(Import_M3U), E_(Close_M3U) );
63     add_submodule();
64         set_description( _("PLS playlist import") );
65         add_shortcut( "pls-open" );
66         set_capability( "demux2", 10 );
67         set_callbacks( E_(Import_PLS), E_(Close_PLS) );
68     add_submodule();
69         set_description( _("B4S playlist import") );
70         add_shortcut( "b4s-open" );
71         add_shortcut( "shout-b4s" );
72         set_capability( "demux2", 10 );
73         set_callbacks( E_(Import_B4S), E_(Close_B4S) );
74     add_submodule();
75         set_description( _("DVB playlist import") );
76         add_shortcut( "dvb-open" );
77         set_capability( "demux2", 10 );
78         set_callbacks( E_(Import_DVB), E_(Close_DVB) );
79     add_submodule();
80         set_description( _("Podcast parser") );
81         add_shortcut( "podcast" );
82         set_capability( "demux2", 10 );
83         set_callbacks( E_(Import_podcast), E_(Close_podcast) );
84     add_submodule();
85         set_description( _("XSPF playlist import") );
86         add_shortcut( "xspf-open" );
87         set_capability( "demux2", 10 );
88         set_callbacks( E_(xspf_import_Activate), NULL );
89     add_submodule();
90         set_description( _("New winamp 5.2 shoutcast import") );
91         add_shortcut( "shout-winamp" );
92         set_capability( "demux2", 10 );
93         set_callbacks( E_(Import_Shoutcast), E_(Close_Shoutcast) );
94         add_bool( "shoutcast-show-adult", VLC_FALSE, NULL,
95                    SHOW_ADULT_TEXT, SHOW_ADULT_LONGTEXT, VLC_FALSE );
96     add_submodule();
97         set_description( _("ASX playlist import") );
98         add_shortcut( "asx-open" );
99         set_capability( "demux2", 10 );
100         set_callbacks( E_(Import_ASX), E_(Close_ASX) );
101     add_submodule();
102         set_description( _("Kasenna MediaBase parser") );
103         add_shortcut( "sgimb" );
104         set_capability( "demux2", 10 );
105         set_callbacks( E_(Import_SGIMB), E_(Close_SGIMB) );
106     add_submodule();
107         set_description( _("QuickTime Media Link importer") );
108         add_shortcut( "qtl" );
109         set_capability( "demux2", 10 );
110         set_callbacks( E_(Import_QTL), E_(Close_QTL) );
111     add_submodule();
112         set_description( _("Google Video Playlist importer") );
113         add_shortcut( "gvp" );
114         set_capability( "demux2", 10 );
115         set_callbacks( E_(Import_GVP), E_(Close_GVP) );
116 vlc_module_end();
117
118
119 /**
120  * Find directory part of the path to the playlist file, in case of
121  * relative paths inside
122  */
123 char *E_(FindPrefix)( demux_t *p_demux )
124 {
125     char *psz_name;
126     char *psz_path = strdup( p_demux->psz_path );
127
128 #ifndef WIN32
129     psz_name = strrchr( psz_path, '/' );
130 #else
131     psz_name = strrchr( psz_path, '\\' );
132     if( !psz_name ) psz_name = strrchr( psz_path, '/' );
133 #endif
134     if( psz_name ) psz_name[1] = '\0';
135     else *psz_path = '\0';
136
137     return psz_path;
138 }
139
140 /**
141  * Add the directory part of the playlist file to the start of the
142  * mrl, if the mrl is a relative file path
143  */
144 char *E_(ProcessMRL)( char *psz_mrl, char *psz_prefix )
145 {
146     /* Check for a protocol name.
147      * for URL, we should look for "://"
148      * for MRL (Media Resource Locator) ([[<access>][/<demux>]:][<source>]),
149      * we should look for ":", so we end up looking simply for ":"
150      * PB: on some file systems, ':' are valid characters though */
151
152     /* Simple cases first */
153     if( !psz_mrl || !*psz_mrl ) return NULL;
154     if( !psz_prefix || !*psz_prefix ) return strdup( psz_mrl );
155
156     /* Check if the line specifies an absolute path */
157     if( *psz_mrl == '/' || *psz_mrl == '\\' ) return strdup( psz_mrl );
158
159     /* Check if the line specifies an mrl/url
160      * (and on win32, contains a drive letter) */
161     if( strchr( psz_mrl, ':' ) ) return strdup( psz_mrl );
162
163     /* This a relative path, prepend the prefix */
164     asprintf( &psz_mrl, "%s%s", psz_prefix, psz_mrl );
165     return psz_mrl;
166 }
167
168 void E_(AddToPlaylist)( demux_t *p_demux, playlist_t *p_playlist,
169                         input_item_t *p_input,
170                         playlist_item_t *p_item, int i_parent_id )
171 {
172     // Only add to parent if specific parent requested or not current
173     // playlist item
174    if( i_parent_id > 0 || ! (
175          p_playlist->status.p_item &&
176          p_playlist->status.p_item->p_input ==
177               ((input_thread_t *)p_demux->p_parent)->input.p_item ) )
178    {
179        playlist_NodeAddInput( p_playlist, p_input, p_item,
180                               PLAYLIST_APPEND, PLAYLIST_END );
181    }
182    // Else, add to both
183    else
184    {
185        playlist_BothAddInput( p_playlist, p_input, p_item,
186                               PLAYLIST_APPEND, PLAYLIST_END );
187    }
188    input_ItemCopyOptions( p_item->p_input, p_input );
189 }
190
191
192 vlc_bool_t E_(FindItem)( demux_t *p_demux, playlist_t *p_playlist,
193                      playlist_item_t **pp_item )
194 {
195      vlc_bool_t b_play = var_CreateGetBool( p_demux, "playlist-autostart" );
196
197      if( b_play && p_playlist->status.p_item &&
198              p_playlist->status.p_item->p_input ==
199                 ((input_thread_t *)p_demux->p_parent)->input.p_item )
200      {
201          msg_Dbg( p_playlist, "starting playlist playback" );
202          *pp_item = p_playlist->status.p_item;
203          b_play = VLC_TRUE;
204      }
205      else
206      {
207          input_item_t *p_current = ( (input_thread_t*)p_demux->p_parent)->
208                                                         input.p_item;
209          *pp_item = playlist_LockItemGetByInput( p_playlist, p_current );
210          if( !*pp_item )
211          {
212              msg_Dbg( p_playlist, "unable to find item in playlist");
213          }
214          msg_Dbg( p_playlist, "not starting playlist playback");
215          p_playlist->status.i_status = PLAYLIST_STOPPED;
216          b_play = VLC_FALSE;
217      }
218      return b_play;
219 }