]> git.sesse.net Git - vlc/blobdiff - modules/demux/playlist/asx.c
Preparse playlist items that don't have enough meta
[vlc] / modules / demux / playlist / asx.c
index 5456de3eafd2da31b373dd3d90a6b82f98e9a838..a3d44aeaa4ad800876921294f78ae9575d9d9f24 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * asx.c : ASX playlist format import
  *****************************************************************************
- * Copyright (C) 2005 the VideoLAN team
+ * Copyright (C) 2005-2006 the VideoLAN team
  * $Id$
  *
  * Authors: Derk-Jan Hartman <hartman at videolan dot org>
@@ -53,29 +53,42 @@ struct demux_sys_t
 static int Demux( demux_t *p_demux);
 static int Control( demux_t *p_demux, int i_query, va_list args );
 
-static int StoreString( demux_t *p_demux, char **ppsz_string, char *psz_source_start, char *psz_source_end )
+static int StoreString( demux_t *p_demux, char **ppsz_string,
+                        const char *psz_source_start,
+                        const char *psz_source_end )
 {
     demux_sys_t *p_sys = p_demux->p_sys;
-    int i_strlen = psz_source_end-psz_source_start;
-    if( i_strlen < 1 )
-        return VLC_EGENERIC;
+    unsigned len = psz_source_end - psz_source_start;
 
     if( *ppsz_string ) free( *ppsz_string );
-    *ppsz_string = malloc( i_strlen*sizeof( char ) +1);
-    memcpy( *ppsz_string, psz_source_start, i_strlen );
-    (*ppsz_string)[i_strlen] = '\0';
+
+    char *buf = *ppsz_string = malloc ((len * (1 + !p_sys->b_utf8)) + 1);
+    if (buf == NULL)
+        return VLC_ENOMEM;
 
     if( p_sys->b_utf8 )
-        EnsureUTF8( *ppsz_string );
+    {
+        memcpy (buf, psz_source_start, len);
+        (*ppsz_string)[len] = '\0';
+        EnsureUTF8 (*ppsz_string);
+    }
     else
     {
-        char *psz_temp;
-        psz_temp = FromLocaleDup( *ppsz_string );
-        if( psz_temp )
+        /* Latin-1 -> UTF-8 */
+        for (unsigned i = 0; i < len; i++)
         {
-            free( *ppsz_string );
-            *ppsz_string = psz_temp;
-        } else EnsureUTF8( *ppsz_string );
+            unsigned char c = psz_source_start[i];
+            if (c & 0x80)
+            {
+                *buf++ = 0xc0 | (c >> 6);
+                *buf++ = 0x80 | (c & 0x3f);
+            }
+            else
+                *buf++ = c;
+        }
+        *buf++ = '\0';
+
+        buf = *ppsz_string = realloc (*ppsz_string, buf - *ppsz_string);
     }
     return VLC_SUCCESS;
 }
@@ -102,13 +115,13 @@ int E_(Import_ASX)( vlc_object_t *p_this )
     }
     else
         return VLC_EGENERIC;
-    
+
     STANDARD_DEMUX_INIT_MSG( "found valid ASX playlist" );
     p_demux->p_sys->psz_prefix = E_(FindPrefix)( p_demux );
     p_demux->p_sys->psz_data = NULL;
     p_demux->p_sys->i_data_len = -1;
     p_demux->p_sys->b_utf8 = VLC_FALSE;
-    
+
     return VLC_SUCCESS;
 }
 
@@ -131,7 +144,7 @@ static int Demux( demux_t *p_demux )
     char        *psz_parse = NULL;
     char        *psz_backup = NULL;
     vlc_bool_t  b_entry = VLC_FALSE;
-
+    input_item_t *p_input;
     INIT_PLAYLIST_STUFF;
 
     /* init txt */
@@ -355,9 +368,10 @@ static int Demux( demux_t *p_demux )
                             psz_string[i_strlen] = '\0';
                             p_input = input_ItemNew( p_playlist, psz_string, psz_title_asx );
                             input_ItemCopyOptions( p_current->p_input, p_input );
-                            playlist_AddWhereverNeeded( p_playlist, p_input, p_current,
-                                 p_item_in_category, (i_parent_id > 0 )? VLC_TRUE : VLC_FALSE,
-                                 PLAYLIST_APPEND );
+                            playlist_BothAddInput( p_playlist, p_input,
+                                                   p_item_in_category,
+                                            PLAYLIST_APPEND|PLAYLIST_SPREPARSE,
+                                            PLAYLIST_END );
                             free( psz_string );
                         }
                         else continue;
@@ -434,10 +448,10 @@ static int Demux( demux_t *p_demux )
                             if( psz_copyright_entry ) vlc_meta_SetCopyright( p_entry->p_meta, psz_copyright_entry );
                             if( psz_moreinfo_entry ) vlc_meta_SetURL( p_entry->p_meta, psz_moreinfo_entry );
                             if( psz_abstract_entry ) vlc_meta_SetDescription( p_entry->p_meta, psz_abstract_entry );
-                            
-                            playlist_AddWhereverNeeded( p_playlist, p_entry, p_current,
-                                p_item_in_category, (i_parent_id > 0 )? VLC_TRUE : VLC_FALSE,
-                                PLAYLIST_APPEND );
+                            playlist_BothAddInput( p_playlist, p_entry,
+                                                 p_item_in_category,
+                                                 PLAYLIST_APPEND | PLAYLIST_SPREPARSE
+                                                 , PLAYLIST_END);
                             free( psz_string );
                         }
                         else continue;
@@ -480,7 +494,7 @@ static int Demux( demux_t *p_demux )
 #endif
     }
     HANDLE_PLAY_AND_RELEASE;
-    return VLC_SUCCESS;
+    return -1; /* Needed for correct operation of go back */
 }
 
 static int Control( demux_t *p_demux, int i_query, va_list args )