blob: aa4055f6f23e886f6ccfd7ba0674d5a8d99f7ebc (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
/* Copyright (C) 2008 Jason A. Donenfeld <Jason@zx2c4.com> */
/* Use at your own risk. */
#include <iostream>
#include <mpegfile.h>
#include <tstring.h>
#include <tag.h>
#include <id3v2tag.h>
#include <textidentificationframe.h>
using namespace TagLib;
using namespace std;
int main(int argc, char *argv[])
{
for(int i = 1; i < argc; i++) {
MPEG::File *file = new MPEG::File(argv[i]);
if(argc > 2)
cout << "--File " << i << " of " << argc - 1 << "--" << endl;
if(!file->isValid()) {
cout << "[!] Could not open " << argv[i] << "." << endl;
continue;
}
Tag *tag = file->tag();
if(tag->isEmpty()) {
cout << "[!] No tags in " << argv[i] << "." << endl;
continue;
}
cout << "[*] Reading " << argv[i] << ":" << endl;
String artist = tag->artist().stripWhiteSpace();
String album = tag->album().stripWhiteSpace();
String title = tag->title().stripWhiteSpace();
TagLib::uint track = tag->track();
TagLib::uint year = tag->year();
String genre = tag->genre().stripWhiteSpace();
// COMMENTS ARE NOT SAVED. I HATE ID3 COMMENTS, SO THEY'RE STRIPPED OUT
String disc;
String bpm;
String composer;
String albumArtist;
String compilation;
if(file->ID3v2Tag()) {
if(!file->ID3v2Tag()->frameListMap()["TPOS"].isEmpty())
disc = file->ID3v2Tag()->frameListMap()["TPOS"].front()->toString().stripWhiteSpace();
if(!file->ID3v2Tag()->frameListMap()["TBPM"].isEmpty())
bpm = file->ID3v2Tag()->frameListMap()["TBPM"].front()->toString().stripWhiteSpace();
if(!file->ID3v2Tag()->frameListMap()["TCOM"].isEmpty())
composer = file->ID3v2Tag()->frameListMap()["TCOM"].front()->toString().stripWhiteSpace();
if(!file->ID3v2Tag()->frameListMap()["TPE2"].isEmpty())
albumArtist = file->ID3v2Tag()->frameListMap()["TPE2"].front()->toString().stripWhiteSpace();
if(!file->ID3v2Tag()->frameListMap()["TCMP"].isEmpty())
compilation = file->ID3v2Tag()->frameListMap()["TCMP"].front()->toString().stripWhiteSpace();
}
cout
<< "\tArtist: " << artist << endl
<< "\tComposer: " << composer << endl
<< "\tAlbum: " << album << endl
<< "\tAlbum Artist: " << albumArtist << endl
<< "\tTitle: " << title << endl
<< "\tTrack: " << track << endl
<< "\tDisc: " << disc << endl
<< "\tCompilation: " << compilation << endl
<< "\tYear: " << year << endl
<< "\tGenre: " << genre << endl;
cout << "[*] Stripping tags and saving." << endl;
file->strip(MPEG::File::AllTags);
file->save();
delete file;
cout << "[*] Re-opening and re-writing new tags." << endl;
file = new MPEG::File(argv[i]);
tag = file->tag();
tag->setArtist(artist);
tag->setAlbum(album);
tag->setTitle(title);
tag->setTrack(track);
tag->setYear(year);
tag->setGenre(genre);
::ID3v2::TextIdentificationFrame *frame;
if(!disc.isEmpty()) {
frame = new ::ID3v2::TextIdentificationFrame("TPOS", ::ID3v2::FrameFactory::instance()->defaultTextEncoding());
frame->setText(disc);
file->ID3v2Tag()->addFrame(frame);
}
if(!bpm.isEmpty()) {
frame = new ::ID3v2::TextIdentificationFrame("TBPM", ::ID3v2::FrameFactory::instance()->defaultTextEncoding());
frame->setText(bpm);
file->ID3v2Tag()->addFrame(frame);
}
if(!composer.isEmpty()) {
frame = new ::ID3v2::TextIdentificationFrame("TCOM", ::ID3v2::FrameFactory::instance()->defaultTextEncoding());
frame->setText(composer);
file->ID3v2Tag()->addFrame(frame);
}
if(!albumArtist.isEmpty()) {
frame = new ::ID3v2::TextIdentificationFrame("TPE2", ::ID3v2::FrameFactory::instance()->defaultTextEncoding());
frame->setText(albumArtist);
file->ID3v2Tag()->addFrame(frame);
}
if(!compilation.isEmpty()) {
frame = new ::ID3v2::TextIdentificationFrame("TCMP", ::ID3v2::FrameFactory::instance()->defaultTextEncoding());
frame->setText(compilation);
file->ID3v2Tag()->addFrame(frame);
}
cout << "[*] Saving file." << endl;
file->save();
delete file;
cout << "[*] Success." << endl;
}
}
|