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>
37 /*****************************************************************************
39 *****************************************************************************/
40 static int ReadDir( stream_t
*, input_item_node_t
* );
42 /*****************************************************************************
43 * Import_PLS: main import function
44 *****************************************************************************/
45 int Import_PLS( vlc_object_t
*p_this
)
47 stream_t
*p_demux
= (stream_t
*)p_this
;
48 const uint8_t *p_peek
;
52 if( vlc_stream_Peek( p_demux
->s
, &p_peek
, 10 ) < 10 ) {
53 msg_Dbg( p_demux
, "not enough data" );
57 if( strncasecmp( (const char *)p_peek
, "[playlist]", 10 )
58 && strncasecmp( (const char *)p_peek
, "[Reference]", 10 )
59 && !stream_HasExtension( p_demux
, ".pls" ) )
62 msg_Dbg( p_demux
, "found valid PLS playlist file");
63 p_demux
->pf_readdir
= ReadDir
;
64 p_demux
->pf_control
= access_vaDirectoryControlHelper
;
69 static int ReadDir( stream_t
*p_demux
, input_item_node_t
*p_subitems
)
71 char *psz_name
= NULL
;
74 char *psz_mrl_orig
= NULL
;
78 input_item_t
*p_input
;
80 input_item_t
*p_current_input
= GetCurrentItem(p_demux
);
82 while( ( psz_line
= vlc_stream_ReadLine( p_demux
->s
) ) )
84 if( !strncasecmp( psz_line
, "[playlist]", sizeof("[playlist]")-1 ) ||
85 !strncasecmp( psz_line
, "[Reference]", sizeof("[Reference]")-1 ) )
91 psz_value
= strchr( psz_line
, '=' );
102 if( !strcasecmp( psz_key
, "version" ) )
104 msg_Dbg( p_demux
, "pls file version: %s", psz_value
);
108 if( !strcasecmp( psz_key
, "numberofentries" ) )
110 msg_Dbg( p_demux
, "pls should have %d entries", atoi(psz_value
) );
115 /* find the number part of of file1, title1 or length1 etc */
117 if( sscanf( psz_key
, "%*[^0-9]%d", &i_new_item
) != 1 )
119 msg_Warn( p_demux
, "couldn't find number of items" );
126 else if( i_item
!= i_new_item
)
128 /* we found a new item, insert the previous */
131 p_input
= input_item_New( psz_mrl
, psz_name
);
132 input_item_CopyOptions( p_input
, p_current_input
);
133 input_item_node_AppendItem( p_subitems
, p_input
);
134 input_item_Release( p_input
);
135 free( psz_mrl_orig
);
136 psz_mrl_orig
= psz_mrl
= NULL
;
140 msg_Warn( p_demux
, "no file= part found for item %d", i_item
);
147 if( !strncasecmp( psz_key
, "file", sizeof("file") -1 ) ||
148 !strncasecmp( psz_key
, "Ref", sizeof("Ref") -1 ) )
150 free( psz_mrl_orig
);
152 psz_mrl
= ProcessMRL( psz_value
, p_demux
->psz_url
);
154 if( !strncasecmp( psz_key
, "Ref", sizeof("Ref") -1 ) )
156 if( !strncasecmp( psz_mrl
, "http://", sizeof("http://") -1 ) )
157 memcpy( psz_mrl
, "mmsh", 4 );
160 else if( !strncasecmp( psz_key
, "title", sizeof("title") -1 ) )
163 psz_name
= strdup( psz_value
);
165 else if( !strncasecmp( psz_key
, "length", sizeof("length") -1 ) )
166 /* duration in seconds */;
169 msg_Warn( p_demux
, "unknown key found in pls file: %s", psz_key
);
173 /* Add last object */
176 p_input
= input_item_New( psz_mrl
, psz_name
);
177 input_item_CopyOptions( p_input
, p_current_input
);
178 input_item_node_AppendItem( p_subitems
, p_input
);
179 input_item_Release( p_input
);
180 free( psz_mrl_orig
);
184 msg_Warn( p_demux
, "no file= part found for item %d", i_item
);