X-Git-Url: http://git.treefish.org/~alex/usetaglib.git/blobdiff_plain/ea02326ffeb7c6cb3fc32e44cbcea5553f726c3f..3f5ca8b570c4a46224f3d99bfbc0a6a520b9c28c:/usetaglib.cpp diff --git a/usetaglib.cpp b/usetaglib.cpp index 18b201f..e54b09e 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,13 +108,15 @@ 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 << "Read and edit meta-data of audio formats supported by taglib." << endl; cout << endl; cout << "-h, --help Show this help" << endl; cout << endl; cout << "ACTIONS" << endl; + cout << " If multiple actions are specified they are executed in given order." << endl; + cout << endl; cout << setfill(' ') << setw(37) << left << " -l, --list" << "list all tags (implicit if no action specified)"<< endl; cout << setfill(' ') << setw(37) << left << " -a, --listaudio" @@ -139,8 +134,10 @@ void printHelp () cout << "EXAMPLES" << endl; cout << " usetaglib file.ogg" << endl; cout << " usetaglib -e ALBUM file.flac" << endl; - cout << " usetaglib -i ARTIST=Horst=Hubert file.mp3" << endl; - cout << " usetaglib -r ARTIST=Horst file.ogg" << endl; + cout << " usetaglib -r \"ALBUM=New Album\" -i ARTIST=Horst=Hubert file.mp3" << endl; + cout << " usetaglib -r ARTIST=Horst -l file1.ogg file2.mp3" << endl; + cout << " usetaglib -i \"ALBUMARTIST=Horst und Hubert\" file.ogg" << endl; + cout << " usetaglib --insert=\"ALBUMARTIST=Horst und Hubert\" file.ogg" << endl; } int main(int argc, char *argv[]) @@ -221,11 +218,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,18 +233,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;