]> git.sesse.net Git - vlc/blob - modules/demux/playlist/asx.c
4f990706a93945b6865cf0c16d4561b95690cc96
[vlc] / modules / demux / playlist / asx.c
1 /*****************************************************************************
2  * asx.c : ASX playlist format import
3  *****************************************************************************
4  * Copyright (C) 2005-2006 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Derk-Jan Hartman <hartman at videolan dot org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 /* See also: http://msdn.microsoft.com/library/en-us/wmplay10/mmp_sdk/windowsmediametafilereference.asp
25  */
26
27 /*****************************************************************************
28  * Preamble
29  *****************************************************************************/
30 #ifdef HAVE_CONFIG_H
31 # include "config.h"
32 #endif
33
34 #include <vlc_common.h>
35 #include <vlc_demux.h>
36
37 #include <ctype.h>
38 #include <vlc_charset.h>
39 #include "playlist.h"
40 #include <vlc_meta.h>
41
42 struct demux_sys_t
43 {
44     char    *psz_prefix;
45     char    *psz_data;
46     int64_t i_data_len;
47     bool b_utf8;
48     bool b_skip_ads;
49 };
50
51 /*****************************************************************************
52  * Local prototypes
53  *****************************************************************************/
54 static int Demux( demux_t *p_demux);
55 static int Control( demux_t *p_demux, int i_query, va_list args );
56
57 static int StoreString( demux_t *p_demux, char **ppsz_string,
58                         const char *psz_source_start,
59                         const char *psz_source_end )
60 {
61     demux_sys_t *p_sys = p_demux->p_sys;
62     unsigned len = psz_source_end - psz_source_start;
63
64     free( *ppsz_string );
65
66     char *buf = *ppsz_string = malloc ((len * (1 + !p_sys->b_utf8)) + 1);
67     if (buf == NULL)
68         return VLC_ENOMEM;
69
70     if( p_sys->b_utf8 )
71     {
72         memcpy (buf, psz_source_start, len);
73         (*ppsz_string)[len] = '\0';
74         EnsureUTF8 (*ppsz_string);
75     }
76     else
77     {
78         /* Latin-1 -> UTF-8 */
79         for (unsigned i = 0; i < len; i++)
80         {
81             unsigned char c = psz_source_start[i];
82             if (c & 0x80)
83             {
84                 *buf++ = 0xc0 | (c >> 6);
85                 *buf++ = 0x80 | (c & 0x3f);
86             }
87             else
88                 *buf++ = c;
89         }
90         *buf++ = '\0';
91
92         buf = realloc (*ppsz_string, buf - *ppsz_string);
93         if( buf )
94             *ppsz_string = buf;
95     }
96     return VLC_SUCCESS;
97 }
98
99 static char *SkipBlanks(char *s, size_t i_strlen )
100 {
101     while( i_strlen > 0 ) {
102         switch( *s )
103         {
104             case ' ':
105             case '\t':
106             case '\r':
107             case '\n':
108                 --i_strlen;
109                 ++s;
110                 break;
111             default:
112                 i_strlen = 0;
113         }
114     }
115     return s;
116 }
117
118 static int ParseTime(char *s, size_t i_strlen)
119 {
120     // need to parse hour:minutes:sec.fraction string
121     int result = 0;
122     int val;
123     const char *end = s + i_strlen;
124     // skip leading spaces if any
125     s = SkipBlanks(s, i_strlen);
126
127     val = 0;
128     while( (s < end) && isdigit(*s) )
129     {
130         int newval = val*10 + (*s - '0');
131         if( newval < val )
132         {
133             // overflow
134             val = 0;
135             break;
136         }
137         val = newval;
138         ++s;
139     }
140     result = val;
141     s = SkipBlanks(s, end-s);
142     if( *s == ':' )
143     {
144         ++s;
145         s = SkipBlanks(s, end-s);
146         result = result * 60;
147         val = 0;
148         while( (s < end) && isdigit(*s) )
149         {
150             int newval = val*10 + (*s - '0');
151             if( newval < val )
152             {
153                 // overflow
154                 val = 0;
155                 break;
156             }
157             val = newval;
158             ++s;
159         }
160         result += val;
161         s = SkipBlanks(s, end-s);
162         if( *s == ':' )
163         {
164             ++s;
165             s = SkipBlanks(s, end-s);
166             result = result * 60;
167             val = 0;
168             while( (s < end) && isdigit(*s) )
169             {
170                 int newval = val*10 + (*s - '0');
171                 if( newval < val )
172                 {
173                     // overflow
174                     val = 0;
175                     break;
176                 }
177                 val = newval;
178                 ++s;
179             }
180             result += val;
181             // TODO: one day, we may need to parse fraction for sub-second resolution
182         }
183     }
184     return result;
185 }
186
187 /*****************************************************************************
188  * Import_ASX: main import function
189  *****************************************************************************/
190 int Import_ASX( vlc_object_t *p_this )
191 {
192     demux_t *p_demux = (demux_t *)p_this;
193     const uint8_t *p_peek;
194     CHECK_PEEK( p_peek, 10 );
195
196     // skip over possible leading empty lines and empty spaces
197     p_peek = (uint8_t *)SkipBlanks((char *)p_peek, 6);
198
199     if( POKE( p_peek, "<asx", 4 ) || demux_IsPathExtension( p_demux, ".asx" ) ||
200         demux_IsPathExtension( p_demux, ".wax" ) || demux_IsPathExtension( p_demux, ".wvx" ) ||
201         demux_IsForced( p_demux, "asx-open" ) )
202     {
203         ;
204     }
205     else
206         return VLC_EGENERIC;
207
208     STANDARD_DEMUX_INIT_MSG( "found valid ASX playlist" );
209     p_demux->p_sys->psz_prefix = FindPrefix( p_demux );
210     p_demux->p_sys->psz_data = NULL;
211     p_demux->p_sys->i_data_len = -1;
212     p_demux->p_sys->b_utf8 = false;
213     p_demux->p_sys->b_skip_ads = config_GetInt( p_demux, "playlist-skip-ads" );
214
215     return VLC_SUCCESS;
216 }
217
218 /*****************************************************************************
219  * Deactivate: frees unused data
220  *****************************************************************************/
221 void Close_ASX( vlc_object_t *p_this )
222 {
223     demux_t *p_demux = (demux_t *)p_this;
224     demux_sys_t *p_sys = p_demux->p_sys;
225
226     free( p_sys->psz_prefix );
227     free( p_sys->psz_data );
228     free( p_sys );
229 }
230
231 static int Demux( demux_t *p_demux )
232 {
233     demux_sys_t *p_sys = p_demux->p_sys;
234     char        *psz_parse = NULL;
235     char        *psz_backup = NULL;
236     bool  b_entry = false;
237     input_item_t *p_current_input = GetCurrentItem(p_demux);
238
239     /* init txt */
240     if( p_sys->i_data_len < 0 )
241     {
242         int64_t i_pos = 0;
243         p_sys->i_data_len = stream_Size( p_demux->s ) + 1; /* This is a cheat to prevent unnecessary realloc */
244         if( p_sys->i_data_len <= 0 || p_sys->i_data_len > 16384 ) p_sys->i_data_len = 1024;
245         p_sys->psz_data = malloc( p_sys->i_data_len +1);
246
247         /* load the complete file */
248         for( ;; )
249         {
250             int i_read = stream_Read( p_demux->s, &p_sys->psz_data[i_pos], p_sys->i_data_len - i_pos );
251             p_sys->psz_data[i_pos + i_read] = '\0';
252
253             if( i_read < p_sys->i_data_len - i_pos ) break; /* Done */
254
255             i_pos += i_read;
256             p_sys->i_data_len <<= 1 ;
257             p_sys->psz_data = realloc( p_sys->psz_data, p_sys->i_data_len * sizeof( char * ) + 1 );
258         }
259         if( p_sys->i_data_len <= 0 ) return -1;
260     }
261
262     psz_parse = p_sys->psz_data;
263     /* Find first element */
264     if( ( psz_parse = strcasestr( psz_parse, "<ASX" ) ) )
265     {
266         /* ASX element */
267         char *psz_string = NULL;
268         int i_strlen = 0;
269
270         char *psz_base_asx = NULL;
271         char *psz_title_asx = NULL;
272         char *psz_artist_asx = NULL;
273         char *psz_copyright_asx = NULL;
274         char *psz_moreinfo_asx = NULL;
275         char *psz_abstract_asx = NULL;
276
277         char *psz_base_entry = NULL;
278         char *psz_title_entry = NULL;
279         char *psz_artist_entry = NULL;
280         char *psz_copyright_entry = NULL;
281         char *psz_moreinfo_entry = NULL;
282         char *psz_abstract_entry = NULL;
283         int i_entry_count = 0;
284         bool b_skip_entry = false;
285
286         char *psz_href = NULL;
287         int i_starttime = 0;
288         int i_duration = 0;
289
290         psz_parse = strcasestr( psz_parse, ">" );
291
292         while( psz_parse && ( psz_parse = strcasestr( psz_parse, "<" ) ) )
293         {
294             if( !strncasecmp( psz_parse, "<!--", 4 ) )
295             {
296                 /* this is a comment */
297                 if( ( psz_parse = strcasestr( psz_parse, "-->" ) ) )
298                     psz_parse+=3;
299                 else continue;
300             }
301             else if( !strncasecmp( psz_parse, "<PARAM ", 7 ) )
302             {
303                 bool b_encoding_flag = false;
304                 psz_parse = SkipBlanks(psz_parse+7, (unsigned)-1);
305                 if( !strncasecmp( psz_parse, "name", 4 ) )
306                 {
307                     if( ( psz_parse = strcasestr( psz_parse, "\"" ) ) )
308                     {
309                         psz_backup = ++psz_parse;
310                         if( ( psz_parse = strcasestr( psz_parse, "\"" ) ) )
311                         {
312                             i_strlen = psz_parse-psz_backup;
313                             if( i_strlen < 1 ) continue;
314                             msg_Dbg( p_demux, "param name strlen: %d", i_strlen);
315                             psz_string = malloc( i_strlen + 1);
316                             memcpy( psz_string, psz_backup, i_strlen );
317                             psz_string[i_strlen] = '\0';
318                             msg_Dbg( p_demux, "param name: %s", psz_string);
319                             b_encoding_flag = !strcasecmp( psz_string, "encoding" );
320                             free( psz_string );
321                         }
322                         else continue;
323                     }
324                     else continue;
325                 }
326                 psz_parse++;
327                 if( !strncasecmp( psz_parse, "value", 5 ) )
328                 {
329                     if( ( psz_parse = strcasestr( psz_parse, "\"" ) ) )
330                     {
331                         psz_backup = ++psz_parse;
332                         if( ( psz_parse = strcasestr( psz_parse, "\"" ) ) )
333                         {
334                             i_strlen = psz_parse-psz_backup;
335                             if( i_strlen < 1 ) continue;
336                             msg_Dbg( p_demux, "param value strlen: %d", i_strlen);
337                             psz_string = malloc( i_strlen +1);
338                             memcpy( psz_string, psz_backup, i_strlen );
339                             psz_string[i_strlen] = '\0';
340                             msg_Dbg( p_demux, "param value: %s", psz_string);
341                             if( b_encoding_flag && !strcasecmp( psz_string, "utf-8" ) ) p_sys->b_utf8 = true;
342                             free( psz_string );
343                         }
344                         else continue;
345                     }
346                     else continue;
347                 }
348                 if( ( psz_parse = strcasestr( psz_parse, "/>" ) ) )
349                     psz_parse += 2;
350                 else continue;
351             }
352             else if( !strncasecmp( psz_parse, "<BANNER", 7 ) )
353             {
354                 /* We skip this element */
355                 if( ( psz_parse = strcasestr( psz_parse, "</BANNER>" ) ) )
356                     psz_parse += 9;
357                 else continue;
358             }
359             else if( !strncasecmp( psz_parse, "<PREVIEWDURATION", 16 ) ||
360                      !strncasecmp( psz_parse, "<LOGURL", 7 ) ||
361                      !strncasecmp( psz_parse, "<Skin", 5 ) )
362             {
363                 /* We skip this element */
364                 if( ( psz_parse = strcasestr( psz_parse, "/>" ) ) )
365                     psz_parse += 2;
366                 else continue;
367             }
368             else if( !strncasecmp( psz_parse, "<BASE ", 6 ) )
369             {
370                 psz_parse = SkipBlanks(psz_parse+6, (unsigned)-1);
371                 if( !strncasecmp( psz_parse, "HREF", 4 ) )
372                 {
373                     if( ( psz_parse = strcasestr( psz_parse, "\"" ) ) )
374                     {
375                         psz_backup = ++psz_parse;
376                         if( ( psz_parse = strcasestr( psz_parse, "\"" ) ) )
377                         {
378                             StoreString( p_demux, (b_entry ? &psz_base_entry : &psz_base_asx), psz_backup, psz_parse );
379                         }
380                         else continue;
381                     }
382                     else continue;
383                 }
384                 if( ( psz_parse = strcasestr( psz_parse, "/>" ) ) )
385                     psz_parse += 2;
386                 else continue;
387             }
388             else if( !strncasecmp( psz_parse, "<TITLE>", 7 ) )
389             {
390                 psz_backup = psz_parse+=7;
391                 if( ( psz_parse = strcasestr( psz_parse, "</TITLE>" ) ) )
392                 {
393                     StoreString( p_demux, (b_entry ? &psz_title_entry : &psz_title_asx), psz_backup, psz_parse );
394                     psz_parse += 8;
395                 }
396                 else continue;
397             }
398             else if( !strncasecmp( psz_parse, "<Author>", 8 ) )
399             {
400                 psz_backup = psz_parse+=8;
401                 if( ( psz_parse = strcasestr( psz_parse, "</Author>" ) ) )
402                 {
403                     StoreString( p_demux, (b_entry ? &psz_artist_entry : &psz_artist_asx), psz_backup, psz_parse );
404                     psz_parse += 9;
405                 }
406                 else continue;
407             }
408             else if( !strncasecmp( psz_parse, "<Copyright", 10 ) )
409             {
410                 psz_backup = psz_parse+=11;
411                 if( ( psz_parse = strcasestr( psz_parse, "</Copyright>" ) ) )
412                 {
413                     StoreString( p_demux, (b_entry ? &psz_copyright_entry : &psz_copyright_asx), psz_backup, psz_parse );
414                     psz_parse += 12;
415                 }
416                 else continue;
417             }
418             else if( !strncasecmp( psz_parse, "<MoreInfo ", 10 ) )
419             {
420                 psz_parse = SkipBlanks(psz_parse+10, (unsigned)-1);
421                 if( !strncasecmp( psz_parse, "HREF", 4 ) )
422                 {
423                     if( ( psz_parse = strcasestr( psz_parse, "\"" ) ) )
424                     {
425                         psz_backup = ++psz_parse;
426                         if( ( psz_parse = strcasestr( psz_parse, "\"" ) ) )
427                         {
428                             StoreString( p_demux, (b_entry ? &psz_moreinfo_entry : &psz_moreinfo_asx), psz_backup, psz_parse );
429                         }
430                         else continue;
431                     }
432                     else continue;
433                 }
434                 if( ( psz_parse = strcasestr( psz_parse, "/>" ) ) )
435                     psz_parse += 2;
436                 else if( ( psz_parse = strcasestr( psz_parse, "</MoreInfo>") ) )
437                     psz_parse += 11;
438                 else continue;
439             }
440             else if( !strncasecmp( psz_parse, "<ABSTRACT>", 10 ) )
441             {
442                 psz_backup = psz_parse+=10;
443                 if( ( psz_parse = strcasestr( psz_parse, "</ABSTRACT>" ) ) )
444                 {
445                     StoreString( p_demux, (b_entry ? &psz_abstract_entry : &psz_abstract_asx), psz_backup, psz_parse );
446                     psz_parse += 11;
447                 }
448                 else continue;
449             }
450             else if( !strncasecmp( psz_parse, "<EntryRef ", 10 ) )
451             {
452                 psz_parse = SkipBlanks(psz_parse+10, (unsigned)-1);
453                 if( !strncasecmp( psz_parse, "HREF", 4 ) )
454                 {
455                     if( ( psz_parse = strcasestr( psz_parse, "\"" ) ) )
456                     {
457                         psz_backup = ++psz_parse;
458                         if( ( psz_parse = strcasestr( psz_parse, "\"" ) ) )
459                         {
460                             i_strlen = psz_parse-psz_backup;
461                             if( i_strlen < 1 ) continue;
462                             psz_string = malloc( i_strlen +1);
463                             memcpy( psz_string, psz_backup, i_strlen );
464                             psz_string[i_strlen] = '\0';
465                             input_item_t *p_input;
466                             p_input = input_item_New( p_demux, psz_string, psz_title_asx );
467                             input_item_CopyOptions( p_current_input, p_input );
468                             input_item_AddSubItem( p_current_input, p_input );
469                             vlc_gc_decref( p_input );
470                             free( psz_string );
471                         }
472                         else continue;
473                     }
474                     else continue;
475                 }
476                 if( ( psz_parse = strcasestr( psz_parse, "/>" ) ) )
477                     psz_parse += 2;
478                 else continue;
479             }
480             else if( !strncasecmp( psz_parse, "</Entry>", 8 ) )
481             {
482                 input_item_t *p_entry = NULL;
483                 char *psz_name = NULL;
484
485                 char * ppsz_options[2];
486                 int i_options = 0;
487
488                 /* add a new entry */
489                 psz_parse+=8;
490                 if( !b_entry )
491                 {
492                     msg_Err( p_demux, "end of entry without start?" );
493                     continue;
494                 }
495
496                 if( !psz_href )
497                 {
498                     msg_Err( p_demux, "entry without href?" );
499                     continue;
500                 }
501
502                 if( p_sys->b_skip_ads && b_skip_entry )
503                 {
504                     char *psz_current_input_name = input_item_GetName( p_current_input );
505
506                     msg_Dbg( p_demux, "skipped entry %d %s (%s)",
507                              i_entry_count,
508                              ( psz_title_entry ? psz_title_entry : psz_current_input_name ), psz_href );
509                     free( psz_current_input_name );
510                 }
511                 else
512                 {
513                     if( i_starttime || i_duration )
514                     {
515                         if( i_starttime )
516                         {
517                             if( asprintf(ppsz_options+i_options, ":start-time=%d", i_starttime) == -1 )
518                                 *(ppsz_options+i_options) = NULL;
519                             else
520                                 ++i_options;
521                         }
522                         if( i_duration )
523                         {
524                             if( asprintf(ppsz_options+i_options, ":stop-time=%d", i_starttime + i_duration) == -1 )
525                                 *(ppsz_options+i_options) = NULL;
526                             else
527                                 ++i_options;
528                         }
529                     }
530
531                     /* create the new entry */
532                     char *psz_current_input_name = input_item_GetName( p_current_input );
533                     if( asprintf( &psz_name, "%d %s", i_entry_count, ( psz_title_entry ? psz_title_entry : psz_current_input_name ) ) != -1 )
534                     {
535                         char *psz_mrl = ProcessMRL( psz_href, p_demux->p_sys->psz_prefix );
536                         p_entry = input_item_NewExt( p_demux, psz_mrl, psz_name,
537                                                      i_options, (const char * const *)ppsz_options, VLC_INPUT_OPTION_TRUSTED, -1 );
538                         free( psz_name );
539                         free( psz_mrl );
540                         input_item_CopyOptions( p_current_input, p_entry );
541                         while( i_options )
542                         {
543                             psz_name = ppsz_options[--i_options];
544                             free( psz_name );
545                         }
546                         psz_name = NULL;
547
548                         if( psz_title_entry ) input_item_SetTitle( p_entry, psz_title_entry );
549                         if( psz_artist_entry ) input_item_SetArtist( p_entry, psz_artist_entry );
550                         if( psz_copyright_entry ) input_item_SetCopyright( p_entry, psz_copyright_entry );
551                         if( psz_moreinfo_entry ) input_item_SetURL( p_entry, psz_moreinfo_entry );
552                         if( psz_abstract_entry ) input_item_SetDescription( p_entry, psz_abstract_entry );
553                         input_item_AddSubItem( p_current_input, p_entry );
554                         vlc_gc_decref( p_entry );
555                     }
556                     free( psz_current_input_name );
557                 }
558
559                 /* cleanup entry */;
560                 FREENULL( psz_href );
561                 FREENULL( psz_title_entry );
562                 FREENULL( psz_base_entry );
563                 FREENULL( psz_artist_entry );
564                 FREENULL( psz_copyright_entry );
565                 FREENULL( psz_moreinfo_entry );
566                 FREENULL( psz_abstract_entry );
567                 b_entry = false;
568             }
569             else if( !strncasecmp( psz_parse, "<Entry", 6 ) )
570             {
571                 char *psz_clientskip;
572                 psz_parse+=6;
573                 if( b_entry )
574                 {
575                     msg_Err( p_demux, "We already are in an entry section" );
576                     continue;
577                 }
578                 i_entry_count += 1;
579                 b_entry = true;
580                 psz_clientskip = strcasestr( psz_parse, "clientskip=\"no\"" );
581                 psz_parse = strcasestr( psz_parse, ">" );
582
583                 /* If clientskip was enabled ... this is an ad */
584                 b_skip_entry = (NULL != psz_clientskip) && (psz_clientskip < psz_parse);
585
586                 // init entry details
587                 FREENULL(psz_href);
588                 i_starttime = 0;
589                 i_duration = 0;
590             }
591             else if( !strncasecmp( psz_parse, "<Ref ", 5 ) )
592             {
593                 psz_parse = SkipBlanks(psz_parse+5, (unsigned)-1);
594                 if( !b_entry )
595                 {
596                     msg_Err( p_demux, "A ref outside an entry section" );
597                     continue;
598                 }
599
600                 if( !strncasecmp( psz_parse, "HREF", 4 ) )
601                 {
602                     if( ( psz_parse = strcasestr( psz_parse, "\"" ) ) )
603                     {
604                         psz_backup = ++psz_parse;
605                         psz_backup = SkipBlanks(psz_backup, (unsigned)-1);
606                         if( ( psz_parse = strcasestr( psz_parse, "\"" ) ) )
607                         {
608                             char *psz_tmp;
609                             i_strlen = psz_parse-psz_backup;
610                             if( i_strlen < 1 ) continue;
611
612                             if( psz_href )
613                             {
614                                 /* we have allready one href in this entry, lets make new input from it and
615                                 continue with new href, don't free meta/options*/
616                                 input_item_t *p_entry = NULL;
617                                 char *psz_name = input_item_GetName( p_current_input );
618
619                                 char *psz_mrl = ProcessMRL( psz_href, p_demux->p_sys->psz_prefix );
620                                 p_entry = input_item_NewExt( p_demux, psz_mrl, psz_name,
621                                                      0, NULL, VLC_INPUT_OPTION_TRUSTED, -1 );
622                                 free( psz_mrl );
623                                 input_item_CopyOptions( p_current_input, p_entry );
624                                 if( psz_title_entry ) input_item_SetTitle( p_entry, psz_title_entry );
625                                 if( psz_artist_entry ) input_item_SetArtist( p_entry, psz_artist_entry );
626                                 if( psz_copyright_entry ) input_item_SetCopyright( p_entry, psz_copyright_entry );
627                                 if( psz_moreinfo_entry ) input_item_SetURL( p_entry, psz_moreinfo_entry );
628                                 if( psz_abstract_entry ) input_item_SetDescription( p_entry, psz_abstract_entry );
629                                 input_item_AddSubItem( p_current_input, p_entry );
630                                 vlc_gc_decref( p_entry );
631                             }
632
633                             free( psz_href );
634                             psz_href = malloc( i_strlen +1);
635                             memcpy( psz_href, psz_backup, i_strlen );
636                             psz_href[i_strlen] = '\0';
637                             psz_tmp = psz_href + (i_strlen-1);
638                             while( psz_tmp >= psz_href &&
639                                  ( *psz_tmp == '\r' || *psz_tmp == '\n' ) )
640                             {
641                                 *psz_tmp = '\0';
642                                 psz_tmp++;
643                             }
644                         }
645                         else continue;
646                     }
647                     else continue;
648                 }
649                 if( ( psz_parse = strcasestr( psz_parse, ">" ) ) )
650                     psz_parse++;
651                 else continue;
652             }
653             else if( !strncasecmp( psz_parse, "<starttime ", 11 ) )
654             {
655                 psz_parse = SkipBlanks(psz_parse+11, (unsigned)-1);
656                 if( !b_entry )
657                 {
658                     msg_Err( p_demux, "starttime outside an entry section" );
659                     continue;
660                 }
661
662                 if( !strncasecmp( psz_parse, "value", 5 ) )
663                 {
664                     if( ( psz_parse = strcasestr( psz_parse, "\"" ) ) )
665                     {
666                         psz_backup = ++psz_parse;
667                         if( ( psz_parse = strcasestr( psz_parse, "\"" ) ) )
668                         {
669                             i_strlen = psz_parse-psz_backup;
670                             if( i_strlen < 1 ) continue;
671
672                             i_starttime = ParseTime(psz_backup, i_strlen);
673                         }
674                         else continue;
675                     }
676                     else continue;
677                 }
678                 if( ( psz_parse = strcasestr( psz_parse, ">" ) ) )
679                     psz_parse++;
680                 else continue;
681             }
682             else if( !strncasecmp( psz_parse, "<duration ", 11 ) )
683             {
684                 psz_parse = SkipBlanks(psz_parse+5, (unsigned)-1);
685                 if( !b_entry )
686                 {
687                     msg_Err( p_demux, "duration outside an entry section" );
688                     continue;
689                 }
690
691                 if( !strncasecmp( psz_parse, "value", 5 ) )
692                 {
693                     if( ( psz_parse = strcasestr( psz_parse, "\"" ) ) )
694                     {
695                         psz_backup = ++psz_parse;
696                         if( ( psz_parse = strcasestr( psz_parse, "\"" ) ) )
697                         {
698                             i_strlen = psz_parse-psz_backup;
699                             if( i_strlen < 1 ) continue;
700
701                             i_duration = ParseTime(psz_backup, i_strlen);
702                         }
703                         else continue;
704                     }
705                     else continue;
706                 }
707                 if( ( psz_parse = strcasestr( psz_parse, ">" ) ) )
708                     psz_parse++;
709                 else continue;
710             }
711             else if( !strncasecmp( psz_parse, "</ASX", 5 ) )
712             {
713                 if( psz_title_asx ) input_item_SetTitle( p_current_input, psz_title_asx );
714                 if( psz_artist_asx ) input_item_SetArtist( p_current_input, psz_artist_asx );
715                 if( psz_copyright_asx ) input_item_SetCopyright( p_current_input, psz_copyright_asx );
716                 if( psz_moreinfo_asx ) input_item_SetURL( p_current_input, psz_moreinfo_asx );
717                 if( psz_abstract_asx ) input_item_SetDescription( p_current_input, psz_abstract_asx );
718                 FREENULL( psz_base_asx );
719                 FREENULL( psz_title_asx );
720                 FREENULL( psz_artist_asx );
721                 FREENULL( psz_copyright_asx );
722                 FREENULL( psz_moreinfo_asx );
723                 FREENULL( psz_abstract_asx );
724                 psz_parse++;
725             }
726             else psz_parse++;
727         }
728 #if 0
729 /* FIXME Unsupported elements */
730             PARAM
731             EVENT
732             REPEAT
733             ENDMARK
734             STARTMARK
735 #endif
736     }
737     vlc_gc_decref(p_current_input);
738     return 0; /* Needed for correct operation of go back */
739 }
740
741 static int Control( demux_t *p_demux, int i_query, va_list args )
742 {
743     VLC_UNUSED(p_demux); VLC_UNUSED(i_query); VLC_UNUSED(args);
744     return VLC_EGENERIC;
745 }