From 6dbc340899059af9921f9c9a696327b7e8c382c5 Mon Sep 17 00:00:00 2001 From: Maxime Leblanc Date: Mon, 14 Jul 2014 18:19:29 +0200 Subject: [PATCH] Examples: adds picture handling --- examples/tagreader.cpp | 17 ++++++++++------- examples/tagwriter.cpp | 38 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 46 insertions(+), 9 deletions(-) diff --git a/examples/tagreader.cpp b/examples/tagreader.cpp index ac81be62..2d17cce3 100644 --- a/examples/tagreader.cpp +++ b/examples/tagreader.cpp @@ -28,6 +28,7 @@ #include #include +#include #include using namespace std; @@ -45,13 +46,15 @@ int main(int argc, char *argv[]) TagLib::Tag *tag = f.tag(); cout << "-- TAG (basic) --" << endl; - cout << "title - \"" << tag->title() << "\"" << endl; - cout << "artist - \"" << tag->artist() << "\"" << endl; - cout << "album - \"" << tag->album() << "\"" << endl; - cout << "year - \"" << tag->year() << "\"" << endl; - cout << "comment - \"" << tag->comment() << "\"" << endl; - cout << "track - \"" << tag->track() << "\"" << endl; - cout << "genre - \"" << tag->genre() << "\"" << endl; + cout << "title - \"" << tag->title() << "\"" << endl; + cout << "artist - \"" << tag->artist() << "\"" << endl; + cout << "album - \"" << tag->album() << "\"" << endl; + cout << "year - \"" << tag->year() << "\"" << endl; + cout << "comment - \"" << tag->comment() << "\"" << endl; + cout << "track - \"" << tag->track() << "\"" << endl; + cout << "genre - \"" << tag->genre() << "\"" << endl; + if(!tag->pictures().isEmpty()) + cout << "pictures -" << tag->pictures() << endl; TagLib::PropertyMap tags = f.file()->properties(); diff --git a/examples/tagwriter.cpp b/examples/tagwriter.cpp index f2896d76..3239a56d 100644 --- a/examples/tagwriter.cpp +++ b/examples/tagwriter.cpp @@ -22,7 +22,9 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include #include +#include #include #include @@ -33,6 +35,8 @@ #include #include #include +#include + #include using namespace std; @@ -65,6 +69,7 @@ void usage() cout << " -g " << endl; cout << " -y " << endl; cout << " -T " << endl; + cout << " -p " << endl; cout << endl; exit(1); @@ -87,14 +92,16 @@ int main(int argc, char *argv[]) if(fileList.isEmpty()) usage(); + if(argv[argc-1][1] == 'p') + argc++; + for(int i = 1; i < argc - 1; i += 2) { if(isArgument(argv[i]) && i + 1 < argc && !isArgument(argv[i + 1])) { char field = argv[i][1]; TagLib::String value = argv[i + 1]; - - TagLib::List::ConstIterator it; + TagLib::List::Iterator it; for(it = fileList.begin(); it != fileList.end(); ++it) { TagLib::Tag *t = (*it).tag(); @@ -121,6 +128,33 @@ int main(int argc, char *argv[]) case 'T': t->setTrack(value.toInt()); break; + case 'p': + { + if(!isFile(value.toCString())) + { + cout << value.toCString() << " not found." << endl; + return 1; + } + ifstream picture; + picture.open(value.toCString()); + stringstream buffer; + buffer << picture.rdbuf(); + picture.close(); + TagLib::String buf(buffer.str()); + TagLib::ByteVector data(buf.data(TagLib::String::Latin1)); + if(!data.find("JFIF")) + { + cout << value.toCString() << " is not a JPEG." << endl; + return 1; + } + TagLib::Picture pic(data, + TagLib::Picture::FrontCover, + "image/jpeg", + "Added with taglib"); + TagLib::PictureMap picMap(pic); + t->setPictures(picMap); + } + break; default: usage(); break;