File: qmp3join.cc

package info (click to toggle)
quelcom 0.4.0-16
  • links: PTS
  • area: main
  • in suites: bookworm
  • size: 1,544 kB
  • sloc: cpp: 4,148; makefile: 158; sh: 15
file content (143 lines) | stat: -rw-r--r-- 3,206 bytes parent folder | download | duplicates (3)
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
# 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 << _(": join mp3 files\n");
  cerr << _(" syntax: ") << APPNAME << _(" [option]... file1 file2...\n");
  cerr << _("   -f, --force: force join bypassing bit rate checks\n");
  cerr << _("   -h, --help: show this help and exit\n");
  cerr << _("   -o, --output <file>: send output to <file>. otherwise, append to <file1>\n");
  cerr << _("   -v, --verbose: verbose\n");
  cerr << _("   -V, --version: show version and exit\n");
}
     

int main (int argc, char **argv) {

  bool verbose=false, force=false;
  string outfile;

  static struct option long_options[] = {
    {"force",no_argument,0,'f'},
    {"help",no_argument,0,'h'},
    {"output",required_argument,0,'o'},
    {"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

  if (argc==1) {
    usage();
    return 1;
  }

  int option;

 // supress getopt error message
  opterr = 0;	

  while ((option = getopt_long(argc, argv, "fho:vV",long_options,0)) != EOF) 
    switch (option) {
      case 'f':
        force = true;
      break;
      case 'h':
        usage();
        return 0;
      break;
      case 'o': 
        outfile=optarg; 
      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<2) {
    cerr << APPNAME << _(": at least two files to join must be specified\n");
    usage();
    return 1;
  }

  argv += optind;

  qmp3 *mp3;

  try {

   // resolve which is the first file
    if (outfile!="") {
      mp3 = new qmp3(*argv);
      if (verbose)
        cerr << _(" copying '") << *argv << _("' to '") << outfile << "'...";
      mp3->dup(outfile);
      if (verbose)
        cerr << "ok." << endl;
      delete mp3;
      mp3 = new qmp3 (outfile,qmp3::READWRITE);
    }
    else
      mp3 = new qmp3(*argv,qmp3::READWRITE);

    if (verbose)
      cerr << _("scanning '") << mp3->getName() << "'...";

    mp3->scan();
    if (verbose)
      cerr << "ok." << endl;

   // append the rest of the files
    while (*++argv) {
      qmp3 mm(*argv);
 
      if (verbose)
        cerr << _("scanning '") << mm.getName() << "'...";
      mm.scan();
      if (verbose)
        cerr << "ok." << endl;

      if (verbose)
        cerr << _("appending '") << mm.getName() << _("' to '")
	     << mp3->getName() << "'...";
      mp3->append(mm,force);
      if (verbose)
        cerr << "ok." << endl;
    }
  }
  catch (qexception e) {
    cerr << *argv << ": " << e << endl;
    return 1;
  }

  if (verbose)
    cerr << *mp3 << endl;

  delete mp3;
  return 0;
}