1
/* Copyright (C) 2004 Scott Wheeler <wheeler@kde.org>
3
* Redistribution and use in source and binary forms, with or without
4
* modification, are permitted provided that the following conditions
7
* 1. Redistributions of source code must retain the above copyright
8
* notice, this list of conditions and the following disclaimer.
9
* 2. Redistributions in binary form must reproduce the above copyright
10
* notice, this list of conditions and the following disclaimer in the
11
* documentation and/or other materials provided with the distribution.
13
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
14
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
15
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
16
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
17
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
#include <sys/types.h>
40
bool isArgument(const char *s)
42
return strlen(s) == 2 && s[0] == '-';
45
bool isFile(const char *s)
49
return ::stat(s, &st) == 0 && (st.st_mode & (S_IFREG));
51
return ::stat(s, &st) == 0 && (st.st_mode & (S_IFREG | S_IFLNK));
58
cout << "Usage: tagwriter <fields> <files>" << endl;
60
cout << "Where the valid fields are:" << endl;
61
cout << " -t <title>" << endl;
62
cout << " -a <artist>" << endl;
63
cout << " -A <album>" << endl;
64
cout << " -c <comment>" << endl;
65
cout << " -g <genre>" << endl;
66
cout << " -y <year>" << endl;
67
cout << " -T <track>" << endl;
73
int main(int argc, char *argv[])
75
TagLib::List<TagLib::FileRef> fileList;
77
while(argc > 0 && isFile(argv[argc - 1])) {
79
TagLib::FileRef f(argv[argc - 1]);
81
if(!f.isNull() && f.tag())
87
if(fileList.isEmpty())
90
for(int i = 1; i < argc - 1; i += 2) {
92
if(isArgument(argv[i]) && i + 1 < argc && !isArgument(argv[i + 1])) {
94
char field = argv[i][1];
95
TagLib::String value = argv[i + 1];
97
TagLib::List<TagLib::FileRef>::Iterator it;
98
for(it = fileList.begin(); it != fileList.end(); ++it) {
100
TagLib::Tag *t = (*it).tag();
113
t->setComment(value);
119
t->setYear(value.toInt());
122
t->setTrack(value.toInt());
134
TagLib::List<TagLib::FileRef>::Iterator it;
135
for(it = fileList.begin(); it != fileList.end(); ++it)
136
(*it).file()->save();