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 ed8b0d7a..bcf99367 100644 --- a/examples/tagwriter.cpp +++ b/examples/tagwriter.cpp @@ -22,8 +22,10 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include #include #include +#include #include #include @@ -34,6 +36,8 @@ #include #include #include +#include + #include #include @@ -70,6 +74,7 @@ void usage() cout << " -R " << endl; cout << " -I " << endl; cout << " -D " << endl; + cout << " -p " << endl; cout << endl; exit(1); @@ -110,14 +115,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(); @@ -167,6 +174,31 @@ int main(int argc, char *argv[]) checkForRejectedProperties((*it).file()->setProperties(map)); 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;