]> git.sesse.net Git - vlc/blobdiff - modules/meta_engine/taglib.cpp
taglib: only try to read local files
[vlc] / modules / meta_engine / taglib.cpp
index c499b51b41488a840e32ada08e322d5e52b3468b..198d14476f0d5e2e5a10b8a58c7dfcc6ec856eb3 100644 (file)
 #include <mpegfile.h>
 #include <oggfile.h>
 #include <oggflacfile.h>
+
+#ifdef TAGLIB_WITH_ASF
+# include <aifffile.h>
+# include <wavfile.h>
+#endif
+
 #include <speexfile.h>
 #include <trueaudiofile.h>
 #include <vorbisfile.h>
@@ -324,23 +330,29 @@ static int ReadMeta( vlc_object_t* p_this)
     demux_t*        p_demux = p_demux_meta->p_demux;
     vlc_meta_t*     p_meta;
     FileRef f;
+    char *psz_path = decode_URI_duplicate( p_demux->psz_path );
 
     p_demux_meta->p_meta = NULL;
+    if( !psz_path )
+        return VLC_ENOMEM;
+    if( strncmp( p_demux->psz_access, "file", strlen("file") ) )
+        return VLC_EGENERIC;
 
 
 #if defined(WIN32) || defined (UNDER_CE)
     wchar_t wpath[MAX_PATH + 1];
-    if( !MultiByteToWideChar( CP_UTF8, 0, p_demux->psz_path, -1, wpath, MAX_PATH) )
+    if( !MultiByteToWideChar( CP_UTF8, 0, psz_path, -1, wpath, MAX_PATH) )
         return VLC_EGENERIC;
     wpath[MAX_PATH] = L'\0';
     f = FileRef( wpath );
 #else
-    const char* local_name = ToLocale( p_demux->psz_path );
+    const char* local_name = ToLocale( psz_path );
     if( !local_name )
         return VLC_EGENERIC;
     f = FileRef( local_name );
     LocaleFree( local_name );
 #endif
+    free( psz_path );
 
     if( f.isNull() )
         return VLC_EGENERIC;
@@ -407,6 +419,15 @@ static int ReadMeta( vlc_object_t* p_this)
         else if( Ogg::Vorbis::File* ogg_vorbis = dynamic_cast<Ogg::Vorbis::File*>(f.file()) )
             ReadMetaFromXiph( ogg_vorbis->tag(), p_demux, p_demux_meta, p_meta );
     }
+#ifdef TAGLIB_WITH_ASF
+    else if( RIFF::File* riff = dynamic_cast<RIFF::File*>(f.file()) )
+    {
+        if( RIFF::AIFF::File* riff_aiff = dynamic_cast<RIFF::AIFF::File*>(f.file()) )
+            ReadMetaFromId3v2( riff_aiff->tag(), p_demux, p_demux_meta, p_meta );
+        else if( RIFF::WAV::File* riff_wav = dynamic_cast<RIFF::WAV::File*>(f.file()) )
+            ReadMetaFromId3v2( riff_wav->tag(), p_demux, p_demux_meta, p_meta );
+    }
+#endif
     else if( TrueAudio::File* trueaudio = dynamic_cast<TrueAudio::File*>(f.file()) )
     {
         if( trueaudio->ID3v2Tag() )
@@ -524,26 +545,16 @@ static int WriteMeta( vlc_object_t *p_this )
         return VLC_EGENERIC;
     }
 
-    char *export_file = strdup(p_export->psz_file);
-    if( decode_URI( export_file ) == NULL )
-    {
-        free( export_file );
-        return VLC_EGENERIC;
-    }
-
 #if defined(WIN32) || defined (UNDER_CE)
     wchar_t wpath[MAX_PATH + 1];
-    if( !MultiByteToWideChar( CP_UTF8, 0, export_file , -1, wpath, MAX_PATH) )
+    if( !MultiByteToWideChar( CP_UTF8, 0, p_export->psz_file, -1, wpath, MAX_PATH) )
         return VLC_EGENERIC;
     wpath[MAX_PATH] = L'\0';
     f = FileRef( wpath );
 #else
-    const char* local_name = ToLocale( export_file );
+    const char* local_name = ToLocale( p_export->psz_file );
     if( !local_name )
-    {
-        free( export_file );
         return VLC_EGENERIC;
-    }
     f = FileRef( local_name );
     LocaleFree( local_name );
 #endif
@@ -551,47 +562,32 @@ static int WriteMeta( vlc_object_t *p_this )
     if( f.isNull() || !f.tag() || f.file()->readOnly() )
     {
         msg_Err( p_this, "File %s can't be opened for tag writing",
-            export_file );
-        free( export_file );
+                 p_export->psz_file );
         return VLC_EGENERIC;
     }
 
-    msg_Dbg( p_this, "Writing metadata for %s", export_file );
-    free( export_file );
+    msg_Dbg( p_this, "Writing metadata for %s", p_export->psz_file );
 
     Tag *p_tag = f.tag();
 
     char *psz_meta;
 
-#define SET( a, b )                                         \
-    if( b )                                                 \
-    {                                                       \
-        String* psz_tmp = new String( b, String::UTF8 );    \
-        p_tag->set##a( *psz_tmp );                          \
-        delete psz_tmp;                                     \
-    }
+#define SET( a, b )                                             \
+    psz_meta = input_item_Get ## a( p_item );                   \
+    if( psz_meta )                                              \
+    {                                                           \
+        String tmp( psz_meta, String::UTF8 );                   \
+        p_tag->set##b( tmp );                                   \
+    }                                                           \
+    free( psz_meta );
 
     // Saving all common fields
     // If the title is empty, use the name
-    psz_meta = input_item_GetTitleFbName( p_item );
-    SET( Title, psz_meta );
-    free( psz_meta );
-
-    psz_meta = input_item_GetArtist( p_item );
-    SET( Artist, psz_meta );
-    free( psz_meta );
-
-    psz_meta = input_item_GetAlbum( p_item );
-    SET( Album, psz_meta );
-    free( psz_meta );
-
-    psz_meta = input_item_GetDescription( p_item );
-    SET( Comment, psz_meta );
-    free( psz_meta );
-
-    psz_meta = input_item_GetGenre( p_item );
-    SET( Genre, psz_meta );
-    free( psz_meta );
+    SET( TitleFbName, Title );
+    SET( Artist, Artist );
+    SET( Album, Album );
+    SET( Description, Comment );
+    SET( Genre, Genre );
 
 #undef SET
 
@@ -633,6 +629,15 @@ static int WriteMeta( vlc_object_t *p_this )
         else if( Ogg::Vorbis::File* ogg_vorbis = dynamic_cast<Ogg::Vorbis::File*>(f.file()) )
             WriteMetaToXiph( ogg_vorbis->tag(), p_item );
     }
+#ifdef TAGLIB_WITH_ASF
+    else if( RIFF::File* riff = dynamic_cast<RIFF::File*>(f.file()) )
+    {
+        if( RIFF::AIFF::File* riff_aiff = dynamic_cast<RIFF::AIFF::File*>(f.file()) )
+            WriteMetaToId3v2( riff_aiff->tag(), p_item );
+        else if( RIFF::WAV::File* riff_wav = dynamic_cast<RIFF::WAV::File*>(f.file()) )
+            WriteMetaToId3v2( riff_wav->tag(), p_item );
+    }
+#endif
     else if( TrueAudio::File* trueaudio = dynamic_cast<TrueAudio::File*>(f.file()) )
     {
         if( trueaudio->ID3v2Tag() )