Commit b27904ab authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

XSPF export fixes and cleanup

 - XML encode everything (especially URL), not just some parameters,
 - use fputs() as appropriate,
 - remove a shadowed variable,
 - print duration as a 64-bits quantity.
parent 1422a735
...@@ -98,6 +98,16 @@ int xspf_export_playlist( vlc_object_t *p_this ) ...@@ -98,6 +98,16 @@ int xspf_export_playlist( vlc_object_t *p_this )
return VLC_SUCCESS; return VLC_SUCCESS;
} }
static char *input_xml( input_item_t *p_item, char *(*func)(input_item_t *) )
{
char *tmp = func( p_item );
if( tmp == NULL )
return NULL;
char *ret = convert_xml_special_chars( tmp );
free( tmp );
return ret;
}
/** /**
* \brief exports one item to file or traverse if item is a node * \brief exports one item to file or traverse if item is a node
* \param p_item playlist item to export * \param p_item playlist item to export
...@@ -107,50 +117,38 @@ int xspf_export_playlist( vlc_object_t *p_this ) ...@@ -107,50 +117,38 @@ int xspf_export_playlist( vlc_object_t *p_this )
static void xspf_export_item( playlist_item_t *p_item, FILE *p_file, static void xspf_export_item( playlist_item_t *p_item, FILE *p_file,
int *p_i_count ) int *p_i_count )
{ {
char *psz;
char *psz_temp;
int i;
mtime_t i_duration;
if( !p_item ) return; if( !p_item ) return;
/* if we get a node here, we must traverse it */ /* if we get a node here, we must traverse it */
if( p_item->i_children > 0 ) if( p_item->i_children > 0 )
{ {
int i; for( int i = 0; i < p_item->i_children; i++ )
for( i = 0; i < p_item->i_children; i++ )
{
xspf_export_item( p_item->pp_children[i], p_file, p_i_count ); xspf_export_item( p_item->pp_children[i], p_file, p_i_count );
}
return; return;
} }
/* don't write empty nodes */ /* don't write empty nodes */
if( p_item->i_children == 0 ) if( p_item->i_children == 0 )
{
return; return;
}
input_item_t *p_input = p_item->p_input;
char *psz;
mtime_t i_duration;
/* leaves can be written directly */ /* leaves can be written directly */
fprintf( p_file, "\t\t<track>\n" ); fputs( "\t\t<track>\n", p_file );
/* -> the location */ /* -> the location */
char *psz_uri = input_item_GetURI( p_item->p_input ); char *psz_uri = input_xml( p_input, input_item_GetURI );
if( psz_uri && *psz_uri ) if( psz_uri && *psz_uri )
fprintf( p_file, "\t\t\t<location>%s</location>\n", psz_uri ); fprintf( p_file, "\t\t\t<location>%s</location>\n", psz_uri );
/* -> the name/title (only if different from uri)*/ /* -> the name/title (only if different from uri)*/
char *psz_name = input_item_GetTitle( p_item->p_input ); psz = input_xml( p_input, input_item_GetTitle );
if( psz_name && psz_uri && strcmp( psz_uri, psz_name ) ) if( psz && strcmp( psz_uri, psz ) )
{ fprintf( p_file, "\t\t\t<title>%s</title>\n", psz );
psz_temp = convert_xml_special_chars( psz_name ); free( psz );
if( *psz_temp )
fprintf( p_file, "\t\t\t<title>%s</title>\n", psz_temp );
free( psz_temp );
}
free( psz_name );
free( psz_uri ); free( psz_uri );
if( p_item->p_input->p_meta == NULL ) if( p_item->p_input->p_meta == NULL )
...@@ -159,87 +157,64 @@ static void xspf_export_item( playlist_item_t *p_item, FILE *p_file, ...@@ -159,87 +157,64 @@ static void xspf_export_item( playlist_item_t *p_item, FILE *p_file,
} }
/* -> the artist/creator */ /* -> the artist/creator */
psz = input_item_GetArtist( p_item->p_input ); psz = input_xml( p_input, input_item_GetArtist );
if( psz == NULL ) psz = strdup( "" ); if( psz && *psz )
psz_temp = convert_xml_special_chars( psz ); fprintf( p_file, "\t\t\t<creator>%s</creator>\n", psz );
free( psz ); free( psz );
if( *psz_temp )
{
fprintf( p_file, "\t\t\t<creator>%s</creator>\n", psz_temp );
}
free( psz_temp );
/* -> the album */ /* -> the album */
psz = input_item_GetAlbum( p_item->p_input ); psz = input_xml( p_input, input_item_GetAlbum );
if( psz == NULL ) psz = strdup( "" ); if( psz && *psz )
psz_temp = convert_xml_special_chars( psz ); fprintf( p_file, "\t\t\t<album>%s</album>\n", psz );
free( psz ); free( psz );
if( *psz_temp )
{
fprintf( p_file, "\t\t\t<album>%s</album>\n", psz_temp );
}
free( psz_temp );
/* -> the track number */ /* -> the track number */
psz = input_item_GetTrackNum( p_item->p_input ); psz = input_xml( p_input, input_item_GetTrackNum );
if( psz == NULL ) psz = strdup( "" ); if( psz )
if( psz && *psz )
{ {
int i_tracknum = atoi( psz ); int i_tracknum = atoi( psz );
free( psz );
if( i_tracknum > 0 ) if( i_tracknum > 0 )
fprintf( p_file, "\t\t\t<trackNum>%i</trackNum>\n", i_tracknum ); fprintf( p_file, "\t\t\t<trackNum>%i</trackNum>\n", i_tracknum );
} }
free( psz );
/* -> the description */ /* -> the description */
psz = input_item_GetDescription( p_item->p_input ); psz = input_xml( p_input, input_item_GetDescription );
if( psz == NULL ) psz = strdup( "" ); if( psz && *psz )
psz_temp = convert_xml_special_chars( psz ); fprintf( p_file, "\t\t\t<annotation>%s</annotation>\n", psz );
free( psz ); free( psz );
if( *psz_temp )
{
fprintf( p_file, "\t\t\t<annotation>%s</annotation>\n", psz_temp );
}
free( psz_temp );
psz = input_item_GetArtURL( p_item->p_input ); psz = input_xml( p_input, input_item_GetArtURL );
if( psz == NULL ) psz = strdup( "" ); if( psz && *psz )
if( !EMPTY_STR( psz ) )
{
fprintf( p_file, "\t\t\t<image>%s</image>\n", psz ); fprintf( p_file, "\t\t\t<image>%s</image>\n", psz );
}
free( psz ); free( psz );
xspfexportitem_end: xspfexportitem_end:
/* -> the duration */ /* -> the duration */
i_duration = input_item_GetDuration( p_item->p_input ); i_duration = input_item_GetDuration( p_item->p_input );
if( i_duration > 0 ) if( i_duration > 0 )
{ fprintf( p_file, "\t\t\t<duration>%"PRIu64"</duration>\n",
fprintf( p_file, "\t\t\t<duration>%ld</duration>\n", i_duration / 1000 );
(long)(i_duration / 1000) );
}
/* export the intenal id and the input's options (bookmarks, ...) /* export the intenal id and the input's options (bookmarks, ...)
* in <extension> */ * in <extension> */
fprintf( p_file, "\t\t\t<extension application=\"" \ fputs( "\t\t\t<extension application=\""
"http://www.videolan.org/vlc/playlist/0\">\n" ); "http://www.videolan.org/vlc/playlist/0\">\n", p_file );
/* print the id and increase the counter */ /* print the id and increase the counter */
fprintf( p_file, "\t\t\t\t<vlc:id>%i</vlc:id>\n", *p_i_count ); fprintf( p_file, "\t\t\t\t<vlc:id>%i</vlc:id>\n", *p_i_count );
( *p_i_count )++; ( *p_i_count )++;
for( i = 0; i < p_item->p_input->i_options; i++ ) for( int i = 0; i < p_item->p_input->i_options; i++ )
{ {
fprintf( p_file, "\t\t\t\t<vlc:option>%s</vlc:option>\n", fprintf( p_file, "\t\t\t\t<vlc:option>%s</vlc:option>\n",
p_item->p_input->ppsz_options[i][0] == ':' ? p_item->p_input->ppsz_options[i][0] == ':' ?
p_item->p_input->ppsz_options[i] + 1 : p_item->p_input->ppsz_options[i] + 1 :
p_item->p_input->ppsz_options[i] ); p_item->p_input->ppsz_options[i] );
} }
fprintf( p_file, "\t\t\t</extension>\n" ); fputs( "\t\t\t</extension>\n", p_file );
fputs( "\t\t</track>\n", p_file );
fprintf( p_file, "\t\t</track>\n" );
return;
} }
/** /**
......
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