]> git.sesse.net Git - vlc/blob - modules/demux/playlist/playlist.c
Input options inheritance for playlists
[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 vlc_module_begin();
37     add_shortcut( "playlist" );
38
39     set_description( _("Old playlist open") );
40     add_shortcut( "old-open" );
41     set_capability( "demux2" , 10 );
42     set_callbacks( Import_Old , NULL );
43
44     add_submodule();
45     set_description( _("M3U playlist import") );
46     add_shortcut( "m3u-open" );
47     set_capability( "demux2" , 10 );
48     set_callbacks( Import_M3U , Close_M3U );
49
50     add_submodule();
51     set_description( _("PLS playlist import") );
52     add_shortcut( "pls-open" );
53     set_capability( "demux2" , 10 );
54     set_callbacks( Import_PLS , Close_PLS );
55 vlc_module_end();
56
57
58 /**
59  * Find directory part of the path to the playlist file, in case of
60  * relative paths inside
61  */
62 char *FindPrefix( demux_t *p_demux )
63 {
64     char *psz_name;
65     char *psz_path = strdup( p_demux->psz_path );
66
67 #ifndef WIN32
68     psz_name = strrchr( psz_path, '/' );
69 #else
70     psz_name = strrchr( psz_path, '\\' );
71     if( !psz_name ) psz_name = strrchr( psz_path, '/' );
72 #endif
73     if( psz_name ) psz_name[1] = '\0';
74     else *psz_path = '\0';
75
76     return psz_path;
77 }
78
79 /**
80  * Add the directory part of the playlist file to the start of the
81  * mrl, if the mrl is a relative file path
82  */
83 char *ProcessMRL( char *psz_mrl, char *psz_prefix )
84 {
85     /* Check for a protocol name.
86      * for URL, we should look for "://"
87      * for MRL (Media Resource Locator) ([[<access>][/<demux>]:][<source>]),
88      * we should look for ":", so we end up looking simply for ":"
89      * PB: on some file systems, ':' are valid characters though */
90
91     /* Simple cases first */
92     if( !psz_mrl || !*psz_mrl ) return NULL;
93     if( !psz_prefix || !*psz_prefix ) return strdup( psz_mrl );
94
95     /* Check if the line specifies an absolute path */
96     if( *psz_mrl == '/' || *psz_mrl == '\\' ) return strdup( psz_mrl );
97
98     /* Check if the line specifies an mrl/url
99      * (and on win32, contains a drive letter) */
100     if( strchr( psz_mrl, ':' ) ) return strdup( psz_mrl );
101
102     /* This a relative path, prepend the prefix */
103     asprintf( &psz_mrl, "%s%s", psz_prefix, psz_mrl );
104     return psz_mrl;
105 }
106
107 vlc_bool_t FindItem( demux_t *p_demux, playlist_t *p_playlist,
108                      playlist_item_t **pp_item )
109 {
110      vlc_bool_t b_play;
111      if( &p_playlist->status.p_item->input ==
112          ((input_thread_t *)p_demux->p_parent)->input.p_item )
113      {
114          msg_Dbg( p_playlist, "starting playlist playback" );
115          *pp_item = p_playlist->status.p_item;
116          b_play = VLC_TRUE;
117      }
118      else
119      {
120          input_item_t *p_current = ( (input_thread_t*)p_demux->p_parent)->
121                                                         input.p_item;
122          *pp_item = playlist_ItemGetByInput( p_playlist, p_current );
123          if( !*pp_item )
124          {
125              msg_Dbg( p_playlist, "unable to find item in playlist");
126          }
127          msg_Dbg( p_playlist, "not starting playlist playback");
128          b_play = VLC_FALSE;
129      }
130      return b_play;
131 }