diff options
author | Stephen F. Booth <me@sbooth.org> | 2015-09-23 23:09:55 -0400 |
---|---|---|
committer | Stephen F. Booth <me@sbooth.org> | 2015-09-23 23:09:55 -0400 |
commit | ab30ec3a6fc22a58261b1fab3882a0b6f15fa16a (patch) | |
tree | ee1f7e297c619a1c6a57abf80f7b2d0f740eb332 | |
parent | 5ca4cd2f520e48d4decc597e572019cadca41d7a (diff) | |
parent | 0a9068780501887dd731c60e441139c5caefa92d (diff) |
Merge pull request #664 from pbhd/master
add options R, I, D for replace/insert/delete of arbitrary tags
-rw-r--r-- | examples/tagwriter.cpp | 46 |
1 files changed, 46 insertions, 0 deletions
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 <iostream> +#include <iomanip> #include <string.h> #include <stdio.h> @@ -34,6 +35,7 @@ #include <fileref.h> #include <tfile.h> #include <tag.h> +#include <tpropertymap.h> using namespace std; @@ -65,11 +67,32 @@ void usage() cout << " -g <genre>" << endl; cout << " -y <year>" << endl; cout << " -T <track>" << endl; + cout << " -R <tagname> <tagvalue>" << endl; + cout << " -I <tagname> <tagvalue>" << endl; + cout << " -D <tagname>" << 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<TagLib::FileRef> 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; |