[vlc-devel] commit: album art: use filename_sanitize function ( Rémi Duraffort )
git version control
git at videolan.org
Tue Mar 31 21:09:18 CEST 2009
vlc | branch: master | Rémi Duraffort <ivoire at videolan.org> | Tue Mar 31 21:04:40 2009 +0200| [e22a6dbd5154aa0274427f981a65695d90d0c673] | committer: Rémi Duraffort
album art: use filename_sanitize function
and change this function to replace spaces by '_' on windows.
(should fix #2143)
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=e22a6dbd5154aa0274427f981a65695d90d0c673
---
include/vlc_strings.h | 2 +-
src/playlist/art.c | 33 ++++-----------------------------
src/text/strings.c | 8 ++++++--
3 files changed, 11 insertions(+), 32 deletions(-)
diff --git a/include/vlc_strings.h b/include/vlc_strings.h
index eab608e..4173ac4 100644
--- a/include/vlc_strings.h
+++ b/include/vlc_strings.h
@@ -50,7 +50,7 @@ VLC_EXPORT( char *, __str_format_meta, ( vlc_object_t *, const char * ) );
#define str_format( a, b ) __str_format( VLC_OBJECT( a ), b )
VLC_EXPORT( char *, __str_format, ( vlc_object_t *, const char * ) );
-VLC_EXPORT( void, filename_sanitize, ( char * ) );
+VLC_EXPORT( char *, filename_sanitize, ( const char * ) );
VLC_EXPORT( void, path_sanitize, ( char * ) );
/**
diff --git a/src/playlist/art.c b/src/playlist/art.c
index 7a82360..002ec6e 100644
--- a/src/playlist/art.c
+++ b/src/playlist/art.c
@@ -61,29 +61,6 @@ static void ArtCacheCreateDir( const char *psz_dir )
utf8_mkdir( psz_dir, 0700 );
}
-static char *ArtCacheGetSanitizedFileName( const char *psz )
-{
- char *dup = strdup(psz);
- int i;
-
- filename_sanitize( dup );
-
- /* Doesn't create a filename with invalid characters
- * TODO: several filesystems forbid several characters: list them all
- */
- for( i = 0; dup[i] != '\0'; i++ )
- {
- if( dup[i] == DIR_SEP_CHAR )
- dup[i] = ' ';
- // "<>:\"/?*" are forbidden for win filenames
-#if defined( WIN32 ) || defined( UNDER_CE )
- else if( strchr( "<>:\"/?*", dup[i] ) )
- dup[i] = '_';
-#endif
- }
- return dup;
-}
-
static void ArtCacheGetDirPath( char *psz_dir,
const char *psz_title,
const char *psz_artist, const char *psz_album )
@@ -92,8 +69,8 @@ static void ArtCacheGetDirPath( char *psz_dir,
if( !EMPTY_STR(psz_artist) && !EMPTY_STR(psz_album) )
{
- char * psz_album_sanitized = ArtCacheGetSanitizedFileName( psz_album );
- char * psz_artist_sanitized = ArtCacheGetSanitizedFileName( psz_artist );
+ char *psz_album_sanitized = filename_sanitize( psz_album );
+ char *psz_artist_sanitized = filename_sanitize( psz_artist );
snprintf( psz_dir, PATH_MAX, "%s" DIR_SEP
"art" DIR_SEP "artistalbum" DIR_SEP "%s" DIR_SEP "%s",
psz_cachedir, psz_artist_sanitized, psz_album_sanitized );
@@ -102,7 +79,7 @@ static void ArtCacheGetDirPath( char *psz_dir,
}
else
{
- char * psz_title_sanitized = ArtCacheGetSanitizedFileName( psz_title );
+ char * psz_title_sanitized = filename_sanitize( psz_title );
snprintf( psz_dir, PATH_MAX, "%s" DIR_SEP
"art" DIR_SEP "title" DIR_SEP "%s",
psz_cachedir, psz_title_sanitized );
@@ -153,9 +130,7 @@ static char *ArtCacheName( input_item_t *p_item, const char *psz_type )
ArtCacheCreateDir( psz_path );
- char *psz_ext = strdup( psz_type ? psz_type : "" );
- filename_sanitize( psz_ext );
-
+ 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 )
psz_filename = NULL;
diff --git a/src/text/strings.c b/src/text/strings.c
index ee0085e..3381840 100644
--- a/src/text/strings.c
+++ b/src/text/strings.c
@@ -1020,8 +1020,10 @@ char *__str_format( vlc_object_t *p_this, const char *psz_src )
/**
* Remove forbidden characters from filenames (including slashes)
*/
-void filename_sanitize( char *str )
+char* filename_sanitize( const char *str_origin )
{
+ char *str = strdup( str_origin );
+ char *str_base = str;
if( *str == '.' && (str[1] == '\0' || (str[1] == '.' && str[2] == '\0' ) ) )
{
while( *str )
@@ -1029,7 +1031,7 @@ void filename_sanitize( char *str )
*str = '_';
str++;
}
- return;
+ return str_base;
}
while( *str )
@@ -1048,11 +1050,13 @@ void filename_sanitize( char *str )
case '|':
case '<':
case '>':
+ case ' ':
#endif
*str = '_';
}
str++;
}
+ return str_base;
}
/**
More information about the vlc-devel
mailing list