Remove no-longer used file.
[ardour.git] / libs / taglib / examples / tagwriter.cpp
1 /* Copyright (C) 2004 Scott Wheeler <wheeler@kde.org>
2  *
3  * Redistribution and use in source and binary forms, with or without
4  * modification, are permitted provided that the following conditions
5  * are met:
6  *
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.
12  *
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.
23  */
24
25 #include <iostream>
26 #include <string.h>
27
28 #include <stdio.h>
29 #include <sys/types.h>
30 #include <sys/stat.h>
31 #include <stdlib.h>
32
33 #include <tlist.h>
34 #include <fileref.h>
35 #include <tfile.h>
36 #include <tag.h>
37
38 using namespace std;
39
40 bool isArgument(const char *s)
41 {
42   return strlen(s) == 2 && s[0] == '-';
43 }
44
45 bool isFile(const char *s)
46 {
47   struct stat st;
48 #ifdef _WIN32
49   return ::stat(s, &st) == 0 && (st.st_mode & (S_IFREG));
50 #else
51   return ::stat(s, &st) == 0 && (st.st_mode & (S_IFREG | S_IFLNK));
52 #endif
53 }
54
55 void usage()
56 {
57   cout << endl;
58   cout << "Usage: tagwriter <fields> <files>" << endl;
59   cout << 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;
68   cout << endl;
69
70   exit(1);
71 }
72
73 int main(int argc, char *argv[])
74 {
75   TagLib::List<TagLib::FileRef> fileList;
76
77   while(argc > 0 && isFile(argv[argc - 1])) {
78
79     TagLib::FileRef f(argv[argc - 1]);
80
81     if(!f.isNull() && f.tag())
82       fileList.append(f);
83
84     argc--;
85   }
86
87   if(fileList.isEmpty())
88     usage();
89
90   for(int i = 1; i < argc - 1; i += 2) {
91
92     if(isArgument(argv[i]) && i + 1 < argc && !isArgument(argv[i + 1])) {
93
94       char field = argv[i][1];
95       TagLib::String value = argv[i + 1];
96
97       TagLib::List<TagLib::FileRef>::Iterator it;
98       for(it = fileList.begin(); it != fileList.end(); ++it) {
99
100         TagLib::Tag *t = (*it).tag();
101
102         switch (field) {
103         case 't':
104           t->setTitle(value);
105           break;
106         case 'a':
107           t->setArtist(value);
108           break;
109         case 'A':
110           t->setAlbum(value);
111           break;
112         case 'c':
113           t->setComment(value);
114           break;
115         case 'g':
116           t->setGenre(value);
117           break;
118         case 'y':
119           t->setYear(value.toInt());
120           break;
121         case 'T':
122           t->setTrack(value.toInt());
123           break;
124         default:
125           usage();
126           break;
127         }
128       }
129     }
130     else
131       usage();
132   }
133
134   TagLib::List<TagLib::FileRef>::Iterator it;
135   for(it = fileList.begin(); it != fileList.end(); ++it)
136     (*it).file()->save();
137
138   return 0;
139 }