From 9dbc165a7224f6d08ddf18f509a498694a9b47b9 Mon Sep 17 00:00:00 2001 From: Alexander Schmidt Date: Fri, 6 Feb 2015 17:06:02 +0100 Subject: [PATCH] Save once for all if tags changed. --- usetaglib.cpp | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/usetaglib.cpp b/usetaglib.cpp index 18b201f..3a8f435 100644 --- a/usetaglib.cpp +++ b/usetaglib.cpp @@ -54,25 +54,19 @@ 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) @@ -116,6 +110,8 @@ int action_printAudio (const TagLib::FileRef f) void printHelp () { + return; + cout << "Usage: usetaglib [ACTION]... [FILE]..." << endl; cout << "List and edit tags on mediafiles in formats supported by libtag." << endl; cout << endl; @@ -221,6 +217,9 @@ 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) { @@ -233,18 +232,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; } } + + if (FCHANGED) { + f.file()->setProperties(propmap); + f.file()->save(); + } } return 0; -- 2.39.2