1 // ampc_tagger.el --- Asynchronous Music Player Controller Tagger
3 // Copyright (C) 2012 Free Software Foundation, Inc.
5 // Author: Christopher Schmidt <christopher@ch.ristopher.com>
6 // Maintainer: Christopher Schmidt <christopher@ch.ristopher.com>
9 // This file is part of ampc.
11 // This program is free software; you can redistribute it and/or modify
12 // it under the terms of the GNU General Public License as published by
13 // the Free Software Foundation, either version 3 of the License, or
14 // (at your option) any later version.
16 // This program is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 // GNU General Public License for more details.
21 // You should have received a copy of the GNU General Public License
22 // along with this program. If not, see <http://www.gnu.org/licenses/>.
27 #include <taglib/fileref.h>
28 #include <taglib/tag.h>
29 #include <taglib/id3v1genres.h>
31 std::wstring
const version
=L
"0.1";
32 std::locale original_wcout_locale
;
34 bool get(std::string
const& file
)
36 using namespace TagLib
;
38 FileRef
file_ref(file
.c_str());
40 if(file_ref
.isNull() || !(tag
=file_ref
.tag()))
42 std::wcerr
<< L
"ERROR: Failed opening file." << std::endl
;
46 std::wcout
<< L
"Title: " << tag
->title().toWString() << std::endl
<<
47 L
"Artist: " << tag
->artist().toWString() << std::endl
<<
48 L
"Album: " << tag
->album().toWString() << std::endl
<<
49 L
"Comment: " << tag
->comment().toWString() << std::endl
<<
50 L
"Genre: " << tag
->genre().toWString() << std::endl
;
53 std::wcout
<< L
"Year: ";
54 std::locale new_locale
=std::wcout
.imbue(original_wcout_locale
);
55 std::wcout
<< tag
->year();
56 std::wcout
.imbue(new_locale
);
57 std::wcout
<< std::endl
;
61 std::wcout
<< L
"Track: ";
62 std::locale new_locale
=std::wcout
.imbue(original_wcout_locale
);
63 std::wcout
<< tag
->track();
64 std::wcout
.imbue(new_locale
);
65 std::wcout
<< std::endl
;
71 bool set(std::string
const& file
)
73 using namespace TagLib
;
75 FileRef
file_ref(file
.c_str());
77 if(file_ref
.isNull() || !(tag
=file_ref
.tag()))
79 std::wcerr
<< L
"ERROR: Failed opening file." << std::endl
;
87 std::wcerr
<< L
"ERROR: invalid input data." << std::endl
;
91 std::wstring tag_to_set
;
92 getline(std::wcin
, tag_to_set
);
99 getline(std::wcin
, value
);
101 std::wcout
<< L
"Setting " << tag_to_set
<<
102 L
" to " << value
<< std::endl
;
104 if(tag_to_set
== L
"Title")
106 tag
->setTitle(value
);
108 else if(tag_to_set
== L
"Artist")
110 tag
->setArtist(value
);
112 else if(tag_to_set
== L
"Album")
114 tag
->setAlbum(value
);
116 else if(tag_to_set
== L
"Comment")
118 tag
->setComment(value
);
120 else if(tag_to_set
== L
"Genre")
122 tag
->setGenre(value
);
124 else if(tag_to_set
== L
"Year")
133 std::wistringstream
val(value
);
138 else if(tag_to_set
== L
"Track")
147 std::wistringstream
val(value
);
154 std::wcerr
<< L
"Unknown tag " << tag_to_set
<< std::endl
;
161 std::wcerr
<< L
"Failed saving file." << std::endl
;
168 int main(int const argc
, char**const argv
)
171 original_wcout_locale
=std::wcout
.imbue(loc
);
172 std::wcin
.imbue(loc
);
173 std::locale::global(loc
);
181 if(action
== "--version")
183 std::wcout
<< version
<< std::endl
;
186 else if(action
== "--genres")
188 using namespace TagLib
;
189 StringList genres
=ID3v1::genreList();
190 for(StringList::ConstIterator genre
=genres
.begin();
194 std::wcout
<< genre
->toWString() << std::endl
;
198 else if(action
== "--get" && argc
== 3)
200 return get(argv
[2]) ? 1 : 0;
202 else if(action
== "--set" && argc
== 3)
204 return set(argv
[2]) ? 1 : 0;
209 L
"Usage: ampc_tagger [--version|--genres|--set file|--get file]" <<
217 // indent-tabs-mode: nil