Fix xspf reading/writing
authorRafaël Carré <rafael.carre@gmail.com>
Wed, 27 May 2009 19:36:22 +0000 (21:36 +0200)
committerRémi Denis-Courmont <remi@remlab.net>
Thu, 28 May 2009 14:11:17 +0000 (17:11 +0300)
When reading a file:// URL from an xspf entry, store the decoded file path; else store the unmodified URL

Always keep album art URLs always encoded and decode the path when needed
Interfaces & plugins only use file paths
Playlist core extract attachment:// URLs (from file meta data), http:// or other (from meta data fetchers like lua) and cache them to a file

Thanks to courmisch for clarification

Signed-off-by: Rémi Denis-Courmont <remi@remlab.net>
12 files changed:
modules/control/http/http.c
modules/demux/playlist/xspf.c
modules/gui/macosx/playlistinfo.m
modules/gui/qt4/input_manager.cpp
modules/meta_engine/folder.c
modules/misc/notify/growl.m
modules/misc/notify/notify.c
modules/misc/playlist/xspf.c
share/lua/meta/10_googleimage.lua
share/lua/playlist/dailymotion.lua
share/lua/playlist/youtube.lua
src/playlist/art.c

index 75f24c2..6987029 100644 (file)
@@ -27,6 +27,7 @@
 
 #include "http.h"
 #include <vlc_plugin.h>
+#include <vlc_url.h>
 
 #include <assert.h>
 
@@ -787,7 +788,8 @@ int  ArtCallback( httpd_handler_sys_t *p_args,
         psz_art = input_item_GetArtURL( p_item );
     }
 
-    if( psz_art && !strncmp( psz_art, "file://", strlen( "file://" ) ) )
+    if( psz_art && !strncmp( psz_art, "file://", strlen( "file://" ) ) &&
+        decode_URI( psz_art + 7 ) )
     {
         FILE *f;
         char *psz_ext;
index ed1ed92..eee5b85 100644 (file)
@@ -546,32 +546,31 @@ static bool parse_track_node COMPLEX_INTERFACE
                 /* special case: location */
                 if( !strcmp( p_handler->name, "location" ) )
                 {
-                    char *psz_uri = NULL;
-                    psz_uri = decode_URI_duplicate( psz_value );
+                    char *psz_location = psz_value;
+                    if( !strncmp( psz_value, "file://", 7 ) )
+                        psz_location = decode_URI( psz_value + 7 );
 
-                    if( !psz_uri )
+                    if( !psz_location )
                     {
                         FREE_ATT();
                         return false;
                     }
 
-                    if( p_demux->p_sys->psz_base && !strstr( psz_uri, "://" ) )
+                    if( p_demux->p_sys->psz_base && !strstr( psz_value, "://" ) )
                     {
                         char* psz_tmp;
                         if( asprintf( &psz_tmp, "%s%s", p_demux->p_sys->psz_base,
-                                      psz_uri ) == -1 )
+                                      psz_location ) == -1 )
                         {
-                            free( psz_uri );
                             FREE_ATT();
                             return NULL;
                         }
-                        free( psz_uri );
-                        psz_uri = psz_tmp;
+                        input_item_SetURI( p_new_input, psz_tmp );
+                        free( psz_tmp );
                     }
-                    input_item_SetURI( p_new_input, psz_uri );
-                    free( psz_uri );
+                    else
+                        input_item_SetURI( p_new_input, psz_location );
                     input_item_CopyOptions( p_input_item, p_new_input );
-                    psz_uri = NULL;
                     FREE_ATT();
                     p_handler = NULL;
                 }
@@ -652,9 +651,7 @@ static bool set_item_info SIMPLE_INTERFACE
     }
     else if( !strcmp( psz_name, "image" ) )
     {
-        char *psz_uri = decode_URI_duplicate( psz_value );
-        input_item_SetArtURL( p_input, psz_uri );
-        free( psz_uri );
+        input_item_SetArtURL( p_input, psz_value );
     }
     return true;
 }
index 6a2b8ce..972f1a6 100644 (file)
@@ -29,6 +29,7 @@
 #include "intf.h"
 #include "playlistinfo.h"
 #include "playlist.h"
