]> git.sesse.net Git - vlc/blob - modules/meta_engine/taglib.cpp
Detect embedded images
[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
32 static int  ReadMeta ( vlc_object_t * );
33
34 vlc_module_begin();
35     set_capability( "meta reader", 1000 );
36     set_callbacks( ReadMeta, NULL );
37 vlc_module_end();
38
39 bool checkID3Image( const TagLib::ID3v2::Tag *tag )
40 {
41     TagLib::ID3v2::FrameList l = tag->frameListMap()[ "APIC" ];
42     return !l.isEmpty();
43 }
44
45
46 static int ReadMeta( vlc_object_t *p_this )
47 {
48     demux_t *p_demux = (demux_t *)p_this;
49
50     if( !strncmp( p_demux->psz_access, "file", 4 ) )
51     {
52         if( !p_demux->p_private )
53             p_demux->p_private = (void*)vlc_meta_New();
54         TagLib::FileRef f( p_demux->psz_path );
55         if( !f.isNull() && f.tag() )
56         {
57             TagLib::Tag *tag = f.tag();
58             vlc_meta_t *p_meta = (vlc_meta_t *)(p_demux->p_private );
59
60             vlc_meta_SetTitle( p_meta, tag->title().toCString( true ) );
61             vlc_meta_SetArtist( p_meta, tag->artist().toCString( true ) );
62
63             if( TagLib::MPEG::File *mpeg =
64                            dynamic_cast<TagLib::MPEG::File *>(f.file() ) )
65             {
66                 if( mpeg->ID3v2Tag() && checkID3Image( mpeg->ID3v2Tag() ) )
67                 {
68                     fprintf( stderr, "%s has APIC\n", p_meta->psz_title );
69                     vlc_meta_SetArtURL( p_meta, "APIC" ); /// Means that the interface will use us to actually fetch it
70                 }
71             }
72             return VLC_SUCCESS;
73         }
74     }
75     return VLC_EGENERIC;
76 }