void read(MPD::MutableSong &s) { TagLib::FileRef f(s.getURI().c_str()); if (f.isNull()) return; s.setDuration(f.audioProperties()->length()); if (auto mpeg_file = dynamic_cast<TagLib::MPEG::File *>(f.file())) { if (auto id3v1 = mpeg_file->ID3v1Tag()) readID3v1Tags(s, id3v1); if (auto id3v2 = mpeg_file->ID3v2Tag()) readID3v2Tags(s, id3v2); } else if (auto ogg_file = dynamic_cast<TagLib::Ogg::Vorbis::File *>(f.file())) { if (auto xiph = ogg_file->tag()) readXiphComments(s, xiph); } else if (auto flac_file = dynamic_cast<TagLib::FLAC::File *>(f.file())) { if (auto xiph = flac_file->xiphComment()) readXiphComments(s, xiph); } else readCommonTags(s, f.tag()); }
Meta::ReplayGainTagMap Meta::readReplayGainTags( const TagLib::FileRef &fileref ) { Meta::ReplayGainTagMap map; // NB: we can't get replay gain info from MPC files, since it's stored in some magic place // and not in the APE tags, and taglib doesn't let us access the information (unless // we want to parse the file ourselves). // FIXME: should we try getting the info from the MPC APE tag just in case? if ( TagLib::MPEG::File *file = dynamic_cast<TagLib::MPEG::File *>( fileref.file() ) ) { if ( file->ID3v2Tag() ) map = readID3v2Tags( file->ID3v2Tag() ); if ( map.isEmpty() && file->APETag() ) map = readAPETags( file->APETag() ); } else if ( TagLib::Ogg::Vorbis::File *file = dynamic_cast<TagLib::Ogg::Vorbis::File *>( fileref.file() ) ) { if ( file->tag() ) map = readXiphTags( file->tag() ); } else if ( TagLib::FLAC::File *file = dynamic_cast<TagLib::FLAC::File *>( fileref.file() ) ) { if ( file->xiphComment() ) map = readXiphTags( file->xiphComment() ); if ( map.isEmpty() && file->ID3v2Tag() ) map = readID3v2Tags( file->ID3v2Tag() ); } else if ( TagLib::Ogg::FLAC::File *file = dynamic_cast<TagLib::Ogg::FLAC::File *>( fileref.file() ) ) { if ( file->tag() ) map = readXiphTags( file->tag() ); } else if ( TagLib::WavPack::File *file = dynamic_cast<TagLib::WavPack::File *>( fileref.file() ) ) { if ( file->APETag() ) map = readAPETags( file->APETag() ); } else if ( TagLib::TrueAudio::File *file = dynamic_cast<TagLib::TrueAudio::File *>( fileref.file() ) ) { if ( file->ID3v2Tag() ) map = readID3v2Tags( file->ID3v2Tag() ); } else if ( TagLib::Ogg::Speex::File *file = dynamic_cast<TagLib::Ogg::Speex::File *>( fileref.file() ) ) { if ( file->tag() ) map = readXiphTags( file->tag() ); } else if ( TagLib::MPC::File *file = dynamic_cast<TagLib::MPC::File *>( fileref.file() ) ) { // This is NOT the correct way to get replay gain tags from MPC files, but // taglib doesn't allow us access to the real information. // This allows people to work around this issue by copying their replay gain // information to the APE tag. if ( file->APETag() ) map = readAPETags( file->APETag() ); } else if ( TagLib::ASF::File *file = dynamic_cast<TagLib::ASF::File *>( fileref.file() ) ) { if ( file->tag() ) map = readASFTags( file->tag() ); } // See comment above #ifdef DO_NOT_USE_THIS_UNTIL_FIXED else if ( TagLib::MP4::File *file = dynamic_cast<TagLib::MP4::File *>( fileref.file() ) ) { if ( file->tag() ) map = readMP4Tags( file->getMP4Tag() ); } #endif return map; }