Changeset 23458725ce766bcb7fd908b392948a1449a760c6
- Timestamp:
- 12/08/05 16:20:06
(3 years ago)
- Author:
- Christophe Mutricy <xtophe@videolan.org>
- git-committer:
- Christophe Mutricy <xtophe@videolan.org> 1123856406 +0000
- git-parent:
[cf08a571ced3bf3a2435207358ab0bdaf8f359f2]
- git-author:
- Christophe Mutricy <xtophe@videolan.org> 1123856406 +0000
- Message:
ALL: Improvements in the M3U output and parser. Patch by Daniel Stränger.
(Put both artist and name, protect comma with \ )
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r2c8f279 |
r2345872 |
|
| 32 | 32 | Damian Ivereigh <damian at cisco.com> - ac3dec uninitialized data structure fix |
|---|
| 33 | 33 | Damien Fouilleul <damien.fouilleul at laposte.net> - DirectShow input improvements |
|---|
| | 34 | Daniel Str�er <vlc at schmaller d0t de> - M3U improvements |
|---|
| 34 | 35 | David Kennedy <dkennedy at tinytoad.com> - X11 fullscreen patch |
|---|
| 35 | 36 | David Weber <david_weber at gmx.de> - Mac OS X interface design & graphics (v0.5.0) |
|---|
| r3cc8c40 |
r2345872 |
|
| 45 | 45 | static int Demux( demux_t *p_demux); |
|---|
| 46 | 46 | static int Control( demux_t *p_demux, int i_query, va_list args ); |
|---|
| | 47 | static void parseEXTINF( char *psz_string, char **ppsz_author, char **ppsz_name, int *pi_duration ); |
|---|
| 47 | 48 | |
|---|
| 48 | 49 | /***************************************************************************** |
|---|
| … | … | |
| 109 | 110 | char *psz_line; |
|---|
| 110 | 111 | |
|---|
| 111 | | char *psz_name = NULL; |
|---|
| 112 | | mtime_t i_duration = -1; |
|---|
| 113 | | char **ppsz_options = NULL; |
|---|
| 114 | | int i_options = 0, i; |
|---|
| | 112 | char *psz_name = NULL; |
|---|
| | 113 | char *psz_author = NULL; |
|---|
| | 114 | int i_parsed_duration = 0; |
|---|
| | 115 | mtime_t i_duration = -1; |
|---|
| | 116 | char **ppsz_options = NULL; |
|---|
| | 117 | int i_options = 0, i; |
|---|
| 115 | 118 | |
|---|
| 116 | 119 | playlist_item_t *p_item, *p_current; |
|---|
| … | … | |
| 156 | 159 | { |
|---|
| 157 | 160 | /* Extended info */ |
|---|
| 158 | | char *psz_duration; |
|---|
| 159 | 161 | psz_parse += sizeof("EXTINF:") - 1; |
|---|
| 160 | | while( *psz_parse == '\t' || *psz_parse == ' ' ) psz_parse++; |
|---|
| 161 | | |
|---|
| 162 | | psz_duration = psz_parse; |
|---|
| 163 | | psz_parse = strchr( psz_parse, ',' ); |
|---|
| 164 | | if( psz_parse ) |
|---|
| 165 | | { |
|---|
| 166 | | *psz_parse = '\0'; |
|---|
| 167 | | psz_parse++; |
|---|
| 168 | | psz_name = strdup( psz_parse ); |
|---|
| 169 | | i_duration = atoi( psz_duration ); |
|---|
| 170 | | if( i_duration != -1 ) i_duration *= 1000000; |
|---|
| 171 | | } |
|---|
| | 162 | parseEXTINF( psz_parse, &psz_author, &psz_name, &i_parsed_duration ); |
|---|
| | 163 | i_duration = i_parsed_duration * 1000000; |
|---|
| | 164 | if ( psz_name ) |
|---|
| | 165 | psz_name = strdup( psz_name ); |
|---|
| | 166 | if ( psz_author ) |
|---|
| | 167 | psz_author = strdup( psz_author ); |
|---|
| 172 | 168 | } |
|---|
| 173 | 169 | else if( !strncasecmp( psz_parse, "EXTVLCOPT:", |
|---|
| … | … | |
| 210 | 206 | } |
|---|
| 211 | 207 | p_item->input.i_duration = i_duration; |
|---|
| 212 | | |
|---|
| | 208 | if ( psz_author ) |
|---|
| | 209 | vlc_input_item_AddInfo( &p_item->input, _("Meta-information"), |
|---|
| | 210 | _("Artist"), "%s", psz_author ); |
|---|
| 213 | 211 | playlist_NodeAddItem( p_playlist, p_item, |
|---|
| 214 | 212 | p_current->pp_parents[0]->i_view, |
|---|
| … | … | |
| 241 | 239 | if( psz_name ) free( psz_name ); |
|---|
| 242 | 240 | psz_name = NULL; |
|---|
| | 241 | if ( psz_author ) free( psz_author ); |
|---|
| | 242 | psz_author = NULL; |
|---|
| | 243 | i_parsed_duration = 0; |
|---|
| 243 | 244 | i_duration = -1; |
|---|
| 244 | 245 | |
|---|
| … | … | |
| 265 | 266 | return VLC_EGENERIC; |
|---|
| 266 | 267 | } |
|---|
| | 268 | |
|---|
| | 269 | static void parseEXTINF(char *psz_string, char **ppsz_author, |
|---|
| | 270 | char **ppsz_name, int *pi_duration) |
|---|
| | 271 | { |
|---|
| | 272 | char *end=NULL; |
|---|
| | 273 | char *psz_item=NULL; |
|---|
| | 274 | |
|---|
| | 275 | end = psz_string + strlen( psz_string ); |
|---|
| | 276 | |
|---|
| | 277 | /* ignore whitespaces */ |
|---|
| | 278 | for (; psz_string < end && ( *psz_string == '\t' || *psz_string == ' ' ); |
|---|
| | 279 | psz_string++ ); |
|---|
| | 280 | |
|---|
| | 281 | /* read all digits */ |
|---|
| | 282 | psz_item = psz_string; |
|---|
| | 283 | while ( psz_string < end && *psz_string >= '0' && *psz_string <= '9' ) |
|---|
| | 284 | { |
|---|
| | 285 | psz_string++; |
|---|
| | 286 | } |
|---|
| | 287 | if ( *psz_item >= '0' && *psz_item <= '9' && *psz_string == ',' ) |
|---|
| | 288 | { |
|---|
| | 289 | *psz_string = '\0'; |
|---|
| | 290 | *pi_duration = atoi(psz_item); |
|---|
| | 291 | } |
|---|
| | 292 | else |
|---|
| | 293 | { |
|---|
| | 294 | return; |
|---|
| | 295 | } |
|---|
| | 296 | if ( psz_string < end ) /* continue parsing if possible */ |
|---|
| | 297 | { |
|---|
| | 298 | psz_string++; |
|---|
| | 299 | } |
|---|
| | 300 | |
|---|
| | 301 | /* read the author */ |
|---|
| | 302 | char *pos; |
|---|
| | 303 | /* parse the author until unescaped comma is reached */ |
|---|
| | 304 | psz_item = pos = psz_string; |
|---|
| | 305 | while( psz_string < end && *psz_string != ',' ) |
|---|
| | 306 | { |
|---|
| | 307 | if( *psz_string == '\\' ) |
|---|
| | 308 | psz_string++; /* Skip escape character */ |
|---|
| | 309 | *pos++ = *psz_string++; |
|---|
| | 310 | } |
|---|
| | 311 | *pos = '\0'; /* terminate the item */ |
|---|
| | 312 | *ppsz_author = psz_item; |
|---|
| | 313 | |
|---|
| | 314 | if( psz_string < end ) /* continue parsing if possible */ |
|---|
| | 315 | psz_string++; |
|---|
| | 316 | /* the title doesn't need to be escaped */ |
|---|
| | 317 | *ppsz_name = psz_string; |
|---|
| | 318 | |
|---|
| | 319 | return; |
|---|
| | 320 | } |
|---|
| | 321 | |
|---|
| rfe087a3 |
r2345872 |
|
| 69 | 69 | if( psz_author && *psz_author ) |
|---|
| 70 | 70 | { |
|---|
| 71 | | fprintf( p_export->p_file, "#EXTINF:%i,%s - %s\n", |
|---|
| 72 | | (int)(p_playlist->pp_items[i]->input.i_duration/1000000), |
|---|
| 73 | | psz_author, p_playlist->pp_items[i]->input.psz_name ); |
|---|
| | 71 | /* the author must be escaped if it contains a comma */ |
|---|
| | 72 | char *p_src; short i_cnt; |
|---|
| | 73 | /* so count the commas or backslash */ |
|---|
| | 74 | for( i_cnt = 0, p_src = psz_author; *p_src; p_src++ ) |
|---|
| | 75 | if(*p_src == ',' || *p_src == '\\' ) |
|---|
| | 76 | i_cnt++; |
|---|
| | 77 | /* Is there a comma ? */ |
|---|
| | 78 | if( i_cnt ) |
|---|
| | 79 | { |
|---|
| | 80 | char *psz_escaped=NULL; |
|---|
| | 81 | char *p_dst; |
|---|
| | 82 | psz_escaped = (char *)malloc( ( strlen( psz_author ) |
|---|
| | 83 | + i_cnt + 1 ) * sizeof( char ) ); |
|---|
| | 84 | if( !psz_escaped ) |
|---|
| | 85 | return VLC_ENOMEM; |
|---|
| | 86 | /* copy the string and escape every comma with backslash */ |
|---|
| | 87 | for( p_src=psz_author, p_dst=psz_escaped; *p_src; |
|---|
| | 88 | p_src++, p_dst++ ) |
|---|
| | 89 | { |
|---|
| | 90 | if( *p_src == ',' || *p_src == '\\' ) |
|---|
| | 91 | *p_dst++ = '\\'; |
|---|
| | 92 | *p_dst = *p_src; |
|---|
| | 93 | } |
|---|
| | 94 | *p_dst = '\0'; |
|---|
| | 95 | free( psz_author); |
|---|
| | 96 | psz_author = psz_escaped; |
|---|
| | 97 | } |
|---|
| | 98 | fprintf( p_export->p_file, "#EXTINF:%i,%s,%s\n", |
|---|
| | 99 | (int)(p_playlist->pp_items[i]->input.i_duration/1000000), |
|---|
| | 100 | psz_author, |
|---|
| | 101 | p_playlist->pp_items[i]->input.psz_name ); |
|---|
| 74 | 102 | } |
|---|
| 75 | 103 | else |
|---|
| 76 | 104 | { |
|---|
| 77 | | fprintf( p_export->p_file, "#EXTINF:%i,%s\n", |
|---|
| 78 | | (int)(p_playlist->pp_items[i]->input.i_duration/1000000), |
|---|
| | 105 | /* write EXTINF without author */ |
|---|
| | 106 | fprintf( p_export->p_file, "#EXTINF:%i,,%s\n", |
|---|
| | 107 | (int)(p_playlist->pp_items[i]->input.i_duration/1000000), |
|---|
| 79 | 108 | p_playlist->pp_items[i]->input.psz_name ); |
|---|
| 80 | 109 | } |
|---|
| 81 | | free(psz_author); |
|---|
| | 110 | if( psz_author ) |
|---|
| | 111 | free( psz_author ); |
|---|
| 82 | 112 | } |
|---|
| 83 | 113 | |
|---|