Load embedded cover art from ogg files. Thanks markwatkinson. Fixes issue #1232

This commit is contained in:
David Sansome 2011-01-23 15:50:59 +00:00
parent fe818e5597
commit 4291d21eab
2 changed files with 38 additions and 9 deletions

View File

@ -29,6 +29,10 @@
#include <taglib/fileref.h>
#include <taglib/id3v2tag.h>
#include <taglib/mpegfile.h>
#include <taglib/oggfile.h>
#include <taglib/oggflacfile.h>
#include <taglib/speexfile.h>
#include <taglib/vorbisfile.h>
const char* AlbumCoverLoader::kManuallyUnsetCover = "(unset)";
const char* AlbumCoverLoader::kEmbeddedCover = "(embedded)";
@ -161,21 +165,43 @@ QImage AlbumCoverLoader::LoadFromTaglib(const QString& filename) {
TagLib::FileRef ref(QFile::encodeName(filename).constData());
#endif
if (ref.isNull())
if (ref.isNull() || !ref.file())
return ret;
// mp3
TagLib::MPEG::File* file = dynamic_cast<TagLib::MPEG::File*>(ref.file());
if (!file || !file->ID3v2Tag())
if (file && file->ID3v2Tag()) {
TagLib::ID3v2::FrameList apic_frames = file->ID3v2Tag()->frameListMap()["APIC"];
if (apic_frames.isEmpty())
return ret;
TagLib::ID3v2::AttachedPictureFrame* pic =
static_cast<TagLib::ID3v2::AttachedPictureFrame*>(apic_frames.front());
ret.loadFromData((const uchar*) pic->picture().data(), pic->picture().size());
return ret;
}
// Ogg vorbis/flac/speex
TagLib::Ogg::XiphComment* xiph_comment =
dynamic_cast<TagLib::Ogg::XiphComment*>(ref.file()->tag());
TagLib::ID3v2::FrameList apic_frames = file->ID3v2Tag()->frameListMap()["APIC"];
if (apic_frames.isEmpty())
if (xiph_comment) {
TagLib::Ogg::FieldListMap map = xiph_comment->fieldListMap();
// Ogg lacks a definitive standard for embedding cover art, but it seems
// b64 encoding a field called COVERART is the general convention
if (!map.contains("COVERART"))
return ret;
QByteArray image_data_b64(map["COVERART"].toString().toCString());
QByteArray image_data = QByteArray::fromBase64(image_data_b64);
if (!ret.loadFromData(image_data))
ret.loadFromData(image_data_b64); //maybe it's not b64 after all
return ret;
TagLib::ID3v2::AttachedPictureFrame* pic =
static_cast<TagLib::ID3v2::AttachedPictureFrame*>(apic_frames.front());
ret.loadFromData((const uchar*) pic->picture().data(), pic->picture().size());
}
return ret;
}

View File

@ -420,6 +420,9 @@ void Song::ParseOggTag(const TagLib::Ogg::FieldListMap& map, const QTextCodec* c
if (!map["COMPILATION"].isEmpty() )
*compilation = TStringToQString( map["COMPILATION"].front() ).trimmed();
if (!map["COVERART"].isEmpty())
d->art_automatic_ = AlbumCoverLoader::kEmbeddedCover;
}
void Song::GuessFileType(TagLib::FileRef* fileref) {