/*****************************************************************************
* m3u.c: a meta demux to parse pls, m3u, asx et b4s playlists
*****************************************************************************
- * Copyright (C) 2001 VideoLAN
- * $Id: m3u.c,v 1.24 2003/08/14 13:02:55 sigmunau Exp $
+ * Copyright (C) 2001-2004 VideoLAN
+ * $Id$
*
* Authors: Sigmund Augdal <sigmunau@idi.ntnu.no>
* Gildas Bazin <gbazin@netcourrier.com>
/*****************************************************************************
* Constants and structures
*****************************************************************************/
-#define MAX_LINE 1024
+#define MAX_LINE 8192
#define TYPE_UNKNOWN 0
#define TYPE_M3U 1
* Module descriptor
*****************************************************************************/
vlc_module_begin();
- set_description( _("playlist metademux") );
+ set_description( _("Playlist metademux") );
set_capability( "demux", 180 );
set_callbacks( Activate, Deactivate );
add_shortcut( "m3u" );
psz_ext = strrchr ( p_input->psz_name, '.' );
if( ( psz_ext && !strcasecmp( psz_ext, ".m3u") ) ||
+ ( psz_ext && !strcasecmp( psz_ext, ".ram") ) || /* a .ram file can contain a single rtsp link */
( p_input->psz_demux && !strcmp(p_input->psz_demux, "m3u") ) )
{
i_type = TYPE_M3U;
/* we had no luck looking at the file extention, so we have a look
* at the content. This is useful for .asp, .php and similar files
- * that are actually html. Also useful for som asx files that have
- * another extention */
+ * that are actually html. Also useful for some asx files that have
+ * another extension */
/* XXX we double check for file != m3u as some asx ... are just m3u file */
if( i_type != TYPE_M3U )
{
{
i_type2 = TYPE_ASX;
}
+#if 0
else if ( !strncasecmp( p_peek, "<?xml", sizeof("<?xml") -1 ) )
{
i_type2 = TYPE_B4S;
}
+#endif
}
}
if ( i_type == TYPE_UNKNOWN && i_type2 == TYPE_UNKNOWN)
*dst = '\0';
}
-
/*****************************************************************************
* ParseLine: read a "line" from the file and add any entries found
* to the playlist. Returns:
* XXX psz_data has the same length that psz_line so no problem if you don't
* expand it
* psz_line is \0 terminated
- ******************************************************************************/
-static int ParseLine ( input_thread_t *p_input, char *psz_line, char *psz_data, vlc_bool_t *pb_next )
+ *****************************************************************************/
+static int ParseLine( input_thread_t *p_input, char *psz_line, char *psz_data,
+ vlc_bool_t *pb_next )
{
demux_sys_t *p_m3u = p_input->p_demux_data;
-
char *psz_bol, *psz_name;
psz_bol = psz_line;
if( *psz_bol == '#' )
{
while( *psz_bol &&
- strncasecmp( psz_bol, "EXTINF:", sizeof("EXTINF:") - 1 ) )
- psz_bol++;
+ strncasecmp( psz_bol, "EXTINF:",
+ sizeof("EXTINF:") - 1 ) &&
+ strncasecmp( psz_bol, "EXTVLCOPT:",
+ sizeof("EXTVLCOPT:") - 1 ) ) psz_bol++;
+
if( !*psz_bol ) return 0;
- psz_bol = strchr( psz_bol, ',' );
- if ( !psz_bol ) return 0;
- psz_bol++;
- /* From now, we have a name line */
+ if( !strncasecmp( psz_bol, "EXTINF:", sizeof("EXTINF:") - 1 ) )
+ {
+ psz_bol = strchr( psz_bol, ',' );
+ if ( !psz_bol ) return 0;
+ psz_bol++;
- strcpy( psz_data , psz_bol );
- return 2;
+ /* From now, we have a name line */
+ strcpy( psz_data , psz_bol );
+ return 2;
+ }
+ else
+ {
+ psz_bol = strchr( psz_bol, ':' );
+ if ( !psz_bol ) return 0;
+ psz_bol++;
+
+ strcpy( psz_data , psz_bol );
+ return 3;
+ }
}
/* If we don't have a comment, the line is directly the URI */
}
static void ProcessLine ( input_thread_t *p_input, playlist_t *p_playlist,
char *psz_line,
char **ppsz_uri, char **ppsz_name,
+ int *pi_options, char ***pppsz_options,
int *pi_position )
{
char psz_data[MAX_LINE];
}
*ppsz_name = strdup( psz_data );
break;
+ case 3:
+ (*pi_options)++;
+ *pppsz_options = realloc( *pppsz_options,
+ sizeof(char *) * *pi_options );
+ (*pppsz_options)[*pi_options - 1] = strdup( psz_data );
+ break;
case 0:
default:
break;
if( b_next && *ppsz_uri )
{
- playlist_AddExt( p_playlist, *ppsz_uri,
- *ppsz_name ? *ppsz_name : *ppsz_uri, -1,
- 0, 0, PLAYLIST_INSERT, *pi_position );
+ playlist_AddExt( p_playlist, *ppsz_uri, *ppsz_name,
+ PLAYLIST_INSERT, *pi_position,
+ -1, (const char **)*pppsz_options, *pi_options );
+
(*pi_position)++;
- if( *ppsz_name )
+ if( *ppsz_name ) free( *ppsz_name ); *ppsz_name = NULL;
+ free( *ppsz_uri ); *ppsz_uri = NULL;
+
+ for( ; *pi_options; (*pi_options)-- )
{
- free( *ppsz_name );
+ free( (*pppsz_options)[*pi_options - 1] );
+ if( *pi_options == 1 ) free( *pppsz_options );
}
- free( *ppsz_uri );
- *ppsz_name = NULL;
- *ppsz_uri = NULL;
+ *pppsz_options = NULL;
}
}
playlist_t *p_playlist;
vlc_bool_t b_discard = VLC_FALSE;
-
char *psz_name = NULL;
char *psz_uri = NULL;
+ int i_options = 0;
+ char **ppsz_options = NULL;
int i_position;
i_linepos = 0;
ProcessLine( p_input, p_playlist, psz_line, &psz_uri, &psz_name,
- &i_position );
+ &i_options, &ppsz_options, &i_position );
}
input_DeletePacket( p_input->p_method_data, p_data );
psz_line[i_linepos] = '\0';
ProcessLine( p_input, p_playlist, psz_line, &psz_uri, &psz_name,
- &i_position );
- /* is there a pendding uri without b_next */
+ &i_options, &ppsz_options, &i_position );
+
+ /* Is there a pendding uri without b_next */
if( psz_uri )
{
- playlist_Add( p_playlist, psz_uri, 0, 0,
- PLAYLIST_INSERT, i_position );
+ playlist_AddExt( p_playlist, psz_uri, psz_name,
+ PLAYLIST_INSERT, i_position,
+ -1, (const char **)ppsz_options, i_options );
}
}
- if( psz_uri )
- {
- free( psz_uri );
- }
- if( psz_name )
+ if( psz_uri ) free( psz_uri );
+ if( psz_name ) free( psz_name );
+ for( ; i_options; i_options-- )
{
- free( psz_name );
+ free( ppsz_options[i_options - 1] );
+ if( i_options == 1 ) free( ppsz_options );
}
vlc_object_release( p_playlist );