From ccb1d036f2341dd18fe0101c567fdaf70316a373 Mon Sep 17 00:00:00 2001 From: Maxime Leblanc Date: Wed, 16 Jul 2014 10:26:58 +0200 Subject: [PATCH] ID3v2: full picture handling --- taglib/mpeg/id3v2/id3v2tag.cpp | 176 ++++++++++++++++++++++++++++++++- 1 file changed, 175 insertions(+), 1 deletion(-) diff --git a/taglib/mpeg/id3v2/id3v2tag.cpp b/taglib/mpeg/id3v2/id3v2tag.cpp index c5c07320..315634eb 100644 --- a/taglib/mpeg/id3v2/id3v2tag.cpp +++ b/taglib/mpeg/id3v2/id3v2tag.cpp @@ -40,6 +40,7 @@ #include "tpropertymap.h" #include "tdebug.h" +#include "frames/attachedpictureframe.h" #include "frames/textidentificationframe.h" #include "frames/commentsframe.h" #include "frames/urllinkframe.h" @@ -241,7 +242,89 @@ TagLib::uint ID3v2::Tag::track() const TagLib::PictureMap ID3v2::Tag::pictures() const { - return PictureMap(); + if(!d->frameListMap.contains("APIC")) + return PictureMap(); + + PictureMap map; + FrameList frameListMap = d->frameListMap["APIC"]; + for(FrameList::ConstIterator it = frameListMap.begin(); + it != frameListMap.end(); + ++it ) + { + const AttachedPictureFrame* frame = static_cast(*it); + Picture::Type type; + switch (frame->type()) { + case AttachedPictureFrame::Other: + type = Picture::Other; + break; + case AttachedPictureFrame::FileIcon: + type = Picture::FileIcon; + break; + case AttachedPictureFrame::OtherFileIcon: + type = Picture::OtherFileIcon; + break; + case AttachedPictureFrame::FrontCover: + type = Picture::FrontCover; + break; + case AttachedPictureFrame::BackCover: + type = Picture::BackCover; + break; + case AttachedPictureFrame::LeafletPage: + type = Picture::LeafletPage; + break; + case AttachedPictureFrame::Media: + type = Picture::Media; + break; + case AttachedPictureFrame::LeadArtist: + type = Picture::LeadArtist; + break; + case AttachedPictureFrame::Artist: + type = Picture::Artist; + break; + case AttachedPictureFrame::Conductor: + type = Picture::Conductor; + break; + case AttachedPictureFrame::Band: + type = Picture::Band; + break; + case AttachedPictureFrame::Composer: + type = Picture::Composer; + break; + case AttachedPictureFrame::Lyricist: + type = Picture::Lyricist; + break; + case AttachedPictureFrame::RecordingLocation: + type = Picture::RecordingLocation; + break; + case AttachedPictureFrame::DuringRecording: + type = Picture::DuringRecording; + break; + case AttachedPictureFrame::DuringPerformance: + type = Picture::DuringPerformance; + break; + case AttachedPictureFrame::MovieScreenCapture: + type = Picture::MovieScreenCapture; + break; + case AttachedPictureFrame::ColouredFish: + type = Picture::ColouredFish; + break; + case AttachedPictureFrame::Illustration: + type = Picture::Illustration; + break; + case AttachedPictureFrame::BandLogo: + type = Picture::BandLogo; + break; + case AttachedPictureFrame::PublisherLogo: + type = Picture::PublisherLogo; + break; + } + Picture picture(frame->picture(), + type, + frame->mimeType(), + frame->description()); + map.insert(picture); + } + return PictureMap(map); } void ID3v2::Tag::setTitle(const String &s) @@ -321,6 +404,97 @@ void ID3v2::Tag::setTrack(uint i) void ID3v2::Tag::setPictures(const PictureMap &l) { + removeFrames("APIC"); + + for( PictureMap::ConstIterator it = l.begin(); + it != l.end(); + ++it ) + { + PictureList list = it->second; + FrameList framesAdded; + for( PictureList::ConstIterator it2 = list.begin(); + it2 != list.end(); + ++it2) + { + const Picture picture = (*it2); + AttachedPictureFrame* frame = new AttachedPictureFrame(); + frame->setPicture(picture.data()); + frame->setMimeType(picture.mime()); + frame->setDescription(picture.description()); + switch (picture.type()) { + case Picture::Other: + frame->setType(AttachedPictureFrame::Other); + break; + case Picture::FileIcon: + frame->setType(AttachedPictureFrame::FileIcon); + break; + case Picture::OtherFileIcon: + frame->setType(AttachedPictureFrame::OtherFileIcon); + break; + case Picture::FrontCover: + frame->setType(AttachedPictureFrame::FrontCover); + break; + case Picture::BackCover: + frame->setType(AttachedPictureFrame::BackCover); + break; + case Picture::LeafletPage: + frame->setType(AttachedPictureFrame::LeafletPage); + break; + case Picture::Media: + frame->setType(AttachedPictureFrame::Media); + break; + case Picture::LeadArtist: + frame->setType(AttachedPictureFrame::LeadArtist); + break; + case Picture::Artist: + frame->setType(AttachedPictureFrame::Artist); + break; + case Picture::Conductor: + frame->setType(AttachedPictureFrame::Conductor); + break; + case Picture::Band: + frame->setType(AttachedPictureFrame::Band); + break; + case Picture::Composer: + frame->setType(AttachedPictureFrame::Composer); + break; + case Picture::Lyricist: + frame->setType(AttachedPictureFrame::Lyricist); + break; + case Picture::RecordingLocation: + frame->setType(AttachedPictureFrame::RecordingLocation); + break; + case Picture::DuringRecording: + frame->setType(AttachedPictureFrame::DuringRecording); + break; + case Picture::DuringPerformance: + frame->setType(AttachedPictureFrame::DuringPerformance); + break; + case Picture::MovieScreenCapture: + frame->setType(AttachedPictureFrame::MovieScreenCapture); + break; + case Picture::ColouredFish: + frame->setType(AttachedPictureFrame::ColouredFish); + break; + case Picture::Illustration: + frame->setType(AttachedPictureFrame::Illustration); + break; + case Picture::BandLogo: + frame->setType(AttachedPictureFrame::BandLogo); + break; + case Picture::PublisherLogo: + frame->setType(AttachedPictureFrame::PublisherLogo); + break; + } + framesAdded.append(frame); + } + for(FrameList::ConstIterator it = framesAdded.begin(); + it != framesAdded.end(); + ++it) + { + addFrame(*it); + } + } } bool ID3v2::Tag::isEmpty() const