Skip to content

Commit 43a55de

Browse files
committed
Closer to tagging with all the tags..
1 parent c089170 commit 43a55de

File tree

5 files changed

+69
-54
lines changed

5 files changed

+69
-54
lines changed

Makefile

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ CFLAGS=-Wall -Wextra -fPIC \
44
-I ..//libjson/include
55

66
LDFLAGS=-L /usr/lib64 -l tag \
7-
-L ../libjson/src -l json -Wl,-rpath=../libjson/src
7+
-L /home/taitken/cpp/libjson/src -l json -Wl,-rpath=/home/taitken/cpp/libjson/src
88

99
DEBUG=-g
1010

@@ -27,8 +27,6 @@ clean-aif:
2727

2828
clean-json:
2929
cp test/clean/clean.json test/test.json
30-
cp test/clean/code_tags.json test/code_tags.json
3130

3231
test: clean all
3332
./bin/tagger --file test/test.aif --tags test/test.json
34-
./bin/tagger --file test/test.aif --tags test/code_tags.json

README

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
11

22
C++ Id3 Tag utility to write id3 tags to an audio file.
3-
The tags can be read from a json file.
3+
The tags can be read from a json file.
4+
5+
This requires both taglib and jsonlib.
6+
7+
TagLib: http://developer.kde.org/~wheeler/taglib.html
8+
jsonlib: https://github.com/thanatos/libjson
9+
10+
Thanks to both those projects to make this one possible.

main.cpp

Lines changed: 43 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ using namespace std;
66
/* TagLib */
77
#include <aifffile.h>
88
#include <id3v2header.h>
9+
#include <id3v2tag.h>
10+
#include <id3v2frame.h>
11+
#include <textidentificationframe.h>
912
#include <tag.h>
1013
#include <fileref.h>
1114
#include <tbytevector.h>
@@ -84,41 +87,66 @@ int main(int argc, char **argv)
8487
if (i.key() == "tags") {
8588
json::Object tags_obj = dynamic_cast<const json::Object &>(i.value());
8689
for (json::Object::const_iterator j = tags_obj.begin(); j != tags_obj.end(); ++j) {
90+
string tag_name = j.key();
8791
if (j->type() == json::TYPE_STRING) {
8892
string tag_value = dynamic_cast<const json::String &>(*j).value();
89-
cout << j.key() << endl;
90-
if (j.key() == "COM") {
91-
f.tag()->setAlbum(tag_value);
93+
cout << tag_name << endl;
94+
if (tag_name == "COMM") {
95+
f.tag()->setComment(tag_value);
9296
cout << "Setting Comment(COM): " << tag_value << endl;
9397
}
94-
if (j.key() == "GENRE") {
95-
f.tag()->setAlbum(tag_value);
98+
if (tag_name == "GENR") {
99+
f.tag()->setGenre(tag_value);
96100
cout << "Setting GENRE: " << tag_value << endl;
97101
}
98-
if (j.key() == "TALB") {
102+
if (tag_name == "TALB") {
99103
f.tag()->setAlbum(tag_value);
100104
cout << "Setting Album(TALB): " << tag_value << endl;
101105
}
102-
if (j.key() == "TPE1") {
106+
if (tag_name == "TPE1") {
103107
f.tag()->setArtist(tag_value);
104108
cout << "Setting Artist(TPE1): " << tag_value << endl;
105109
}
110+
if (tag_name == "TPE4") {
111+
TagLib::ID3v2::Tag* id3v2Tag;
112+
TagLib::ByteVector remixer;
113+
remixer.setData(tag_name.c_str());
114+
cout << remixer << endl;
115+
TagLib::ID3v2::TextIdentificationFrame frame(remixer, TagLib::String::Latin1);
116+
id3v2Tag->addFrame(&frame);
117+
cout << "Setting Artist(TPE1): " << tag_value << endl;
118+
}
119+
if (tag_name == "TIT2") {
120+
f.tag()->setTitle(tag_value);
121+
cout << "Setting TITLE(TIT2): " << tag_value << endl;
122+
}
123+
if (tag_name == "TPUB") {
124+
cout << "Setting Publisher(TPUB): " << tag_value << endl;
125+
}
126+
if (tag_name == "TKEY") {
127+
cout << "Setting Key(TKEY): " << tag_value << endl;
128+
}
129+
if (tag_name == "TFLT") {
130+
cout << "Setting Filetype(TFLT): " << tag_value << endl;
131+
}
132+
if (tag_name == "TCON") {
133+
cout << "Setting Content TYpe(TCON): " << tag_value << endl;
134+
}
106135
}
107136
if (j->type() == json::TYPE_INTEGER) {
108137
int tag_value = dynamic_cast<const json::Integer &>(*j).value;
109-
cout << j.key() << endl;
110-
if (j.key() == "ryear") {
111-
f.tag()->setYear(tag_value);
112-
cout << "Setting year: " << tag_value << endl;
138+
cout << tag_name << endl;
139+
if (tag_name == "TDOR") {
140+
cout << "Setting release year(TDOR): " << tag_value << endl;
113141
}
114-
if (j.key() == "year") {
142+
if (tag_name == "TDRC") {
115143
f.tag()->setYear(tag_value);
116-
cout << "Setting year: " << tag_value << endl;
144+
cout << "Setting year(TDRC): " << tag_value << endl;
117145
}
118-
if (j.key() == "TBPM") {
146+
if (tag_name == "TBPM") {
119147
cout << "Setting bpm(TBPM): " << tag_value << endl;
120148
}
121-
if (j.key() == "TRCK") {
149+
if (tag_name == "TRCK") {
122150
f.tag()->setTrack(tag_value);
123151
cout << "Setting track (TRCK): " << tag_value << endl;
124152
}

test/clean/clean.json

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
{
22
"tags": {
3-
"artist": "Artist from Json",
4-
"name": "Track Name",
5-
"artist": "Artist",
6-
"remixer": "Remixer",
7-
"album": "Album from JSON",
8-
"label": "Label",
9-
"relaseyear": 2010,
10-
"year": 2011,
11-
"set": true,
12-
"track": 1,
13-
"isrc": "abcdefhigklmno",
14-
"ctype": "Content Type",
15-
"ftype": "File Type",
16-
"genre": "Genre",
17-
"bpm": 123,
18-
"key": "AM"
3+
"TPE1": "Artist from Json",
4+
"TIT2": "Track Name (Remix)",
5+
"TPE1": "Artist",
6+
"TPE4": "Remixer",
7+
"TALB": "Album from JSON",
8+
"TPUB": "Label",
9+
"TDOR": 2010,
10+
"TDRC": 2011,
11+
"TPOS": 1,
12+
"TRCK": 1,
13+
"TSRC": "abcdefhigklmno",
14+
"TCON": "Content Type",
15+
"TFLT": "File Type",
16+
"TBPM": 123,
17+
"TKEY": "F#",
18+
"GENR": "Genre",
19+
"COMM": "Some comment"
1920
}
2021
}

test/clean/code_tags.json

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)