[vlc-devel] [PATCH 1/3] taglib: fix broken ape tags (cover art, extra tags)

Anatoliy Anischovich lin.aaa.lin at gmail.com
Wed Jul 23 11:04:14 CEST 2014


That cover art processing was silly.
Also, add unprocessed items as extra ones.

---
 modules/meta_engine/taglib.cpp | 84 ++++++++++++++++++++++++++++++------------
 1 file changed, 61 insertions(+), 23 deletions(-)

diff --git a/modules/meta_engine/taglib.cpp b/modules/meta_engine/taglib.cpp
index 7d6ceb7..1fa1b85 100644
--- a/modules/meta_engine/taglib.cpp
+++ b/modules/meta_engine/taglib.cpp
@@ -135,43 +135,66 @@ static void ExtractTrackNumberValues( vlc_meta_t* p_meta, const char *psz_value
  */
 static void ReadMetaFromAPE( APE::Tag* tag, demux_meta_t* p_demux_meta, vlc_meta_t* p_meta )
 {
-    APE::Item item;
+    APE::ItemListMap fields(tag->itemListMap());
+    APE::ItemListMap::Iterator iter;
 
-    item = tag->itemListMap()["COVER ART (FRONT)"];
-    if( !item.isEmpty() )
+    /* TODO: Process all kinds of images */
+    TAB_INIT( p_demux_meta->i_attachments, p_demux_meta->attachments );
+    iter = fields.find("COVER ART (FRONT)");
+    if( iter != fields.end() && !iter->second.isEmpty() )
     {
         input_attachment_t *p_attachment;
 
-        const ByteVector picture = item.value();
+        const ByteVector picture = iter->second.binaryData();
         const char *p_data = picture.data();
         unsigned i_data = picture.size();
+        const char *psz_name = "cover";
+        const char *psz_mime;
 
+        /* Null terminated filename followed by the image data */
         size_t desc_len = strnlen(p_data, i_data);
         if (desc_len < i_data) {
-            const char *psz_name = p_data;
+            psz_name = p_data;
             p_data += desc_len + 1; /* '\0' */
             i_data -= desc_len + 1;
-            msg_Dbg( p_demux_meta, "Found embedded art: %s (%s) is %u bytes",
-                     psz_name, "image/jpeg", i_data );
+        }
+
+        psz_mime = vlc_mime_Ext2Mime( psz_name );
+
+        msg_Dbg( p_demux_meta, "Found embedded art: %s (%s) is %u bytes",
+                 psz_name, psz_mime, i_data );
+
+        p_attachment = vlc_input_attachment_New( psz_name, psz_mime,
+                                psz_name, p_data, i_data );
 
-            p_attachment = vlc_input_attachment_New( "cover", "image/jpeg",
-                                    psz_name, p_data, i_data );
-            if( p_attachment )
-                TAB_APPEND_CAST( (input_attachment_t**),
-                                 p_demux_meta->i_attachments, p_demux_meta->attachments,
-                                 p_attachment );
+        if( p_attachment ) {
+            TAB_APPEND_CAST( (input_attachment_t**), p_demux_meta->i_attachments,
+                             p_demux_meta->attachments, p_attachment );
 
-            vlc_meta_SetArtURL( p_meta, "attachment://cover" );
+            char *psz_url;
+            if( asprintf( &psz_url, "attachment://%s", p_attachment->psz_name ) != -1 )
+            {
+                vlc_meta_SetArtURL( p_meta, psz_url );
+                free( psz_url );
+            }
         }
+
+        fields.erase(iter);
     }
 
 #define SET( keyName, metaName ) \
-    item = tag->itemListMap()[keyName]; \
-    if( !item.isEmpty() ) vlc_meta_Set##metaName( p_meta, item.toString().toCString( true ) );
+    iter = fields.find(keyName); \
+    if( iter != fields.end() && !iter->second.isEmpty() ) { \
+        vlc_meta_Set##metaName( p_meta, iter->second.toString().toCString( true ) ); \
+        fields.erase(iter); \
+    }
 
 #define SET_EXTRA( keyName, metaName ) \
-    item = tag->itemListMap()[keyName]; \
-    if( !item.isEmpty() ) vlc_meta_AddExtra( p_meta, metaName, item.toString().toCString( true ) );
+    iter = fields.find(keyName); \
+    if( iter != fields.end() && !iter->second.isEmpty() ) { \
+        vlc_meta_AddExtra( p_meta, metaName, iter->second.toString().toCString( true ) ); \
+        fields.erase(iter); \
+    }
 
     SET( "ALBUM", Album );
     SET( "ARTIST", Artist );
@@ -189,17 +212,32 @@ static void ReadMetaFromAPE( APE::Tag* tag, demux_meta_t* p_demux_meta, vlc_meta
 #undef SET_EXTRA
 
     /* */
-    item = tag->itemListMap()["TRACK"];
-    if( !item.isEmpty() )
+    iter = fields.find("TRACK");
+    if( iter != fields.end() && !iter->second.isEmpty() )
     {
-        ExtractTrackNumberValues( p_meta, item.toString().toCString( true ) );
+        ExtractTrackNumberValues( p_meta, iter->second.toString().toCString( true ) );
+        fields.erase(iter);
+    }
+
+    /* Others */
+    for( iter = fields.begin(); iter != fields.end(); ++iter )
+    {
+        if( iter->second.isEmpty() )
+            continue;
+
+        if( iter->second.type() != APE::Item::Text )
+            continue;
+
+        vlc_meta_AddExtra( p_meta,
+                           iter->first.toCString( true ),
+                           iter->second.toString().toCString( true ) );
     }
 }
 
 
 /**
- * Read meta information from APE tags
- * @param tag: the APE tag
+ * Read meta information from ASF tags
+ * @param tag: the ASF tag
  * @param p_demux_meta: the demuxer meta
  * @param p_meta: the meta
  */
-- 
2.0.1




More information about the vlc-devel mailing list