]> git.sesse.net Git - vlc/blob - modules/demux/playlist/playlist.c
* Stringreview !!!
[vlc] / modules / demux / playlist / playlist.c
1 /*****************************************************************************
2  * playlist.c :  Playlist import module
3  *****************************************************************************
4  * Copyright (C) 2004 VideoLAN
5  * $Id: playlist.c,v 1.3 2004/01/25 20:05:29 hartman Exp $
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 "ninput.h"
29
30 #include "playlist.h"
31
32 /*****************************************************************************
33  * Module descriptor
34  *****************************************************************************/
35 vlc_module_begin();
36     add_shortcut( "playlist" );
37
38     set_description( _("Old playlist open") );
39     add_shortcut( "old-open" );
40     set_capability( "demux2" , 10 );
41     set_callbacks( Import_Old , NULL );
42
43     add_submodule();
44         set_description( _("M3U playlist import") );
45         add_shortcut( "m3u-open" );
46         set_capability( "demux2" , 10 );
47         set_callbacks( Import_M3U , Close_M3U );
48     add_submodule();
49         set_description( _("PLS playlist import") );
50         add_shortcut( "pls-open" );
51         set_capability( "demux2" , 10 );
52         set_callbacks( Import_PLS , Close_PLS );
53 vlc_module_end();
54
55
56 /**
57  * Find directory part of the path to the playlist file, in case of
58  * relative paths inside
59  */
60 char *FindPrefix( demux_t *p_demux )
61 {
62     char *psz_name;
63     char *psz_path = strdup( p_demux->psz_path );
64
65 #ifndef WIN32
66     psz_name = strrchr( psz_path, '/' );
67 #else
68     psz_name = strrchr( psz_path, '\\' );
69     if ( ! psz_name ) psz_name = strrchr( psz_path, '/' );
70 #endif
71     if( psz_name ) *psz_name = '\0';
72     else *psz_path = '\0';
73     return psz_path;
74 }
75
76 /**
77  * Add the directory part of the playlist file to the start of the
78  * mrl, if the mrl is a relative file path
79  */
80 char *ProcessMRL( char *psz_mrl, char *psz_prefix )
81 {
82     char *psz_name;
83     /* check for a protocol name */
84     /* for URL, we should look for "://"
85      * for MRL (Media Resource Locator) ([[<access>][/<demux>]:][<source>]),
86      * we should look for ":"
87      * so we end up looking simply for ":"*/
88     /* PB: on some file systems, ':' are valid characters though*/
89     psz_name = psz_mrl;
90     while( *psz_name && *psz_name!=':' )
91     {
92         psz_name++;
93     }
94 #ifdef WIN32
95     if ( *psz_name && ( psz_name == psz_mrl + 1 ) )
96     {
97         /* if it is not an URL,
98          * as it is unlikely to be an MRL (PB: if it is ?)
99          * it should be an absolute file name with the drive letter */
100         if ( *(psz_name+1) == '/' )/* "*:/" */
101         {
102             if ( *(psz_name+2) != '/' )/* not "*://" */
103                 while ( *psz_name ) *psz_name++;/* so now (*psz_name==0) */
104         }
105         else while ( *psz_name ) *psz_name++;/* "*:*"*/
106     }
107 #endif
108
109     /* if the line doesn't specify a protocol name,
110      * check if the line has an absolute or relative path */
111 #ifndef WIN32
112     if( !*psz_name && *psz_mrl != '/' )
113          /* If this line doesn't begin with a '/' */
114 #else
115     if( !*psz_name
116             && *psz_mrl!='/'
117             && *psz_mrl!='\\'
118             && *(psz_mrl+1)!=':' )
119          /* if this line doesn't begin with
120           *  "/" or "\" or "*:" or "*:\" or "*:/" or "\\" */
121 #endif
122     {
123 #ifndef WIN32
124         psz_name = malloc( strlen(psz_prefix) + strlen(psz_mrl) + 2 );
125         sprintf( psz_name, "%s/%s", psz_prefix, psz_mrl );
126 #else
127         if ( *p_m3u->psz_prefix != '\0' )
128         {
129             psz_name = malloc( strlen(psz_prefix) + strlen(psz_mrl) + 2 );
130             sprintf( psz_name, "%s\\%s", psz_prefix, psz_mrl );
131         }
132         else psz_name = strdup( psz_mrl );
133 #endif
134     }
135     else
136     {
137         psz_name = strdup( psz_mrl );
138     }
139     return psz_name;
140 }
141