asx.c
上传用户:kjfoods
上传日期:2020-07-06
资源大小:29949k
文件大小:26k
源码类别:

midi

开发平台:

Unix_Linux

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