diff --git a/examples/tagwriter.cpp b/examples/tagwriter.cpp index f2896d76..ed8b0d7a 100644 --- a/examples/tagwriter.cpp +++ b/examples/tagwriter.cpp @@ -23,6 +23,7 @@ */ #include +#include #include #include @@ -34,6 +35,7 @@ #include #include #include +#include using namespace std; @@ -65,11 +67,32 @@ void usage() cout << " -g " << endl; cout << " -y " << endl; cout << " -T " << endl; + cout << " -R " << endl; + cout << " -I " << endl; + cout << " -D " << endl; cout << endl; exit(1); } +void checkForRejectedProperties(const TagLib::PropertyMap &tags) +{ // stolen from tagreader.cpp + if(tags.size() > 0) { + unsigned int longest = 0; + for(TagLib::PropertyMap::ConstIterator i = tags.begin(); i != tags.end(); ++i) { + if(i->first.size() > longest) { + longest = i->first.size(); + } + } + cout << "-- rejected TAGs (properties) --" << endl; + for(TagLib::PropertyMap::ConstIterator i = tags.begin(); i != tags.end(); ++i) { + for(TagLib::StringList::ConstIterator j = i->second.begin(); j != i->second.end(); ++j) { + cout << left << std::setw(longest) << i->first << " - " << '"' << *j << '"' << endl; + } + } + } +} + int main(int argc, char *argv[]) { TagLib::List fileList; @@ -121,6 +144,29 @@ int main(int argc, char *argv[]) case 'T': t->setTrack(value.toInt()); break; + case 'R': + case 'I': + if(i + 2 < argc) { + TagLib::PropertyMap map = (*it).file()->properties (); + if(field == 'R') { + map.replace(value, TagLib::String(argv[i + 2])); + } + else { + map.insert(value, TagLib::String(argv[i + 2])); + } + ++i; + checkForRejectedProperties((*it).file()->setProperties(map)); + } + else { + usage(); + } + break; + case 'D': { + TagLib::PropertyMap map = (*it).file()->properties(); + map.erase(value); + checkForRejectedProperties((*it).file()->setProperties(map)); + break; + } default: usage(); break;