]> git.sesse.net Git - vlc/blob - modules/meta_engine/taglib.cpp
Read album, also detect images in FLAC
[vlc] / modules / meta_engine / taglib.cpp
1 /*****************************************************************************
2  * taglib.cpp: Taglib tag parser/writer
3  *****************************************************************************
4  * Copyright (C) 2003-2006 the VideoLAN team
5  * $Id$
6  *
7  * Authors: ClĂ©ment Stenac <zorglub@videolan.org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23 #include <vlc/vlc.h>
24 #include <vlc/input.h>
25 #include <vlc_meta.h>
26
27 #include <fileref.h>
28 #include <tag.h>
29 #include <id3v2tag.h>
30 #include <mpegfile.h>
31 #include <flacfile.h>
32
33 static int  ReadMeta ( vlc_object_t * );
34
35 vlc_module_begin();
36     set_capability( "meta reader", 1000 );
37     set_callbacks( ReadMeta, NULL );
38 vlc_module_end();
39
40 static bool checkID3Image( const TagLib::ID3v2::Tag *tag )
41 {
42     TagLib::ID3v2::FrameList l = tag->frameListMap()[ "APIC" ];
43     return !l.isEmpty();
44 }
45
46 /* Try detecting embedded art */
47 static void DetectImage( TagLib::FileRef f, vlc_meta_t *p_meta )
48 {
49     if( TagLib::MPEG::File *mpeg =
50                dynamic_cast<TagLib::MPEG::File *>(f.file() ) )
51     {
52         if( mpeg->ID3v2Tag() && checkID3Image( mpeg->ID3v2Tag() ) )
53             vlc_meta_SetArtURL( p_meta, "APIC" );
54     }
55     else if( TagLib::FLAC::File *flac =
56              dynamic_cast<TagLib::FLAC::File *>(f.file() ) )
57     {
58         if( flac->ID3v2Tag() && checkID3Image( flac->ID3v2Tag() ) )
59             vlc_meta_SetArtURL( p_meta, "APIC" );
60     }
61 #if 0
62 /* This needs special additions to taglib */
63  * else if( TagLib::MP4::File *mp4 =
64                dynamic_cast<TagLib::MP4::File *>( f.file() ) )
65     {
66         TagLib::MP4::Tag *mp4tag =
67                 dynamic_cast<TagLib::MP4::Tag *>( mp4->tag() );
68         if( mp4tag && mp4tag->cover().size() )
69             vlc_meta_SetArtURL( p_meta, "MP4C" );
70     }
71 #endif
72 }
73
74 static int ReadMeta( vlc_object_t *p_this )
75 {
76     demux_t *p_demux = (demux_t *)p_this;
77
78     if( !strncmp( p_demux->psz_access, "file", 4 ) )
79     {
80         if( !p_demux->p_private )
81             p_demux->p_private = (void*)vlc_meta_New();
82         TagLib::FileRef f( p_demux->psz_path );
83         if( !f.isNull() && f.tag() )
84         {
85             TagLib::Tag *tag = f.tag();
86             vlc_meta_t *p_meta = (vlc_meta_t *)(p_demux->p_private );
87
88 #define SET( foo, bar ) vlc_meta_Set##foo( p_meta, tag->bar ().toCString(true))
89             SET( Title, title );
90             SET( Artist, artist );
91             SET( Album, album );
92 //            SET( Comment, comment );
93             SET( Genre, genre );
94 //            SET( Year, year ); Gra, this is an int, need to convert
95 //            SET( Tracknum , track ); Same
96 #undef SET
97             DetectImage( f, p_meta );
98
99             return VLC_SUCCESS;
100         }
101     }
102     return VLC_EGENERIC;
103 }