taginfo.cc (1185B)
1 #include <iostream> 2 #include <iomanip> 3 4 #include <fileref.h> 5 #include <tag.h> 6 7 // dump tags of audio files 8 // depends: taglib 9 10 using namespace std; 11 12 static int all = 0; 13 14 int 15 main(int argc, char *argv[]) 16 { 17 if (argv[1] != NULL && strcmp(argv[1], "-a") == 0) { 18 all = 1; 19 argv++; 20 argc--; 21 } 22 23 if (argc == 1) { 24 cerr << "usage: taginfo [-a] file ..." << endl; 25 return 1; 26 } 27 28 // detect unicode locale 29 setlocale(LC_ALL, ""); 30 string lc = string(setlocale(LC_CTYPE, NULL)); 31 bool unicode = lc.find("UTF-8") != string::npos; 32 33 for (int i = 1; i < argc; i++) { 34 TagLib::FileRef f(argv[i]); 35 TagLib::Tag *tag = f.tag(); 36 37 if (f.isNull() || !tag) 38 continue; 39 40 string a = tag->artist().toCString(unicode); 41 string t = tag->title().toCString(unicode); 42 string b = tag->album().toCString(unicode); 43 uint y = tag->year(); 44 uint n = tag->track(); 45 string g = tag->genre().toCString(unicode); 46 string c = tag->comment().toCString(unicode); 47 48 cout << a; 49 cout << " - "; 50 cout << b; 51 if (all) { 52 cout << " (" << y << ")"; 53 cout << " [" << g << "]"; 54 cout << " -- " << c; 55 cout << " -- " << setw(2) << n; 56 } 57 cout << " - "; 58 cout << t; 59 cout << endl; 60 } 61 62 return 0; 63 }