1 /*****************************************************************************
2 * taglib.cpp: Taglib tag parser/writer
3 *****************************************************************************
4 * Copyright (C) 2003-2006 the VideoLAN team
7 * Authors: Clément Stenac <zorglub@videolan.org>
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.
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.
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 *****************************************************************************/
24 #include <vlc_playlist.h>
25 #include <vlc/input.h>
34 static int ReadMeta ( vlc_object_t * );
35 static int DownloadArt ( vlc_object_t * );
36 static int WriteMeta ( vlc_object_t * );
39 set_capability( "meta reader", 1000 );
40 set_callbacks( ReadMeta, NULL );
42 set_capability( "art downloader", 50 );
43 set_callbacks( DownloadArt, NULL );
45 set_capability( "meta writer", 50 );
46 set_callbacks( WriteMeta, NULL );
49 static bool checkID3Image( const TagLib::ID3v2::Tag *tag )
51 TagLib::ID3v2::FrameList l = tag->frameListMap()[ "APIC" ];
55 /* Try detecting embedded art */
56 static void DetectImage( TagLib::FileRef f, vlc_meta_t *p_meta )
58 if( TagLib::MPEG::File *mpeg =
59 dynamic_cast<TagLib::MPEG::File *>(f.file() ) )
61 if( mpeg->ID3v2Tag() && checkID3Image( mpeg->ID3v2Tag() ) )
62 vlc_meta_SetArtURL( p_meta, "APIC" );
64 else if( TagLib::FLAC::File *flac =
65 dynamic_cast<TagLib::FLAC::File *>(f.file() ) )
67 if( flac->ID3v2Tag() && checkID3Image( flac->ID3v2Tag() ) )
68 vlc_meta_SetArtURL( p_meta, "APIC" );
71 /* This needs special additions to taglib */
72 * else if( TagLib::MP4::File *mp4 =
73 dynamic_cast<TagLib::MP4::File *>( f.file() ) )
75 TagLib::MP4::Tag *mp4tag =
76 dynamic_cast<TagLib::MP4::Tag *>( mp4->tag() );
77 if( mp4tag && mp4tag->cover().size() )
78 vlc_meta_SetArtURL( p_meta, "MP4C" );
83 static int ReadMeta( vlc_object_t *p_this )
85 demux_t *p_demux = (demux_t *)p_this;
87 if( !strncmp( p_demux->psz_access, "file", 4 ) )
89 if( !p_demux->p_private )
90 p_demux->p_private = (void*)vlc_meta_New();
91 TagLib::FileRef f( p_demux->psz_path );
92 if( !f.isNull() && f.tag() && !f.tag()->isEmpty() )
94 TagLib::Tag *tag = f.tag();
95 vlc_meta_t *p_meta = (vlc_meta_t *)(p_demux->p_private );
97 #define SET( foo, bar ) vlc_meta_Set##foo( p_meta, tag->bar ().toCString(true))
99 SET( Artist, artist );
101 // SET( Comment, comment );
103 // SET( Year, year ); Gra, this is an int, need to convert
104 // SET( Tracknum , track ); Same
106 DetectImage( f, p_meta );
114 static int WriteMeta( vlc_object_t *p_this )
116 playlist_t *p_playlist = (playlist_t *)p_this;
117 meta_export_t *p_export = (meta_export_t *)p_playlist->p_private;
118 input_item_t *p_item = p_export->p_item;
120 TagLib::FileRef f( p_export->psz_file );
121 if( !f.isNull() && f.tag() )
123 TagLib::Tag *tag = f.tag();
124 tag->setArtist( p_item->p_meta->psz_artist );
131 static int DownloadArt( vlc_object_t *p_this )
133 /* We need to be passed the file name
134 * Fetch the thing from the file, save it to the cache folder