+#include <vlc_url.h>
 
 /*****************************************************************************
  * VLCPlaylistInfo Implementation
@@ -292,7 +293,7 @@ static VLCInfo *_o_sharedInstance = nil;
         char *psz_meta;
         NSImage *o_image;
         psz_meta = input_item_GetArtURL( p_item );
-        if( psz_meta && !strncmp( psz_meta, "file://", 7 ) )
+        if( psz_meta && !strncmp( psz_meta, "file://", 7 ) && decode_URI( psz_meta + 7 ) )
             o_image = [[NSImage alloc] initWithContentsOfFile: [NSString stringWithUTF8String: psz_meta+7]];
         else
             o_image = [[NSImage imageNamed: @"noart.png"] retain];
index 0b456ad..1fc1f49 100644 (file)
@@ -29,6 +29,7 @@
 
 #include "input_manager.hpp"
 #include <vlc_keys.h>
+#include <vlc_url.h>
 
 #include <QApplication>
 
@@ -589,12 +590,12 @@ void InputManager::UpdateArt()
     if( hasInput() )
     {
         char *psz_art = input_item_GetArtURL( input_GetItem( p_input ) );
-        url = qfu( psz_art );
+        if( psz_art && !strncmp( psz_art, "file://", 7 ) &&
+                decode_URI( psz_art + 7 ) )
+            url = qfu( psz_art + 7);
         free( psz_art );
     }
-    url = url.replace( "file://", QString("" ) );
-    /* Taglib seems to define a attachment://, It won't work yet */
-    url = url.replace( "attachment://", QString("" ) );
+
     /* Update Art meta */
     emit artChanged( url );
 }
index 4d41b0a..4f9856f 100644 (file)
@@ -98,26 +98,31 @@ static int FindMeta( vlc_object_t *p_this )
             case 0:
             /* Windows Folder.jpg */
             snprintf( psz_filename, MAX_PATH,
-                      "file://%sFolder.jpg", psz_path );
+                      "%sFolder.jpg", psz_path );
             break;
 
             case 1:
             /* Windows AlbumArtSmall.jpg == small version of Folder.jpg */
             snprintf( psz_filename, MAX_PATH,
-                  "file://%sAlbumArtSmall.jpg", psz_path );
+                  "%sAlbumArtSmall.jpg", psz_path );
             break;
 
             case 2:
             /* KDE (?) .folder.png */
             snprintf( psz_filename, MAX_PATH,
-                  "file://%s.folder.png", psz_path );
+                  "%s.folder.png", psz_path );
             break;
         }
 
-        if( utf8_stat( psz_filename+7, &a ) != -1 )
+        if( utf8_stat( psz_filename, &a ) != -1 )
         {
-            input_item_SetArtURL( p_item, psz_filename );
-            b_have_art = true;
+            char *psz_uri = make_URI( psz_filename );
+            if( psz_uri )
+            {
+                input_item_SetArtURL( p_item, psz_uri );
+                free( psz_uri );
+                b_have_art = true;
+            }
         }
     }
 
index c0503b0..95ad205 100644 (file)
@@ -58,6 +58,7 @@
 #include <vlc_playlist.h>
 #include <vlc_meta.h>
 #include <vlc_interface.h>
+#include <vlc_url.h>
 
 
 /*****************************************************************************
@@ -210,7 +211,7 @@ static int ItemChange( vlc_object_t *p_this, const char *psz_var,
     char *psz_arturl = input_item_GetArtURL( p_item );
     CFDataRef art = NULL;
     if( psz_arturl && !strncmp( psz_arturl, "file://", 7 ) &&
-                    strlen( psz_arturl ) > 7 )
+                    decode_URI( psz_arturl + 7 ) )
         art = (CFDataRef) readFile( psz_arturl + 7 );
 
     free( psz_title );
index 6b3be7c..6fa084a 100644 (file)
@@ -32,6 +32,7 @@
 #include <vlc_plugin.h>
 #include <vlc_interface.h>
 #include <vlc_playlist.h>
+#include <vlc_url.h>
 
 #include <gdk-pixbuf/gdk-pixbuf.h>
 #include <libnotify/notify.h>
@@ -221,12 +222,11 @@ static int ItemChange( vlc_object_t *p_this, const char *psz_var,
     vlc_object_release( p_input );
 
     if( psz_arturl && !strncmp( psz_arturl, "file://", 7 ) &&
-                strlen( psz_arturl ) > 7 )
+                decode_URI( psz_arturl + 7 ) )
     { /* scale the art to show it in notify popup */
         GError *p_error = NULL;
         pix = gdk_pixbuf_new_from_file_at_scale( &psz_arturl[7],
                                                  72, 72, TRUE, &p_error );
-        free( psz_arturl );
     }
     else /* else we show state-of-the art logo */
     {
@@ -239,6 +239,8 @@ static int ItemChange( vlc_object_t *p_this, const char *psz_var,
         }
     }
 
+    free( psz_arturl );
+
     /* we need to replace '&' with '&amp;' because '&' is a keyword of
      * notification-daemon parser */
     const int i_len = strlen( psz_tmp );
