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 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
|
# include <getopt.h> // getopt
# include "qmp3.hh"
# include "qexception.hh"
#ifdef NLS
# include <locale.h>
# include <libintl.h>
# define _(s) gettext (s)
#else
# define _(s) (s)
#endif
void usage () {
cerr << ' ' << APPNAME << _(": show info from mp3 files\n");
cerr << _(" syntax: ") << APPNAME << _(" [option]... file...\n");
cerr << _(" -c, --check: check the entire stream (slower but accurate)\n");
cerr << _(" -h, --help: show this help and exit\n");
cerr << _(" -s, --summary-only: show only the summary\n");
cerr << _(" -v, --verbose: verbose\n");
cerr << _(" -V, --version: show version and exit\n");
}
int main (int argc, char **argv) {
int option;
bool verbose=false;
bool summarize=false;
bool check=false;
static struct option long_options[] = {
{"check",no_argument,0,'c'},
{"help",no_argument,0,'h'},
{"summary-only",no_argument,0,'s'},
{"verbose",no_argument,0,'v'},
{"version",no_argument,0,'V'},
{0,0,0,0}
};
#ifdef NLS
setlocale(LC_ALL, "");
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);
#endif
// un altre dia, per defecte llegir *.mp3 ...
if (argc==1) {
usage();
return 1;
}
// supress getopt error message
opterr = 0;
while ((option = getopt_long(argc, argv, "chsvV",long_options,0)) != EOF)
switch (option) {
case 'c':
check=true;
break;
case 'h':
usage();
return 0;
break;
case 's':
summarize=true;
break;
case 'v':
verbose=true;
break;
case 'V':
cerr << APPNAME << " - " << _("version") << ' ' << VERSION
<< _("build") << ' ' << __DATE__ << '\n';
return 0;
break;
case '?':
default:
cerr << APPNAME << ": " << _("option") << " '" << argv[optind-1]
<< "' " << _("is not recognized or bad used") << '\n';
usage();
return 1;
}
if (argc<=optind) {
// haurem de fer *.mp3 ...
cerr << APPNAME << _(": no input file(s)") << endl;
usage();
return 1;
}
u_int32_t files=0, errors=0;
u_int32_t msduration, total_msduration=0;
u_int32_t bytes, frames, total_bytes=0, total_frames=0;
while (argv[optind]) {
files++;
try {
qmp3 p(argv[optind]);
if (!check && p.isVbr()) {
if (verbose)
cerr << p.getName() << _(": vbr detected => automatic check") << endl;
check = true;
}
if (check)
p.scan();
msduration = p.getMsDuration();
total_msduration += msduration;
if (!summarize)
cout << p;
if (verbose) {
bytes = p.getSize();
frames = p.getFrames();
if (!summarize)
cout << " " << bytes << " bytes " << frames << " frames";
total_bytes += bytes;
total_frames += frames;
}
if (!summarize)
cout << endl;
}
catch (qexception e) {
cerr << argv[optind] << ": " << e << endl;
errors++;
}
optind++;
}
cout << files << _(" file") << (files>1?"s":"");
if (errors)
cout << errors << _(" error") << (errors>1?"s":"");
if (verbose) {
cout << " => " << total_msduration/60000 << ":";
cout.width(2);
cout.fill('0');
cout << (total_msduration/1000)%60 << '.';
cout.width(3);
cout.fill('0');
cout << total_msduration%1000 << " " << total_frames << " "
<< total_bytes << " bytes\n";
} else {
cout << " => " << total_msduration/60000 << ':';
cout.width(2);
cout.fill('0');
cout << (total_msduration/1000)%60 << '\n';
}
}
|