Commit 9a746cfa authored by Rafaël Carré's avatar Rafaël Carré Committed by Jean-Baptiste Kempf

Fix xspf reading/writing

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: default avatarRémi Denis-Courmont <remi@remlab.net>
(cherry picked from commit a654d4a1)
parent 1f374e04
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include "http.h" #include "http.h"
#include <vlc_plugin.h> #include <vlc_plugin.h>
#include <vlc_url.h>
#include <assert.h> #include <assert.h>
...@@ -787,7 +788,8 @@ int ArtCallback( httpd_handler_sys_t *p_args, ...@@ -787,7 +788,8 @@ int ArtCallback( httpd_handler_sys_t *p_args,
psz_art = input_item_GetArtURL( p_item ); 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; FILE *f;
char *psz_ext; char *psz_ext;
......
...@@ -546,32 +546,31 @@ static bool parse_track_node COMPLEX_INTERFACE ...@@ -546,32 +546,31 @@ static bool parse_track_node COMPLEX_INTERFACE
/* special case: location */ /* special case: location */
if( !strcmp( p_handler->name, "location" ) ) if( !strcmp( p_handler->name, "location" ) )
{ {
char *psz_uri = NULL; char *psz_location = psz_value;
psz_uri = decode_URI_duplicate( psz_value ); if( !strncmp( psz_value, "file://", 7 ) )
psz_location = decode_URI( psz_value + 7 );
if( !psz_uri ) if( !psz_location )
{ {
FREE_ATT(); FREE_ATT();
return false; 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; char* psz_tmp;
if( asprintf( &psz_tmp, "%s%s", p_demux->p_sys->psz_base, if( asprintf( &psz_tmp, "%s%s", p_demux->p_sys->psz_base,
psz_uri ) == -1 ) psz_location ) == -1 )
{ {
free( psz_uri );
FREE_ATT(); FREE_ATT();
return NULL; return NULL;
} }
free( psz_uri ); input_item_SetURI( p_new_input, psz_tmp );
psz_uri = psz_tmp; free( psz_tmp );
} }
input_item_SetURI( p_new_input, psz_uri ); else
free( psz_uri ); input_item_SetURI( p_new_input, psz_location );
input_item_CopyOptions( p_input_item, p_new_input ); input_item_CopyOptions( p_input_item, p_new_input );
psz_uri = NULL;
FREE_ATT(); FREE_ATT();
p_handler = NULL; p_handler = NULL;
} }
...@@ -652,9 +651,7 @@ static bool set_item_info SIMPLE_INTERFACE ...@@ -652,9 +651,7 @@ static bool set_item_info SIMPLE_INTERFACE
} }
else if( !strcmp( psz_name, "image" ) ) else if( !strcmp( psz_name, "image" ) )
{ {
char *psz_uri = decode_URI_duplicate( psz_value ); input_item_SetArtURL( p_input, psz_value );
input_item_SetArtURL( p_input, psz_uri );
free( psz_uri );
} }
return true; return true;
} }
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include "intf.h" #include "intf.h"
#include "playlistinfo.h" #include "playlistinfo.h"
#include "playlist.h" #include "playlist.h"
#include <vlc_url.h>
/***************************************************************************** /*****************************************************************************
* VLCPlaylistInfo Implementation * VLCPlaylistInfo Implementation
...@@ -290,7 +291,7 @@ static VLCInfo *_o_sharedInstance = nil; ...@@ -290,7 +291,7 @@ static VLCInfo *_o_sharedInstance = nil;
char *psz_meta; char *psz_meta;
NSImage *o_image; NSImage *o_image;
psz_meta = input_item_GetArtURL( p_item ); 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]]; o_image = [[NSImage alloc] initWithContentsOfFile: [NSString stringWithUTF8String: psz_meta+7]];
else else
o_image = [[NSImage imageNamed: @"noart.png"] retain]; o_image = [[NSImage imageNamed: @"noart.png"] retain];
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include "input_manager.hpp" #include "input_manager.hpp"
#include <vlc_keys.h> #include <vlc_keys.h>
#include <vlc_url.h>
#include <QApplication> #include <QApplication>
...@@ -590,7 +591,9 @@ void InputManager::UpdateArt() ...@@ -590,7 +591,9 @@ void InputManager::UpdateArt()
if( hasInput() ) if( hasInput() )
{ {
char *psz_art = input_item_GetArtURL( input_GetItem( p_input ) ); 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 ); free( psz_art );
url = url.replace( "file://", "" ); url = url.replace( "file://", "" );
......
...@@ -98,26 +98,31 @@ static int FindMeta( vlc_object_t *p_this ) ...@@ -98,26 +98,31 @@ static int FindMeta( vlc_object_t *p_this )
case 0: case 0:
/* Windows Folder.jpg */ /* Windows Folder.jpg */
snprintf( psz_filename, MAX_PATH, snprintf( psz_filename, MAX_PATH,
"file://%sFolder.jpg", psz_path ); "%sFolder.jpg", psz_path );
break; break;
case 1: case 1:
/* Windows AlbumArtSmall.jpg == small version of Folder.jpg */ /* Windows AlbumArtSmall.jpg == small version of Folder.jpg */
snprintf( psz_filename, MAX_PATH, snprintf( psz_filename, MAX_PATH,
"file://%sAlbumArtSmall.jpg", psz_path ); "%sAlbumArtSmall.jpg", psz_path );
break; break;
case 2: case 2:
/* KDE (?) .folder.png */ /* KDE (?) .folder.png */
snprintf( psz_filename, MAX_PATH, snprintf( psz_filename, MAX_PATH,
"file://%s.folder.png", psz_path ); "%s.folder.png", psz_path );
break; break;
} }
if( utf8_stat( psz_filename+7, &a ) != -1 ) if( utf8_stat( psz_filename, &a ) != -1 )
{ {
input_item_SetArtURL( p_item, psz_filename ); char *psz_uri = make_URI( psz_filename );
b_have_art = true; if( psz_uri )
{
input_item_SetArtURL( p_item, psz_uri );
free( psz_uri );
b_have_art = true;
}
} }
} }
......
...@@ -58,6 +58,7 @@ ...@@ -58,6 +58,7 @@
#include <vlc_playlist.h> #include <vlc_playlist.h>
#include <vlc_meta.h> #include <vlc_meta.h>
#include <vlc_interface.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, ...@@ -210,7 +211,7 @@ static int ItemChange( vlc_object_t *p_this, const char *psz_var,
char *psz_arturl = input_item_GetArtURL( p_item ); char *psz_arturl = input_item_GetArtURL( p_item );
CFDataRef art = NULL; CFDataRef art = NULL;
if( psz_arturl && !strncmp( psz_arturl, "file://", 7 ) && if( psz_arturl && !strncmp( psz_arturl, "file://", 7 ) &&
strlen( psz_arturl ) > 7 ) decode_URI( psz_arturl + 7 ) )
art = (CFDataRef) readFile( psz_arturl + 7 ); art = (CFDataRef) readFile( psz_arturl + 7 );
free( psz_title ); free( psz_title );
......
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#include <vlc_plugin.h> #include <vlc_plugin.h>
#include <vlc_interface.h> #include <vlc_interface.h>
#include <vlc_playlist.h> #include <vlc_playlist.h>
#include <vlc_url.h>
#include <gdk-pixbuf/gdk-pixbuf.h> #include <gdk-pixbuf/gdk-pixbuf.h>
#include <libnotify/notify.h> #include <libnotify/notify.h>
...@@ -221,12 +222,11 @@ static int ItemChange( vlc_object_t *p_this, const char *psz_var, ...@@ -221,12 +222,11 @@ static int ItemChange( vlc_object_t *p_this, const char *psz_var,
vlc_object_release( p_input ); vlc_object_release( p_input );
if( psz_arturl && !strncmp( psz_arturl, "file://", 7 ) && 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 */ { /* scale the art to show it in notify popup */
GError *p_error = NULL; GError *p_error = NULL;
pix = gdk_pixbuf_new_from_file_at_scale( &psz_arturl[7], pix = gdk_pixbuf_new_from_file_at_scale( &psz_arturl[7],
72, 72, TRUE, &p_error ); 72, 72, TRUE, &p_error );
free( psz_arturl );
} }
else /* else we show state-of-the art logo */ 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, ...@@ -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 /* we need to replace '&' with '&amp;' because '&' is a keyword of
* notification-daemon parser */ * notification-daemon parser */
const int i_len = strlen( psz_tmp ); const int i_len = strlen( psz_tmp );
......
...@@ -212,9 +212,7 @@ static void xspf_export_item( playlist_item_t *p_item, FILE *p_file, ...@@ -212,9 +212,7 @@ static void xspf_export_item( playlist_item_t *p_item, FILE *p_file,
if( psz == NULL ) psz = strdup( "" ); if( psz == NULL ) psz = strdup( "" );
if( !EMPTY_STR( psz ) ) if( !EMPTY_STR( psz ) )
{ {
psz_uri = make_URI( psz ); fprintf( p_file, "\t\t\t<image>%s</image>\n", psz );
fprintf( p_file, "\t\t\t<image>%s</image>\n", psz_uri );
free( psz_uri );
} }
free( psz ); free( psz );
......
...@@ -44,9 +44,5 @@ function fetch_art() ...@@ -44,9 +44,5 @@ function fetch_art()
page = fd:read( 65653 ) page = fd:read( 65653 )
fd = nil fd = nil
_, _, arturl = string.find( page, "imgurl=([^&]+)" ) _, _, arturl = string.find( page, "imgurl=([^&]+)" )
if arturl then return arturl
return vlc.strings.decode_uri(arturl)
else
return nil
end
end end
...@@ -41,7 +41,7 @@ function parse() ...@@ -41,7 +41,7 @@ function parse()
if not line then break end if not line then break end
if string.match( line, "param name=\"flashvars\" value=\".*video=" ) if string.match( line, "param name=\"flashvars\" value=\".*video=" )
then 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=([^&]*)" ) ) videos = vlc.strings.decode_uri( find( line, "param name=\"flashvars\" value=\".*video=([^&]*)" ) )
--[[ we get a list of different streams available, at various codecs --[[ we get a list of different streams available, at various codecs
and resolutions: and resolutions:
......
...@@ -26,7 +26,7 @@ end ...@@ -26,7 +26,7 @@ end
function get_arturl( path, video_id ) function get_arturl( path, video_id )
if string.match( vlc.path, "iurl=" ) then 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 end
if not arturl then if not arturl then
return "http://img.youtube.com/vi/"..video_id.."/default.jpg" return "http://img.youtube.com/vi/"..video_id.."/default.jpg"
......
...@@ -132,7 +132,7 @@ static char *ArtCacheName( input_item_t *p_item, const char *psz_type ) ...@@ -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_ext = filename_sanitize( psz_type ? psz_type : "" );
char *psz_filename; 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; psz_filename = NULL;
free( psz_ext ); free( psz_ext );
...@@ -164,12 +164,19 @@ int playlist_FindArtInCache( input_item_t *p_item ) ...@@ -164,12 +164,19 @@ int playlist_FindArtInCache( input_item_t *p_item )
if( !strncmp( psz_filename, "art", 3 ) ) if( !strncmp( psz_filename, "art", 3 ) )
{ {
char *psz_file; 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_path, psz_filename ) < 0 )
psz_file = NULL; psz_file = NULL;
if( psz_file ) 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; b_found = true;
} }
...@@ -192,17 +199,25 @@ int playlist_SaveArt( playlist_t *p_playlist, input_item_t *p_item, ...@@ -192,17 +199,25 @@ int playlist_SaveArt( playlist_t *p_playlist, input_item_t *p_item,
if( !psz_filename ) if( !psz_filename )
return VLC_EGENERIC; 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 */ /* Check if we already dumped it */
struct stat s; 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_filename );
free( psz_uri );
return VLC_SUCCESS; return VLC_SUCCESS;
} }
/* Dump it otherwise */ /* Dump it otherwise */
FILE *f = utf8_fopen( psz_filename+7, "wb" ); FILE *f = utf8_fopen( psz_filename, "wb" );
if( f ) if( f )
{ {
if( fwrite( p_buffer, i_buffer, 1, f ) != 1 ) 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, ...@@ -212,11 +227,12 @@ int playlist_SaveArt( playlist_t *p_playlist, input_item_t *p_item,
else else
{ {
msg_Dbg( p_playlist, "album art saved to %s", psz_filename ); 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 ); fclose( f );
} }
free( psz_filename ); free( psz_filename );
free( psz_uri );
return VLC_SUCCESS; return VLC_SUCCESS;
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment