X-Git-Url: http://git.treefish.org/~alex/usetaglib.git/blobdiff_plain/13ffc39ada83ca2054654021357028b219543a15..d2b5c66be510d1b66430d33b79e7c2489caabaed:/usetaglib.cpp diff --git a/usetaglib.cpp b/usetaglib.cpp index 7909009..d4522d2 100644 --- a/usetaglib.cpp +++ b/usetaglib.cpp @@ -54,39 +54,32 @@ tagpair splitToTagPair (const string &rawarg) return make_pair(rawarg.substr(0, delpos), rawarg.substr(delpos+1, string::npos)); } -void action_eraseTag (const TagLib::FileRef f, const string &key) +void action_eraseTag (TagLib::PropertyMap &propmap, const string &key) { - TagLib::PropertyMap propmap = f.file()->properties(); propmap.erase(key); - f.file()->setProperties(propmap); } -void action_replaceTag (const TagLib::FileRef f, const tagpair &tagPair) +void action_replaceTag (TagLib::PropertyMap &propmap, const tagpair &tagPair) { - TagLib::PropertyMap propmap = f.file()->properties(); propmap.replace(tagPair.first, argToStringList(tagPair.second)); - f.file()->setProperties(propmap); } -void action_insertTag (const TagLib::FileRef f, const tagpair &tagPair) +void action_insertTag (TagLib::PropertyMap &propmap, const tagpair &tagPair) { - TagLib::PropertyMap propmap = f.file()->properties(); propmap.insert(tagPair.first, argToStringList(tagPair.second)); - f.file()->setProperties(propmap); } -int action_printTags (const TagLib::FileRef f) +int action_printTags (const TagLib::FileRef f, TagLib::PropertyMap &propmap) { if(f.tag()) { - TagLib::PropertyMap tags = f.file()->properties(); unsigned int longest = 0; - for(TagLib::PropertyMap::ConstIterator i = tags.begin(); i != tags.end(); ++i) { + for(TagLib::PropertyMap::ConstIterator i = propmap.begin(); i != propmap.end(); ++i) { if (i->first.size() > longest) { longest = i->first.size(); } } cout << "-- TAG (properties) --" << endl; - for(TagLib::PropertyMap::ConstIterator i = tags.begin(); i != tags.end(); ++i) { + for(TagLib::PropertyMap::ConstIterator i = propmap.begin(); i != propmap.end(); ++i) { for(TagLib::StringList::ConstIterator j = i->second.begin(); j != i->second.end(); ++j) { cout << i->first << "=" << *j << endl; } @@ -115,7 +108,7 @@ int action_printAudio (const TagLib::FileRef f) } void printHelp () -{ +{ cout << "Usage: usetaglib [ACTION]... [FILE]..." << endl; cout << "List and edit tags on mediafiles in formats supported by libtag." << endl; cout << endl; @@ -221,11 +214,14 @@ int main(int argc, char *argv[]) if(f.isNull()) continue; + + TagLib::PropertyMap propmap = f.file()->properties(); + bool FCHANGED = false; for (actionqueue::iterator actit = requestedActions.begin(); actit != requestedActions.end(); ++actit) { switch (actit->first) { case LIST: - action_printTags(f); + action_printTags(f, propmap); break; case AUDIO: @@ -233,20 +229,26 @@ int main(int argc, char *argv[]) break; case ERASE: - action_eraseTag(f, actit->second); + action_eraseTag(propmap, actit->second); + FCHANGED = true; break; case REPLACE: - action_replaceTag(f, splitToTagPair(actit->second)); + action_replaceTag(propmap, splitToTagPair(actit->second)); + FCHANGED = true; break; case INSERT: - action_insertTag(f, splitToTagPair(actit->second)); + action_insertTag(propmap, splitToTagPair(actit->second)); + FCHANGED = true; break; } } - - f.file()->save(); + + if (FCHANGED) { + f.file()->setProperties(propmap); + f.file()->save(); + } } return 0;