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