]> git.sesse.net Git - vlc/blobdiff - modules/misc/playlist/xspf.c
Renamed playlist "item-append/deleted" to "playlist-item-append/deleted".
[vlc] / modules / misc / playlist / xspf.c
index d854de27a471524d27c22d683f41d230b9249205..9bdfa43719c5c78dcc1ea01b0bb3160ef9c7cadf 100644 (file)
@@ -30,7 +30,7 @@
 # include "config.h"
 #endif
 
-#include <vlc/vlc.h>
+#include <vlc_common.h>
 #include <vlc_interface.h>
 #include <vlc_playlist.h>
 #include <vlc_input.h>
@@ -60,7 +60,8 @@ int xspf_export_playlist( vlc_object_t *p_this )
     /* write XSPF XML header */
     fprintf( p_export->p_file, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" );
     fprintf( p_export->p_file,
-             "<playlist version=\"1\" xmlns=\"http://xspf.org/ns/0/\">\n" );
+             "<playlist version=\"1\" xmlns=\"http://xspf.org/ns/0/\" " \
+             "xmlns:vlc=\"http://www.videolan.org/vlc/playlist/ns/0/\">\n" );
 
     if( !p_node ) return VLC_SUCCESS;
 
@@ -72,14 +73,6 @@ int xspf_export_playlist( vlc_object_t *p_this )
     }
     free( psz_temp );
 
-    /* save location of the playlist node */
-    psz_temp = assertUTF8URI( p_export->psz_filename );
-    if( psz_temp && *psz_temp )
-    {
-        fprintf( p_export->p_file, "\t<location>%s</location>\n", psz_temp );
-        free( psz_temp );
-    }
-
     /* export all items in a flat format */
     fprintf( p_export->p_file, "\t<trackList>\n" );
     i_count = 0;
@@ -91,7 +84,8 @@ int xspf_export_playlist( vlc_object_t *p_this )
     fprintf( p_export->p_file, "\t</trackList>\n" );
 
     /* export the tree structure in <extension> */
-    fprintf( p_export->p_file, "\t<extension application=\"http://www.videolan.org/vlc/playlist/0\">\n" );
+    fprintf( p_export->p_file, "\t<extension application=\"" \
+             "http://www.videolan.org/vlc/playlist/0\">\n" );
     i_count = 0;
     for( i = 0; i < p_node->i_children; i++ )
     {
@@ -142,10 +136,6 @@ static void xspf_export_item( playlist_item_t *p_item, FILE *p_file,
     /* leaves can be written directly */
     fprintf( p_file, "\t\t<track>\n" );
 
-    /* print identifier and increase the counter */
-    fprintf( p_file, "\t\t\t<identifier>%i</identifier>\n", *p_i_count );
-    ( *p_i_count )++;
-
     /* -> the location */
 
     char *psz_uri = input_item_GetURI( p_item->p_input );
@@ -228,17 +218,6 @@ static void xspf_export_item( playlist_item_t *p_item, FILE *p_file,
     }
     free( psz );
 
-    /* export the input's options (bookmarks, ...) in <extension> */
-    fprintf( p_file, "\t\t\t<extension application=\"http://www.videolan.org/vlc/playlist/0\">\n" );
-    for( i = 0; i < p_item->p_input->i_options; i++ )
-    {
-        fprintf( p_file, "\t\t\t\t<option>%s</option>\n",
-                 p_item->p_input->ppsz_options[i][0] == ':' ?
-                 p_item->p_input->ppsz_options[i] + 1 :
-                 p_item->p_input->ppsz_options[i] );
-    }
-    fprintf( p_file, "\t\t\t</extension>\n" );
-
 xspfexportitem_end:
     /* -> the duration */
     i_duration = input_item_GetDuration( p_item->p_input );
@@ -248,6 +227,24 @@ xspfexportitem_end:
                  (long)(i_duration / 1000) );
     }
 
+    /* export the intenal id and the input's options (bookmarks, ...)
+     * in <extension> */
+    fprintf( p_file, "\t\t\t<extension application=\"" \
+             "http://www.videolan.org/vlc/playlist/0\">\n" );
+
+    /* print the id and increase the counter */
+    fprintf( p_file, "\t\t\t\t<vlc:id>%i</vlc:id>\n", *p_i_count );
+    ( *p_i_count )++;
+
+    for( i = 0; i < p_item->p_input->i_options; i++ )
+    {
+        fprintf( p_file, "\t\t\t\t<vlc:option>%s</vlc:option>\n",
+                 p_item->p_input->ppsz_options[i][0] == ':' ?
+                 p_item->p_input->ppsz_options[i] + 1 :
+                 p_item->p_input->ppsz_options[i] );
+    }
+    fprintf( p_file, "\t\t\t</extension>\n" );
+
     fprintf( p_file, "\t\t</track>\n" );
 
     return;
@@ -270,7 +267,7 @@ static void xspf_extension_item( playlist_item_t *p_item, FILE *p_file,
         int i;
         char *psz_temp;
         psz_temp = convert_xml_special_chars( p_item->p_input->psz_name );
-        fprintf( p_file, "\t\t<node title=\"%s\">\n",
+        fprintf( p_file, "\t\t<vlc:node title=\"%s\">\n",
                  *psz_temp ? psz_temp : "" );
         free( psz_temp );
 
@@ -279,13 +276,13 @@ static void xspf_extension_item( playlist_item_t *p_item, FILE *p_file,
             xspf_extension_item( p_item->pp_children[i], p_file, p_i_count );
         }
 
-        fprintf( p_file, "\t\t</node>\n" );
+        fprintf( p_file, "\t\t</vlc:node>\n" );
         return;
     }
 
 
     /* print leaf and increase the counter */
-    fprintf( p_file, "\t\t\t<item href=\"%i\" />\n", *p_i_count );
+    fprintf( p_file, "\t\t\t<vlc:item tid=\"%i\" />\n", *p_i_count );
     ( *p_i_count )++;
 
     return;
@@ -314,14 +311,14 @@ static char *assertUTF8URI( char *psz_name )
 
     /* max. 3x for URI conversion (percent escaping) and
        8 bytes for "file://" and NULL-termination */
-    psz_ret = (char *)malloc( sizeof(char)*strlen(psz_name)*6*3+8 );
+    psz_ret = (char *)malloc( strlen(psz_name)*6*3+8 );
     if( !psz_ret )
         return NULL;
 
     /** \todo check for a valid scheme part preceding the colon */
-    size_t i_delim = strcspn( psz_s, ":" );
-    if( i_delim != strlen( psz_s ) )
+    if( strstr( psz_s, "://") != NULL )
     {
+        size_t i_delim = strcspn( psz_s, ":" );
         i_delim++; /* skip the ':' */
         strncpy( psz_ret, psz_s, i_delim );
         psz_d = psz_ret + i_delim;
@@ -349,6 +346,7 @@ static char *assertUTF8URI( char *psz_name )
             *psz_s == ' ' ||
             *psz_s == '+' ||
             *psz_s == '%' ||
+            *psz_s == '\\' ||
             ( b_uri_is_file && (
             *psz_s == ':' ||
             *psz_s == '"' ||
@@ -373,5 +371,5 @@ static char *assertUTF8URI( char *psz_name )
     }
     *psz_d = '\0';
 
-    return (char *)realloc( psz_ret, sizeof(char)*strlen( psz_ret ) + 1 );
+    return (char *)realloc( psz_ret, strlen( psz_ret ) + 1 );
 }