diff -ud vlc-0.8.2/modules/demux/playlist/m3u.c vlc-0.8.2-neu/modules/demux/playlist/m3u.c --- vlc-0.8.2/modules/demux/playlist/m3u.c Sat Jun 25 15:43:06 2005 +++ vlc-0.8.2-neu/modules/demux/playlist/m3u.c Wed Aug 10 12:30:09 2005 @@ -44,6 +44,7 @@ *****************************************************************************/ static int Demux( demux_t *p_demux); static int Control( demux_t *p_demux, int i_query, va_list args ); +static void parseEXTINF( char *psz_string, char **ppsz_author, char **ppsz_name, int *pi_duration ); /***************************************************************************** * Import_M3U: main import function @@ -108,10 +109,12 @@ playlist_t *p_playlist; char *psz_line; - char *psz_name = NULL; - mtime_t i_duration = -1; - char **ppsz_options = NULL; - int i_options = 0, i; + char *psz_name = NULL; + char *psz_author = NULL; + int i_parsed_duration = 0; + mtime_t i_duration = -1; + char **ppsz_options = NULL; + int i_options = 0, i; playlist_item_t *p_item, *p_current; @@ -155,20 +158,13 @@ if( !strncasecmp( psz_parse, "EXTINF:", sizeof("EXTINF:") -1 ) ) { /* Extended info */ - char *psz_duration; psz_parse += sizeof("EXTINF:") - 1; - while( *psz_parse == '\t' || *psz_parse == ' ' ) psz_parse++; - - psz_duration = psz_parse; - psz_parse = strchr( psz_parse, ',' ); - if( psz_parse ) - { - *psz_parse = '\0'; - psz_parse++; - psz_name = strdup( psz_parse ); - i_duration = atoi( psz_duration ); - if( i_duration != -1 ) i_duration *= 1000000; - } + parseEXTINF( psz_parse, &psz_author, &psz_name, &i_parsed_duration ); + i_duration = i_parsed_duration * 1000000; + if ( psz_name ) + psz_name = strdup( psz_name ); + if ( psz_author ) + psz_author = strdup( psz_author ); } else if( !strncasecmp( psz_parse, "EXTVLCOPT:", sizeof("EXTVLCOPT:") -1 ) ) @@ -205,7 +201,9 @@ playlist_ItemAddOption( p_item, ppsz_options[i] ); } p_item->input.i_duration = i_duration; - + if ( psz_author ) + vlc_input_item_AddInfo( &p_item->input, _("Meta-information"), + _("Artist"), "%s", psz_author ); playlist_NodeAddItem( p_playlist, p_item, p_current->pp_parents[0]->i_view, p_current, PLAYLIST_APPEND, @@ -236,6 +234,9 @@ ppsz_options = NULL; i_options = 0; if( psz_name ) free( psz_name ); psz_name = NULL; + if ( psz_author ) free( psz_author ); + psz_author = NULL; + i_parsed_duration = 0; i_duration = -1; b_cleanup = VLC_FALSE; @@ -260,3 +261,51 @@ { return VLC_EGENERIC; } + +static void parseEXTINF(char *psz_string, char **ppsz_author, char **ppsz_name, int *pi_duration) +{ + char *end=NULL; + char *psz_item=NULL; + + /* do we have a TERMINATED string ? */ + end = psz_string + strnlen( psz_string, 1000 ); + if ( end - psz_string >= 1000 ) + return; + + /* ignore whitespaces */ + for (; psz_string < end && ( *psz_string == '\t' || *psz_string == ' ' ); psz_string++ ); + + /* read all digits */ + psz_item = psz_string; + while ( psz_string < end && *psz_string >= '0' && *psz_string <= '9' ) + psz_string++; + if ( *psz_item >= '0' && *psz_item <= '9' && *psz_string == ',' ) + { + *psz_string = '\0'; + *pi_duration = atoi(psz_item); + } else + return; + if ( psz_string < end ) /* continue parsing if possible */ + psz_string++; + + /* read the author */ + char *pos; + /* parse the author until unescaped comma is reached */ + psz_item = pos = psz_string; + while ( psz_string < end && *psz_string != ',' ) + { + if ( *psz_string == '\\' ) + psz_string++; /* Skip escape character */ + *pos++ = *psz_string++; + } + *pos = '\0'; /* terminate the item */ + *ppsz_author = psz_item; + + if ( psz_string < end ) /* continue parsing if possible */ + psz_string++; + /* the title doesn't need to be escaped */ + *ppsz_name = psz_string; + + return; +} + diff -ud vlc-0.8.2/modules/misc/playlist/m3u.c vlc-0.8.2-neu/modules/misc//playlist/m3u.c --- vlc-0.8.2/modules/misc/playlist/m3u.c Sat Jun 25 15:43:10 2005 +++ vlc-0.8.2-neu/modules/misc//playlist/m3u.c Mon Aug 8 15:12:55 2005 @@ -68,17 +68,49 @@ _("Meta-information"), _("Artist") ); if( psz_author && *psz_author ) { - fprintf( p_export->p_file, "#EXTINF:%i,%s - %s\n", - (int)(p_playlist->pp_items[i]->input.i_duration/1000000), - psz_author, p_playlist->pp_items[i]->input.psz_name ); + /* the author must be escaped if it contains a comma */ + char *p_src; int i_cnt; + /* so count the commas */ + for (i_cnt = 0, p_src = psz_author; *p_src; p_src++) + if (*p_src == ',' ) + i_cnt++; + /* Is there a comma ? */ + if ( i_cnt ) + { + char *psz_escaped=NULL; + char *p_dst; + psz_escaped = (char *)malloc( ( strlen( psz_author ) + i_cnt + 1 ) * sizeof( char ) ); + if ( !psz_escaped ) return VLC_ENOMEM; + /* copy the string and escape every comma with backslash */ + for ( p_src=psz_author, p_dst=psz_escaped; *p_src; p_src++, p_dst++ ) + { + if ( *p_src == ',' || *p_src == '\\' ) + *p_dst++ = '\\'; + *p_dst = *p_src; + } + *p_dst = '\0'; + /* write EXTINF with escaped author */ + fprintf( p_export->p_file, "#EXTINF:%i,%s,%s\n", + (int)(p_playlist->pp_items[i]->input.i_duration/1000000), + psz_escaped, p_playlist->pp_items[i]->input.psz_name ); + free( psz_escaped ); + } + else + { + /* write EXTINF with author without comma */ + fprintf( p_export->p_file, "#EXTINF:%i,%s,%s\n", + (int)(p_playlist->pp_items[i]->input.i_duration/1000000), + psz_author, p_playlist->pp_items[i]->input.psz_name ); + } } else { - fprintf( p_export->p_file, "#EXTINF:%i,%s\n", + /* write EXTINF without author */ + fprintf( p_export->p_file, "#EXTINF:%i,,%s\n", (int)(p_playlist->pp_items[i]->input.i_duration/1000000), p_playlist->pp_items[i]->input.psz_name ); } - free(psz_author); + free( psz_author ); } /* VLC specific options */