]> git.sesse.net Git - vlc/commitdiff
Read album, also detect images in FLAC
authorClément Stenac <zorglub@videolan.org>
Sun, 24 Sep 2006 15:09:25 +0000 (15:09 +0000)
committerClément Stenac <zorglub@videolan.org>
Sun, 24 Sep 2006 15:09:25 +0000 (15:09 +0000)
modules/meta_engine/taglib.cpp

index a6ccb143503d2c69ce80f7941ad7e109d6ca41c8..bab9eb2d4e1d1ec4a943606e517a77f5c0574c03 100644 (file)
@@ -28,6 +28,7 @@
 #include <tag.h>
 #include <id3v2tag.h>
 #include <mpegfile.h>
+#include <flacfile.h>
 
 static int  ReadMeta ( vlc_object_t * );
 
@@ -36,12 +37,39 @@ vlc_module_begin();
     set_callbacks( ReadMeta, NULL );
 vlc_module_end();
 
-bool checkID3Image( const TagLib::ID3v2::Tag *tag )
+static bool checkID3Image( const TagLib::ID3v2::Tag *tag )
 {
     TagLib::ID3v2::FrameList l = tag->frameListMap()[ "APIC" ];
     return !l.isEmpty();
 }
 
+/* Try detecting embedded art */
+static void DetectImage( TagLib::FileRef f, vlc_meta_t *p_meta )
+{
+    if( TagLib::MPEG::File *mpeg =
+               dynamic_cast<TagLib::MPEG::File *>(f.file() ) )
+    {
+        if( mpeg->ID3v2Tag() && checkID3Image( mpeg->ID3v2Tag() ) )
+            vlc_meta_SetArtURL( p_meta, "APIC" );
+    }
+    else if( TagLib::FLAC::File *flac =
+             dynamic_cast<TagLib::FLAC::File *>(f.file() ) )
+    {
+        if( flac->ID3v2Tag() && checkID3Image( flac->ID3v2Tag() ) )
+            vlc_meta_SetArtURL( p_meta, "APIC" );
+    }
+#if 0
+/* This needs special additions to taglib */
+ * else if( TagLib::MP4::File *mp4 =
+               dynamic_cast<TagLib::MP4::File *>( f.file() ) )
+    {
+        TagLib::MP4::Tag *mp4tag =
+                dynamic_cast<TagLib::MP4::Tag *>( mp4->tag() );
+        if( mp4tag && mp4tag->cover().size() )
+            vlc_meta_SetArtURL( p_meta, "MP4C" );
+    }
+#endif
+}
 
 static int ReadMeta( vlc_object_t *p_this )
 {
@@ -57,18 +85,17 @@ static int ReadMeta( vlc_object_t *p_this )
             TagLib::Tag *tag = f.tag();
             vlc_meta_t *p_meta = (vlc_meta_t *)(p_demux->p_private );
 
-            vlc_meta_SetTitle( p_meta, tag->title().toCString( true ) );
-            vlc_meta_SetArtist( p_meta, tag->artist().toCString( true ) );
+#define SET( foo, bar ) vlc_meta_Set##foo( p_meta, tag->bar ().toCString(true))
+            SET( Title, title );
+            SET( Artist, artist );
+            SET( Album, album );
+//            SET( Comment, comment );
+            SET( Genre, genre );
+//            SET( Year, year ); Gra, this is an int, need to convert
+//            SET( Tracknum , track ); Same
+#undef SET
+            DetectImage( f, p_meta );
 
-            if( TagLib::MPEG::File *mpeg =
-                           dynamic_cast<TagLib::MPEG::File *>(f.file() ) )
-            {
-                if( mpeg->ID3v2Tag() && checkID3Image( mpeg->ID3v2Tag() ) )
-                {
-                    fprintf( stderr, "%s has APIC\n", p_meta->psz_title );
-                    vlc_meta_SetArtURL( p_meta, "APIC" ); /// Means that the interface will use us to actually fetch it
-                }
-            }
             return VLC_SUCCESS;
         }
     }