X-Git-Url: http://git.treefish.org/~alex/usetaglib.git/blobdiff_plain/5e2119a394e8163a0ac1105fae0e4ec8727eb2c3..c601670587f56d9123eb81d6d4294edc6ad1f4ae:/usetaglib.cpp
diff --git a/usetaglib.cpp b/usetaglib.cpp
index a616a2e..6a3a7a8 100644
--- a/usetaglib.cpp
+++ b/usetaglib.cpp
@@ -1,17 +1,18 @@
-/*
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see .
-*/
+/* Copyright (C) 2015 Alexander Schmidt
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
#include
#include
@@ -53,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;
}
@@ -114,21 +108,34 @@ 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;
cout << "-h, --help Show this help" << endl;
cout << endl;
cout << "ACTIONS" << endl;
- cout << setfill(' ') << setw(45) << left << " -l, --list"
+ cout << setfill(' ') << setw(37) << left << " -l, --list"
<< "list all tags (implicit if no action specified)"<< endl;
- cout << setfill(' ') << setw(45) << left << " -e, --erase=TAGNAME"
- << "erase tag with name TAGNAME"<< endl;
- cout << setfill(' ') << setw(45) << left << " -r, --replace=TAGNAME=TAGVAL[=TAGVAL...]"
- << "replace tag TAGNAME with list of values TAGVAL"<< endl;
- cout << setfill(' ') << setw(45) << left << " -i, --insert=TAGNAME=TAGVAL[=TAGVAL...]"
- << "insert list of values TAGVAL for tag TAGNAME"<< endl;
+ cout << setfill(' ') << setw(37) << left << " -a, --listaudio"
+ << "show audio information"<< endl;
+ cout << setfill(' ') << setw(37) << left << " -e, --erase=TAGNAME"
+ << "erase tag TAGNAME"<< endl;
+ cout << setfill(' ') << setw(37) << left << " -r, --replace=TAGNAME=TAGVALSPEC"
+ << "replace tag TAGNAME with value TAGVALSPEC"<< endl;
+ cout << setfill(' ') << setw(37) << left << " -i, --insert=TAGNAME=TAGVALSPEC"
+ << "insert value TAGVALSPEC for tag TAGNAME"<< endl;
+ cout << endl;
+ cout << "TAGVALSPEC" << endl;
+ cout << " a list of values separated by '=': val1=val2=val3..." << endl;
+ cout << endl;
+ 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 -i \"ALBUMARTIST=Horst und Hubert\" file.ogg" << endl;
+ cout << " usetaglib --insert=\"ALBUMARTIST=Horst und Hubert\" file.ogg" << endl;
}
int main(int argc, char *argv[])
@@ -195,20 +202,28 @@ int main(int argc, char *argv[])
}
}
+ if ( optind == argc ) {
+ printHelp();
+ return 0;
+ }
+
if (requestedActions.size() == 0)
requestedActions.push_back( make_pair(LIST, "") );
-
+
for(int i = optind; i < argc; i++) {
cout << "******************** \"" << argv[i] << "\" ********************" << endl;
TagLib::FileRef f(argv[i]);
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:
@@ -216,20 +231,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;