index 0f5f82c..6765adb 100644 (file)
@@ -212,9 +212,7 @@ static void xspf_export_item( playlist_item_t *p_item, FILE *p_file,
     if( psz == NULL ) psz = strdup( "" );
     if( !EMPTY_STR( psz ) )
     {
-        psz_uri = make_URI( psz );
-        fprintf( p_file, "\t\t\t<image>%s</image>\n", psz_uri );
-        free( psz_uri );
+        fprintf( p_file, "\t\t\t<image>%s</image>\n", psz );
     }
     free( psz );
 
index e203c9c..8dc1e04 100644 (file)
@@ -44,9 +44,5 @@ function fetch_art()
     page = fd:read( 65653 )
     fd = nil
     _, _, arturl = string.find( page, "imgurl=([^&]+)" )
-    if arturl then
-        return vlc.strings.decode_uri(arturl)
-    else
-        return nil
-    end
+    return arturl
 end
index e850bcf..f4545c6 100644 (file)
@@ -41,7 +41,7 @@ function parse()
         if not line then break end
         if string.match( line, "param name=\"flashvars\" value=\".*video=" )
         then
-            arturl = vlc.strings.decode_uri( find( line, "param name=\"flashvars\" value=\".*preview=([^&]*)" ) )
+            arturl = find( line, "param name=\"flashvars\" value=\".*preview=([^&]*)" )
             videos = vlc.strings.decode_uri( find( line, "param name=\"flashvars\" value=\".*video=([^&]*)" ) )
        --[[ we get a list of different streams available, at various codecs
             and resolutions:
index 452400f..238d3eb 100644 (file)
@@ -26,7 +26,7 @@ end
 
 function get_arturl( path, video_id )
     if string.match( vlc.path, "iurl=" ) then
-        return vlc.strings.decode_uri( get_url_param( vlc.path, "iurl" ) )
+        return vlc.strings( get_url_param( vlc.path, "iurl" ) )
     end
     if not arturl then
         return "http://img.youtube.com/vi/"..video_id.."/default.jpg"
index 002ec6e..2cffcbb 100644 (file)
@@ -132,7 +132,7 @@ static char *ArtCacheName( input_item_t *p_item, const char *psz_type )
 
     char *psz_ext = filename_sanitize( psz_type ? psz_type : "" );
     char *psz_filename;
-    if( asprintf( &psz_filename, "file://%s" DIR_SEP "art%s", psz_path, psz_ext ) < 0 )
+    if( asprintf( &psz_filename, "%s" DIR_SEP "art%s", psz_path, psz_ext ) < 0 )
         psz_filename = NULL;
 
     free( psz_ext );
@@ -164,12 +164,19 @@ int playlist_FindArtInCache( input_item_t *p_item )
         if( !strncmp( psz_filename, "art", 3 ) )
         {
             char *psz_file;
-            if( asprintf( &psz_file, "file://%s" DIR_SEP "%s",
+            if( asprintf( &psz_file, "%s" DIR_SEP "%s",
                           psz_path, psz_filename ) < 0 )
                 psz_file = NULL;
             if( psz_file )
-                input_item_SetArtURL( p_item, psz_file );
-            free( psz_file );
+            {
+                char *psz_uri = make_URI( psz_file );
+                if( psz_uri )
+                {
+                    input_item_SetArtURL( p_item, psz_uri );
+                    free( psz_uri );
+                }
+                free( psz_file );
+            }
 
             b_found = true;
         }
@@ -192,17 +199,25 @@ int playlist_SaveArt( playlist_t *p_playlist, input_item_t *p_item,
     if( !psz_filename )
         return VLC_EGENERIC;
 
+    char *psz_uri = make_URI( psz_filename );
+    if( !psz_uri )
+    {
+        free( psz_filename );
+        return VLC_EGENERIC;
+    }
+
     /* Check if we already dumped it */
     struct stat s;
-    if( !utf8_stat( psz_filename+7, &s ) )
+    if( !utf8_stat( psz_filename, &s ) )
     {
-        input_item_SetArtURL( p_item, psz_filename );
+        input_item_SetArtURL( p_item, psz_uri );
         free( psz_filename );
+        free( psz_uri );
         return VLC_SUCCESS;
     }
 
     /* Dump it otherwise */
-    FILE *f = utf8_fopen( psz_filename+7, "wb" );
+    FILE *f = utf8_fopen( psz_filename, "wb" );
     if( f )
     {
         if( fwrite( p_buffer, i_buffer, 1, f ) != 1 )
@@ -212,11 +227,12 @@ int playlist_SaveArt( playlist_t *p_playlist, input_item_t *p_item,
         else
         {
             msg_Dbg( p_playlist, "album art saved to %s", psz_filename );
-            input_item_SetArtURL( p_item, psz_filename );
+            input_item_SetArtURL( p_item, psz_uri );
         }
         fclose( f );
     }
     free( psz_filename );
+    free( psz_uri );
     return VLC_SUCCESS;
 }