From 8ecfba0c30c2fe16e08c6c29ace9e6f044e935b7 Mon Sep 17 00:00:00 2001 From: Maxime Leblanc Date: Thu, 17 Jul 2014 13:22:59 +0200 Subject: [PATCH 1/2] APE: full picture handling --- taglib/ape/apetag.cpp | 97 ++++++++++++++++++++++++++++++++++++++++++- taglib/ape/apetag.h | 11 +++++ 2 files changed, 107 insertions(+), 1 deletion(-) diff --git a/taglib/ape/apetag.cpp b/taglib/ape/apetag.cpp index 19423e66..4acc4d7e 100644 --- a/taglib/ape/apetag.cpp +++ b/taglib/ape/apetag.cpp @@ -130,7 +130,44 @@ TagLib::uint APE::Tag::track() const TagLib::PictureMap APE::Tag::pictures() const { - return PictureMap(); + PictureMap map; + if( d->itemListMap.contains(FRONT_COVER)) + { + Item front = d->itemListMap[FRONT_COVER]; + if(Item::Binary == front.type()) + { + ByteVector picture = front.binaryData(); + int index = picture.find('\0'); + if( index < picture.size() ) + { + ByteVector desc = picture.mid(0, index + 1); + String mime = "image/jpeg"; + ByteVector data = picture.mid(index + 1); + Picture p(data, Picture::FrontCover, mime, desc); + map.insert(p); + } + } + } + + if( d->itemListMap.contains(BACK_COVER)) + { + Item back = d->itemListMap[BACK_COVER]; + if(Item::Binary == back.type()) + { + ByteVector picture = back.binaryData(); + int index = picture.find('\0'); + if( index < picture.size() ) + { + ByteVector desc = picture.mid(0, index + 1); + String mime = "image/jpeg"; + ByteVector data = picture.mid(index + 1); + Picture p(data, Picture::BackCover, mime, desc); + map.insert(p); + } + } + } + + return PictureMap(map); } void APE::Tag::setTitle(const String &s) @@ -176,6 +213,64 @@ void APE::Tag::setTrack(uint i) void APE::Tag::setPictures(const PictureMap &l) { + removeItem(FRONT_COVER); + removeItem(BACK_COVER); + for(PictureMap::ConstIterator pictureMapIt = l.begin(); + pictureMapIt != l.end(); + ++pictureMapIt) + { + Picture::Type type = pictureMapIt->first; + if(Picture::FrontCover != type && Picture::BackCover != type) + { + std::cout << "APE: Trying to add a picture with wrong type" + << std::endl; + continue; + } + + const char* id; + switch(type) + { + case Picture::FrontCover: + id = FRONT_COVER; + break; + case Picture::BackCover: + id = BACK_COVER; + break; + default: + id = FRONT_COVER; + break; + } + + PictureList list = pictureMapIt->second; + for( PictureList::ConstIterator pictureListIt = list.begin(); + pictureListIt != list.end(); + ++pictureListIt) + { + Picture picture = *pictureListIt; + if(d->itemListMap.contains(id)) + { + std::cout << "APE: Already added a picture of type " + << id + << " '" + << picture.description() + << "' " + << "and next are being ignored" + << std::endl; + break; + } + + ByteVector data = picture.description().data(String::Latin1) + .append('\0') + .append(picture.data()); + + Item item; + item.setKey(id); + item.setType(Item::Binary); + item.setBinaryData(data); + setItem(item.key(), item); + } + } + } // conversions of tag keys between what we use in PropertyMap and what's usual diff --git a/taglib/ape/apetag.h b/taglib/ape/apetag.h index 2fd2168c..b24967b9 100644 --- a/taglib/ape/apetag.h +++ b/taglib/ape/apetag.h @@ -34,6 +34,9 @@ #include "apeitem.h" +#define FRONT_COVER "COVER ART (FRONT)" +#define BACK_COVER "COVER ART (BACK)" + namespace TagLib { class File; @@ -94,6 +97,14 @@ namespace TagLib { virtual String genre() const; virtual uint year() const; virtual uint track() const; + + /** + * @brief pictures + * According to : + * http://www.hydrogenaud.io/forums/index.php?showtopic=40603&st=50&p=504669&#entry504669 + * http://git.videolan.org/?p=vlc.git;a=blob;f=modules/meta_engine/taglib.cpp + * @return + */ virtual PictureMap pictures() const; virtual void setTitle(const String &s); From 35cf4afdba6d7adfb43f4fe1872a48e8cd2fce3f Mon Sep 17 00:00:00 2001 From: Maxime Leblanc Date: Wed, 9 Sep 2015 10:26:26 +0200 Subject: [PATCH 2/2] apetag.cpp: run astyle --- taglib/ape/apetag.cpp | 169 ++++++++++++++++++++---------------------- 1 file changed, 79 insertions(+), 90 deletions(-) diff --git a/taglib/ape/apetag.cpp b/taglib/ape/apetag.cpp index 4acc4d7e..ebf3287f 100644 --- a/taglib/ape/apetag.cpp +++ b/taglib/ape/apetag.cpp @@ -130,44 +130,38 @@ TagLib::uint APE::Tag::track() const TagLib::PictureMap APE::Tag::pictures() const { - PictureMap map; - if( d->itemListMap.contains(FRONT_COVER)) - { - Item front = d->itemListMap[FRONT_COVER]; - if(Item::Binary == front.type()) - { - ByteVector picture = front.binaryData(); - int index = picture.find('\0'); - if( index < picture.size() ) - { - ByteVector desc = picture.mid(0, index + 1); - String mime = "image/jpeg"; - ByteVector data = picture.mid(index + 1); - Picture p(data, Picture::FrontCover, mime, desc); - map.insert(p); - } - } + PictureMap map; + if(d->itemListMap.contains(FRONT_COVER)) { + Item front = d->itemListMap[FRONT_COVER]; + if(Item::Binary == front.type()) { + ByteVector picture = front.binaryData(); + int index = picture.find('\0'); + if(index < picture.size()) { + ByteVector desc = picture.mid(0, index + 1); + String mime = "image/jpeg"; + ByteVector data = picture.mid(index + 1); + Picture p(data, Picture::FrontCover, mime, desc); + map.insert(p); + } } + } - if( d->itemListMap.contains(BACK_COVER)) - { - Item back = d->itemListMap[BACK_COVER]; - if(Item::Binary == back.type()) - { - ByteVector picture = back.binaryData(); - int index = picture.find('\0'); - if( index < picture.size() ) - { - ByteVector desc = picture.mid(0, index + 1); - String mime = "image/jpeg"; - ByteVector data = picture.mid(index + 1); - Picture p(data, Picture::BackCover, mime, desc); - map.insert(p); - } - } + if(d->itemListMap.contains(BACK_COVER)) { + Item back = d->itemListMap[BACK_COVER]; + if(Item::Binary == back.type()) { + ByteVector picture = back.binaryData(); + int index = picture.find('\0'); + if(index < picture.size()) { + ByteVector desc = picture.mid(0, index + 1); + String mime = "image/jpeg"; + ByteVector data = picture.mid(index + 1); + Picture p(data, Picture::BackCover, mime, desc); + map.insert(p); + } } + } - return PictureMap(map); + return PictureMap(map); } void APE::Tag::setTitle(const String &s) @@ -213,64 +207,59 @@ void APE::Tag::setTrack(uint i) void APE::Tag::setPictures(const PictureMap &l) { - removeItem(FRONT_COVER); - removeItem(BACK_COVER); - for(PictureMap::ConstIterator pictureMapIt = l.begin(); - pictureMapIt != l.end(); - ++pictureMapIt) - { - Picture::Type type = pictureMapIt->first; - if(Picture::FrontCover != type && Picture::BackCover != type) - { - std::cout << "APE: Trying to add a picture with wrong type" - << std::endl; - continue; - } - - const char* id; - switch(type) - { - case Picture::FrontCover: - id = FRONT_COVER; - break; - case Picture::BackCover: - id = BACK_COVER; - break; - default: - id = FRONT_COVER; - break; - } - - PictureList list = pictureMapIt->second; - for( PictureList::ConstIterator pictureListIt = list.begin(); - pictureListIt != list.end(); - ++pictureListIt) - { - Picture picture = *pictureListIt; - if(d->itemListMap.contains(id)) - { - std::cout << "APE: Already added a picture of type " - << id - << " '" - << picture.description() - << "' " - << "and next are being ignored" - << std::endl; - break; - } - - ByteVector data = picture.description().data(String::Latin1) - .append('\0') - .append(picture.data()); - - Item item; - item.setKey(id); - item.setType(Item::Binary); - item.setBinaryData(data); - setItem(item.key(), item); - } + removeItem(FRONT_COVER); + removeItem(BACK_COVER); + for(PictureMap::ConstIterator pictureMapIt = l.begin(); + pictureMapIt != l.end(); + ++pictureMapIt) { + Picture::Type type = pictureMapIt->first; + if(Picture::FrontCover != type && Picture::BackCover != type) { + std::cout << "APE: Trying to add a picture with wrong type" + << std::endl; + continue; } + const char *id; + switch(type) { + case Picture::FrontCover: + id = FRONT_COVER; + break; + case Picture::BackCover: + id = BACK_COVER; + break; + default: + id = FRONT_COVER; + break; + } + + PictureList list = pictureMapIt->second; + for(PictureList::ConstIterator pictureListIt = list.begin(); + pictureListIt != list.end(); + ++pictureListIt) { + Picture picture = *pictureListIt; + if(d->itemListMap.contains(id)) { + std::cout << "APE: Already added a picture of type " + << id + << " '" + << picture.description() + << "' " + << "and next are being ignored" + << std::endl; + break; + } + + ByteVector data = picture.description().data(String::Latin1) + .append('\0') + .append(picture.data()); + + Item item; + item.setKey(id); + item.setType(Item::Binary); + item.setBinaryData(data); + setItem(item.key(), item); + } + } + } // conversions of tag keys between what we use in PropertyMap and what's usual