Commit 82c2d527 authored by yoann's avatar yoann
Browse files

* demux/playlist/xspf: skeleton for XSPF tree playlist import

parent 6bc1500f
/*******************************************************************************
* Copyright (C) 2006 Daniel Stränger <vlc at schmaller dot de>
* xspf.c : XSPF playlist import functions
*******************************************************************************
* Copyright (C) 2006 the VideoLAN team
* $Id$
*
* Authors: Daniel Stränger <vlc at schmaller dot de>
* Yoann Peronneau <yoann@videolan.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -33,6 +39,8 @@ struct demux_sys_t
{
playlist_item_t *p_item_in_category;
int i_parent_id;
input_item_t **pp_tracklist;
int i_tracklist_entries;
};
/**
......@@ -76,6 +84,8 @@ int xspf_import_Demux( demux_t *p_demux )
INIT_PLAYLIST_STUFF;
p_demux->p_sys->p_item_in_category = p_item_in_category;
p_demux->p_sys->i_parent_id = i_parent_id;
p_demux->p_sys->pp_tracklist = NULL;
p_demux->p_sys->i_tracklist_entries = 0;
/* create new xml parser from stream */
p_xml = xml_Create( p_demux );
......@@ -161,7 +171,7 @@ static vlc_bool_t parse_playlist_node COMPLEX_INTERFACE
{"attribution", COMPLEX_CONTENT, {.cmplx = skip_element} },
{"link", SIMPLE_CONTENT, {NULL} },
{"meta", SIMPLE_CONTENT, {NULL} },
{"extension", COMPLEX_CONTENT, {.cmplx = skip_element} },
{"extension", COMPLEX_CONTENT, {.cmplx = parse_extension_node} },
{"trackList", COMPLEX_CONTENT, {.cmplx = parse_tracklist_node} },
{NULL, UNKNOWN_CONTENT, {NULL} }
};
......@@ -179,7 +189,7 @@ static vlc_bool_t parse_playlist_node COMPLEX_INTERFACE
}
/* attribute: version */
if( !strcmp( psz_name, "version" ) )
{
{
b_version_found = VLC_TRUE;
if( strcmp( psz_value, "0" ) && strcmp( psz_value, "1" ) )
msg_Warn( p_demux, "unsupported XSPF version" );
......@@ -474,10 +484,14 @@ static vlc_bool_t parse_track_node COMPLEX_INTERFACE
{
FREE_ATT();
/* Add it */
playlist_AddWhereverNeeded( p_playlist, p_new_input,
/*playlist_AddWhereverNeeded( p_playlist, p_new_input,
p_item, p_demux->p_sys->p_item_in_category,
(p_demux->p_sys->i_parent_id >0 ) ? VLC_TRUE:
VLC_FALSE, PLAYLIST_APPEND );
VLC_FALSE, PLAYLIST_APPEND );*/
INSERT_ELEM( p_demux->p_sys->pp_tracklist,
p_demux->p_sys->i_tracklist_entries,
p_demux->p_sys->i_tracklist_entries,
p_new_input );
return VLC_TRUE;
}
/* there MUST have been a start tag for that element name */
......@@ -521,6 +535,9 @@ static vlc_bool_t parse_track_node COMPLEX_INTERFACE
return VLC_FALSE;
}
}
else if( !strcmp( p_handler->name, "identifier" ) )
{
}
else
{
/* there MUST be an item */
......@@ -594,6 +611,224 @@ static vlc_bool_t set_item_info SIMPLE_INTERFACE
return VLC_TRUE;
}
/**
* \brief parse the extension node of a XSPF playlist
*/
static vlc_bool_t parse_extension_node COMPLEX_INTERFACE
{
char *psz_name = NULL;
char *psz_value = NULL;
int i_node;
xml_elem_hnd_t *p_handler = NULL;
xml_elem_hnd_t pl_elements[] =
{ {"title", SIMPLE_CONTENT, {.cmplx = skip_element} },
{"node", COMPLEX_CONTENT, {.cmplx = parse_extension_node} },
{"item", COMPLEX_CONTENT, {.cmplx = parse_extitem_node} },
{NULL, UNKNOWN_CONTENT, {NULL} }
};
fprintf( stderr, " <node>\n" );
/* parse the child elements */
while( xml_ReaderRead( p_xml_reader ) == 1 )
{
i_node = xml_ReaderNodeType( p_xml_reader );
switch( i_node )
{
case XML_READER_NONE:
break;
case XML_READER_STARTELEM:
/* element start tag */
psz_name = xml_ReaderName( p_xml_reader );
if( !psz_name || !*psz_name )
{
msg_Err( p_demux, "invalid xml stream" );
FREE_ATT();
return VLC_FALSE;
}
/* choose handler */
for( p_handler = pl_elements;
p_handler->name && strcmp( psz_name, p_handler->name );
p_handler++ );
if( !p_handler->name )
{
msg_Err( p_demux, "unexpected element <%s>", psz_name );
FREE_ATT();
return VLC_FALSE;
}
FREE_NAME();
/* complex content is parsed in a separate function */
if( p_handler->type == COMPLEX_CONTENT )
{
if( p_handler->pf_handler.cmplx( p_demux,
p_playlist,
p_item, NULL,
p_xml_reader,
p_handler->name ) )
{
p_handler = NULL;
FREE_ATT();
}
else
{
FREE_ATT();
return VLC_FALSE;
}
}
break;
case XML_READER_TEXT:
/* simple element content */
FREE_ATT();
psz_value = xml_ReaderValue( p_xml_reader );
if( !psz_value )
{
msg_Err( p_demux, "invalid xml stream" );
FREE_ATT();
return VLC_FALSE;
}
break;
case XML_READER_ENDELEM:
/* element end tag */
psz_name = xml_ReaderName( p_xml_reader );
if( !psz_name )
{
msg_Err( p_demux, "invalid xml stream" );
FREE_ATT();
return VLC_FALSE;
}
/* leave if the current parent node is terminated */
if( !strcmp( psz_name, psz_element ) )
{
fprintf( stderr, " </node>\n" );
FREE_ATT();
return VLC_TRUE;
}
/* there MUST have been a start tag for that element name */
if( !p_handler || !p_handler->name
|| strcmp( p_handler->name, psz_name ))
{
msg_Err( p_demux, "there's no open element left for <%s>",
psz_name );
FREE_ATT();
return VLC_FALSE;
}
if( p_handler->pf_handler.smpl )
{
p_handler->pf_handler.smpl( p_item, NULL, p_handler->name,
psz_value );
}
FREE_ATT();
p_handler = NULL;
break;
default:
/* unknown/unexpected xml node */
msg_Err( p_demux, "unexpected xml node %i", i_node );
FREE_ATT();
return VLC_FALSE;
}
FREE_NAME();
}
return VLC_FALSE;
}
/**
* \brief parse the extension item node of a XSPF playlist
*/
static vlc_bool_t parse_extitem_node COMPLEX_INTERFACE
{
char *psz_name = NULL;
char *psz_value = NULL;
int i_node;
int i_href = -1;
/* read all playlist attributes */
while( xml_ReaderNextAttr( p_xml_reader ) == VLC_SUCCESS )
{
psz_name = xml_ReaderName( p_xml_reader );
psz_value = xml_ReaderValue( p_xml_reader );
if( !psz_name || !psz_value )
{
msg_Err( p_demux, "invalid xml stream @ <item>" );
FREE_ATT();
return VLC_FALSE;
}
/* attribute: href */
if( !strcmp( psz_name, "href" ) )
{
i_href = atoi( psz_value );
}
/* unknown attribute */
else
msg_Warn( p_demux, "invalid <item> attribute:\"%s\"", psz_name);
FREE_ATT();
}
/* attribute href is mandatory */
if( i_href < 0 )
{
msg_Warn( p_demux, "<item> requires \"href\" attribute" );
return VLC_FALSE;
}
if( i_href > p_demux->p_sys->i_tracklist_entries )
{
msg_Warn( p_demux, "invalid \"href\" attribute" );
return VLC_FALSE;
}
fprintf( stderr, " %s\n", p_demux->p_sys->pp_tracklist[i_href]->psz_name );
/* parse the child elements */
while( xml_ReaderRead( p_xml_reader ) == 1 )
{
i_node = xml_ReaderNodeType( p_xml_reader );
switch( i_node )
{
case XML_READER_NONE:
break;
case XML_READER_STARTELEM:
/* element start tag */
case XML_READER_TEXT:
/* simple element content */
msg_Err( p_demux, "invalid xml stream" );
return VLC_FALSE;
case XML_READER_ENDELEM:
/* element end tag */
psz_name = xml_ReaderName( p_xml_reader );
if( !psz_name )
{
msg_Err( p_demux, "invalid xml stream" );
FREE_ATT();
return VLC_FALSE;
}
/* leave if the current parent node is terminated */
if( !strcmp( psz_name, psz_element ) )
{
FREE_ATT();
return VLC_TRUE;
}
FREE_ATT();
break;
default:
/* unknown/unexpected xml node */
msg_Err( p_demux, "unexpected xml node %i", i_node );
FREE_ATT();
return VLC_FALSE;
}
FREE_NAME();
}
return VLC_FALSE;
}
/**
* \brief skips complex element content that we can't manage
*/
......
......@@ -47,6 +47,8 @@ int xspf_import_Control( demux_t *, int, va_list );
static vlc_bool_t parse_playlist_node COMPLEX_INTERFACE;
static vlc_bool_t parse_tracklist_node COMPLEX_INTERFACE;
static vlc_bool_t parse_track_node COMPLEX_INTERFACE;
static vlc_bool_t parse_extension_node COMPLEX_INTERFACE;
static vlc_bool_t parse_extitem_node COMPLEX_INTERFACE;
static vlc_bool_t set_item_info SIMPLE_INTERFACE;
static vlc_bool_t skip_element COMPLEX_INTERFACE;
static vlc_bool_t insert_new_item( playlist_t *, playlist_item_t *, playlist_item_t **, char *);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment