X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fmeta_engine%2Ftaglib.cpp;h=52fc2ee299c102fd261a43353e2db4d6cbea4d58;hb=9e595c955f1aebae18435f0f5c740802ce347852;hp=e317b7ce0243a587378be2425834ceae0183bd28;hpb=b6198c885bce18a31b3c6adbafed66169c7ff200;p=vlc diff --git a/modules/meta_engine/taglib.cpp b/modules/meta_engine/taglib.cpp index e317b7ce02..52fc2ee299 100644 --- a/modules/meta_engine/taglib.cpp +++ b/modules/meta_engine/taglib.cpp @@ -20,7 +20,6 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/ -#include #include #include @@ -29,13 +28,20 @@ #include #include +#include #include #include #include +#if 0 +#include +#endif +#include +#include +#include +#include #include -#if 0 //for artist and album id #include -#endif +//#include /* parse the tags without taglib helpers? */ static int ReadMeta ( vlc_object_t * ); static int DownloadArt ( vlc_object_t * ); @@ -95,20 +101,91 @@ static int ReadMeta( vlc_object_t *p_this ) if( !p_demux->p_private ) p_demux->p_private = (void*)vlc_meta_New(); TagLib::FileRef f( p_demux->psz_path ); + + if( !f.isNull() ) + { + if( TagLib::Ogg::Vorbis::File *p_ogg_v = + dynamic_cast(f.file() ) ) + { + int i_ogg_v_length = p_ogg_v->audioProperties()->length(); + + input_thread_t *p_input = (input_thread_t *)vlc_object_find( p_demux, VLC_OBJECT_INPUT, FIND_PARENT ); + if( p_input ) + { + input_item_t *p_item = input_GetItem( p_input ); + if( p_item ) + { + vlc_mutex_lock( &p_item->lock ); + p_item->i_duration = i_ogg_v_length * 1000000; + vlc_mutex_unlock( &p_item->lock ); + } + vlc_object_release( p_input ); + } + } +#if 0 /* at this moment, taglib is unable to detect ogg/flac files + * becauses type detection is based on file extension: + * ogg = ogg/vorbis + * flac = flac + * ø = ogg/flac + */ + else if( TagLib::Ogg::FLAC::File *p_ogg_f = + dynamic_cast(f.file() ) ) + { + long i_ogg_f_length = p_ogg_f->streamLength(); + input_thread_t *p_input = (input_thread_t *)vlc_object_find( p_demux, VLC_OBJECT_INPUT, FIND_PARENT ); + if( p_input ) + { + input_item_t *p_item = input_GetItem( p_input ); + if( p_item ) + { + vlc_mutex_lock( &p_item->lock ); + p_item->i_duration = i_ogg_f_length * 1000000; + vlc_mutex_unlock( &p_item->lock ); + } + vlc_object_release( p_input ); + } + } +#endif + else if( TagLib::FLAC::File *p_flac = + dynamic_cast(f.file() ) ) + { + long i_flac_length = p_flac->audioProperties()->length(); + input_thread_t *p_input = (input_thread_t *)vlc_object_find( p_demux, VLC_OBJECT_INPUT, FIND_PARENT ); + if( p_input ) + { + input_item_t *p_item = input_GetItem( p_input ); + if( p_item ) + { + vlc_mutex_lock( &p_item->lock ); + p_item->i_duration = i_flac_length * 1000000; + vlc_mutex_unlock( &p_item->lock ); + } + vlc_object_release( p_input ); + } + } + } + if( !f.isNull() && f.tag() && !f.tag()->isEmpty() ) { TagLib::Tag *tag = f.tag(); vlc_meta_t *p_meta = (vlc_meta_t *)(p_demux->p_private ); #define SET( foo, bar ) vlc_meta_Set##foo( p_meta, tag->bar ().toCString(true)) +#define SETINT( foo, bar ) { \ + char psz_tmp[10]; \ + snprintf( (char*)psz_tmp, 10, "%d", tag->bar() ); \ + vlc_meta_Set##foo( p_meta, (char*)psz_tmp ); \ + } + SET( Title, title ); SET( Artist, artist ); SET( Album, album ); -// SET( Comment, comment ); + SET( Description, comment ); SET( Genre, genre ); -// SET( Year, year ); Gra, this is an int, need to convert -// SET( Tracknum , track ); Same + SETINT( Date, year ); + SETINT( Tracknum , track ); #undef SET +#undef SETINT if( TagLib::MPEG::File *p_mpeg = dynamic_cast(f.file() ) ) @@ -138,8 +215,7 @@ static int ReadMeta( vlc_object_t *p_this ) free( psz_ufid ); } } - /* musicbrainz artist and album id: not useful yet */ -#if 0 + list = tag->frameListMap()["TXXX"]; TagLib::ID3v2::UserTextIdentificationFrame* p_txxx; for( TagLib::ID3v2::FrameList::Iterator iter = list.begin(); @@ -147,14 +223,47 @@ static int ReadMeta( vlc_object_t *p_this ) { p_txxx = dynamic_cast(*iter); const char *psz_desc= p_txxx->description().toCString(); +#if 0 /* musicbrainz artist and album id: not useful (yet?) */ if( !strncmp( psz_desc, "MusicBrainz Artist Id", 21 ) ) vlc_meta_SetArtistID( p_meta, p_txxx->fieldList().toString().toCString()); if( !strncmp( psz_desc, "MusicBrainz Album Id", 20 ) ) vlc_meta_SetAlbumID( p_meta, p_txxx->fieldList().toString().toCString()); +#endif + vlc_meta_AddExtra( p_meta, psz_desc, + p_txxx->fieldList().toString().toCString()); + } +#if 0 + list = tag->frameListMap()["RVA2"]; + TagLib::ID3v2::RelativeVolumeFrame* p_rva2; + for( TagLib::ID3v2::FrameList::Iterator iter = list.begin(); + iter != list.end(); iter++ ) + { + p_rva2 = dynamic_cast(*iter); + /* TODO: process rva2 frames */ } #endif + list = tag->frameList(); + TagLib::ID3v2::Frame* p_t; + char psz_tag[4]; + for( TagLib::ID3v2::FrameList::Iterator iter = list.begin(); + iter != list.end(); iter++ ) + { + p_t = dynamic_cast (*iter); + memcpy( psz_tag, p_t->frameID().data(), 4); + +#define SET( foo, bar ) if( !strncmp( psz_tag, foo, 4 ) ) \ + vlc_meta_Set##bar( p_meta, p_t->toString().toCString(true)) + SET( "TPUB", Publisher ); + SET( "TCOP", Copyright ); + SET( "TENC", EncodedBy ); + SET( "TLAN", Language ); + //SET( "POPM", Rating ); + //if( !strncmp( psz_tag, "RVA2", 4 ) ) + /* TODO */ +#undef SET + } } } @@ -166,7 +275,12 @@ static int ReadMeta( vlc_object_t *p_this ) return VLC_EGENERIC; } -#define SET(a,b) if(b) tag->set##a( b ); +#define SET(a,b) if(b) { \ + TagLib::String *psz_##a = new TagLib::String( b, \ + TagLib::String::UTF8 ); \ + tag->set##a( *psz_##a ); \ + delete psz_##a; \ + } static int WriteMeta( vlc_object_t *p_this ) { @@ -184,18 +298,39 @@ static int WriteMeta( vlc_object_t *p_this ) if( !f.isNull() && f.tag() ) { msg_Dbg( p_this, "Updating metadata for %s", p_export->psz_file ); + TagLib::Tag *tag = f.tag(); - SET( Artist, p_item->p_meta->psz_artist ); - if( p_item->p_meta->psz_title ) - tag->setTitle( p_item->p_meta->psz_title ); - else - tag->setTitle( p_item->psz_name ); - SET( Album, p_item->p_meta->psz_album ); - SET( Genre, p_item->p_meta->psz_genre ); - if( p_item->p_meta->psz_date ) - tag->setYear( atoi( p_item->p_meta->psz_date ) ); - if( p_item->p_meta->psz_tracknum ) - tag->setTrack( atoi( p_item->p_meta->psz_tracknum ) ); + + char *psz_meta; + + psz_meta = input_item_GetArtist( p_item ); + SET( Artist, psz_meta ); + free( psz_meta ); + + psz_meta = input_item_GetTitle( p_item ); + if( !psz_meta ) psz_meta = input_item_GetName( p_item ); + TagLib::String *psz_title = new TagLib::String( psz_meta, + TagLib::String::UTF8 ); + tag->setTitle( *psz_title ); + delete psz_title; + free( psz_meta ); + + psz_meta = input_item_GetAlbum( p_item ); + SET( Album, psz_meta ); + free( psz_meta ); + + psz_meta = input_item_GetGenre( p_item ); + SET( Genre, psz_meta ); + free( psz_meta ); + + psz_meta = input_item_GetDate( p_item ); + if( psz_meta ) tag->setYear( atoi( psz_meta ) ); + free( psz_meta ); + + psz_meta = input_item_GetTrackNum( p_item ); + if( psz_meta ) tag->setTrack( atoi( psz_meta ) ); + free( psz_meta ); + f.save(); return VLC_SUCCESS; }