1 /*****************************************************************************
2 * pls.c : PLS playlist format import
3 *****************************************************************************
4 * Copyright (C) 2004 VLC authors and VideoLAN
7 * Authors: Clément Stenac <zorglub@videolan.org>
8 * Authors: Sigmund Augdal Helberg <dnumgis@videolan.org>
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU Lesser General Public License as published by
12 * the Free Software Foundation; either version 2.1 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with this program; if not, write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
32 #include <vlc_common.h>
33 #include <vlc_access.h>
34 #include <vlc_charset.h>
38 /*****************************************************************************
40 *****************************************************************************/
41 static int ReadDir( stream_t
*, input_item_node_t
* );
43 /*****************************************************************************
44 * Import_PLS: main import function
45 *****************************************************************************/
46 int Import_PLS( vlc_object_t
*p_this
)
48 stream_t
*p_demux
= (stream_t
*)p_this
;
49 const uint8_t *p_peek
;
53 if( vlc_stream_Peek( p_demux
->s
, &p_peek
, 10 ) < 10 ) {
54 msg_Dbg( p_demux
, "not enough data" );
58 if( strncasecmp( (const char *)p_peek
, "[playlist]", 10 )
59 && strncasecmp( (const char *)p_peek
, "[Reference]", 10 )
60 && !stream_HasExtension( p_demux
, ".pls" ) )
63 msg_Dbg( p_demux
, "found valid PLS playlist file");
64 p_demux
->pf_readdir
= ReadDir
;
65 p_demux
->pf_control
= access_vaDirectoryControlHelper
;
70 static int ReadDir( stream_t
*p_demux
, input_item_node_t
*p_subitems
)
72 char *psz_name
= NULL
;
75 char *psz_mrl_orig
= NULL
;
79 input_item_t
*p_input
;
83 input_item_t
*p_current_input
= GetCurrentItem(p_demux
);
85 while( ( psz_line
= vlc_stream_ReadLine( p_demux
->s
) ) )
87 if (ascii
&& !IsASCII(psz_line
))
89 unicode
= IsUTF8(psz_line
);
95 char *latin
= FromLatin1(psz_line
);
100 if( !strncasecmp( psz_line
, "[playlist]", sizeof("[playlist]")-1 ) ||
101 !strncasecmp( psz_line
, "[Reference]", sizeof("[Reference]")-1 ) )
107 psz_value
= strchr( psz_line
, '=' );
118 if( !strcasecmp( psz_key
, "version" ) )
120 msg_Dbg( p_demux
, "pls file version: %s", psz_value
);
124 if( !strcasecmp( psz_key
, "numberofentries" ) )
126 msg_Dbg( p_demux
, "pls should have %d entries", atoi(psz_value
) );
131 /* find the number part of of file1, title1 or length1 etc */
133 if( sscanf( psz_key
, "%*[^0-9]%d", &i_new_item
) != 1 )
135 msg_Warn( p_demux
, "couldn't find number of items" );
142 else if( i_item
!= i_new_item
)
144 /* we found a new item, insert the previous */
147 p_input
= input_item_New( psz_mrl
, psz_name
);
148 input_item_CopyOptions( p_input
, p_current_input
);
149 input_item_node_AppendItem( p_subitems
, p_input
);
150 input_item_Release( p_input
);
151 free( psz_mrl_orig
);
152 psz_mrl_orig
= psz_mrl
= NULL
;
156 msg_Warn( p_demux
, "no file= part found for item %d", i_item
);
163 if( !strncasecmp( psz_key
, "file", sizeof("file") -1 ) ||
164 !strncasecmp( psz_key
, "Ref", sizeof("Ref") -1 ) )
166 free( psz_mrl_orig
);
168 psz_mrl
= ProcessMRL( psz_value
, p_demux
->psz_url
);
170 if( !strncasecmp( psz_key
, "Ref", sizeof("Ref") -1 ) )
172 if( !strncasecmp( psz_mrl
, "http://", sizeof("http://") -1 ) )
173 memcpy( psz_mrl
, "mmsh", 4 );
176 else if( !strncasecmp( psz_key
, "title", sizeof("title") -1 ) )
179 psz_name
= strdup( psz_value
);
181 else if( !strncasecmp( psz_key
, "length", sizeof("length") -1 ) )
182 /* duration in seconds */;
185 msg_Warn( p_demux
, "unknown key found in pls file: %s", psz_key
);
189 /* Add last object */
192 p_input
= input_item_New( psz_mrl
, psz_name
);
193 input_item_CopyOptions( p_input
, p_current_input
);
194 input_item_node_AppendItem( p_subitems
, p_input
);
195 input_item_Release( p_input
);
196 free( psz_mrl_orig
);
200 msg_Warn( p_demux
, "no file= part found for item %d", i_item
);