1 | #!/usr/bin/perl -w
|
---|
2 | #
|
---|
3 | # Reads CDDB info, allow modifications and send back to CDDB server
|
---|
4 | #
|
---|
5 | # $Id$
|
---|
6 | #
|
---|
7 | # Copyright B. Cornec 2009
|
---|
8 | # Provided under the GPL v2
|
---|
9 |
|
---|
10 | # Syntax: see at end
|
---|
11 |
|
---|
12 | use strict 'vars';
|
---|
13 | use Getopt::Long qw(:config auto_abbrev no_ignore_case);
|
---|
14 | use Data::Dumper;
|
---|
15 | use English;
|
---|
16 | use ProjectBuilder::Base;
|
---|
17 | use ProjectBuilder::Conf;
|
---|
18 | use Mail::Sendmail;
|
---|
19 | use POSIX qw(strftime :sys_wait_h);
|
---|
20 | use Newt qw(NEWT_FLAG_WRAP NEWT_ENTRY_SCROLL NEWT_ANCHOR_LEFT NEWT_ANCHOR_RIGHT :entry :textbox :macros);
|
---|
21 | use lib qw (lib);
|
---|
22 | use locale;
|
---|
23 | # >= 2.27
|
---|
24 | use CDDB_get qw( get_cddb get_discids );
|
---|
25 | use Encode;
|
---|
26 | #use Linux::CDROM;
|
---|
27 | use Device::Cdio::Device;
|
---|
28 | use Device::Cdio::Track;
|
---|
29 | use File::Copy;
|
---|
30 | use File::Basename;
|
---|
31 |
|
---|
32 | # Global variables
|
---|
33 | my %opts; # CLI Options
|
---|
34 | my $action; # action to realize
|
---|
35 |
|
---|
36 | my @date = pb_get_date();
|
---|
37 | my $pbdate = strftime("%Y-%m-%d", @date);
|
---|
38 |
|
---|
39 | pb_temp_init();
|
---|
40 |
|
---|
41 | =pod
|
---|
42 |
|
---|
43 | =head1 NAME
|
---|
44 |
|
---|
45 | CDDBeditor, read, modidy and send your CDDB contrinutions
|
---|
46 |
|
---|
47 | =head1 DESCRIPTION
|
---|
48 |
|
---|
49 | CDDBeditor helps you read, modidy and send your CDDB contrinutions.
|
---|
50 |
|
---|
51 | =head1 SYNOPSIS
|
---|
52 |
|
---|
53 | CDDBeditor [-vhmq][-t|-g]
|
---|
54 |
|
---|
55 | CDDBeditor [--verbose][--help][--man][--quiet][--text|--graphic]
|
---|
56 |
|
---|
57 | =head1 OPTIONS
|
---|
58 |
|
---|
59 | =over 4
|
---|
60 |
|
---|
61 | =item B<-v|--verbose>
|
---|
62 |
|
---|
63 | Print a brief help message and exits.
|
---|
64 |
|
---|
65 | =item B<-q|--quiet>
|
---|
66 |
|
---|
67 | Do not print any output.
|
---|
68 |
|
---|
69 | =item B<-h|--help>
|
---|
70 |
|
---|
71 | Print a brief help message and exits.
|
---|
72 |
|
---|
73 | =item B<--man>
|
---|
74 |
|
---|
75 | Prints the manual page and exits.
|
---|
76 |
|
---|
77 | =item B<-t|--text>
|
---|
78 | =item B<-g|--graphic>
|
---|
79 |
|
---|
80 | Interface is either text mode or graphical mode (newt based)
|
---|
81 |
|
---|
82 | =back
|
---|
83 |
|
---|
84 | =head1 ARGUMENTS
|
---|
85 |
|
---|
86 | =head1 WEB SITES
|
---|
87 |
|
---|
88 | The main Web site of the project is available at L<http://www.project-builder.org/>. Bug reports should be filled using the trac instance of the project at L<http://trac.project-builder.org/>.
|
---|
89 |
|
---|
90 | =head1 USER MAILING LIST
|
---|
91 |
|
---|
92 | None exists for the moment.
|
---|
93 |
|
---|
94 | =head1 CONFIGURATION FILES
|
---|
95 |
|
---|
96 | =head1 AUTHORS
|
---|
97 |
|
---|
98 | The CDDBeditor team L<http://trac.project-builder.org/> lead by Bruno Cornec L<mailto:bruno@project-builder.org>.
|
---|
99 |
|
---|
100 | =head1 COPYRIGHT
|
---|
101 |
|
---|
102 | CDDBeditor is distributed under the GPL v2.0 license
|
---|
103 | described in the file C<COPYING> included with the distribution.
|
---|
104 |
|
---|
105 | =cut
|
---|
106 |
|
---|
107 | # ---------------------------------------------------------------------------
|
---|
108 |
|
---|
109 | #Avoids an error from Newt
|
---|
110 | no AutoLoader;
|
---|
111 |
|
---|
112 |
|
---|
113 | # Initialize the syntax string
|
---|
114 |
|
---|
115 | my $projver = "PBVER";
|
---|
116 | my $projrev = "PBREV";
|
---|
117 |
|
---|
118 | pb_syntax_init("CDDBeditor Version $projver-$projrev\n");
|
---|
119 |
|
---|
120 | GetOptions("help|?|h" => \$opts{'h'},
|
---|
121 | "man" => \$opts{'man'},
|
---|
122 | "verbose|v+" => \$opts{'v'},
|
---|
123 | "quiet|q" => \$opts{'q'},
|
---|
124 | "text|t" => \$opts{'t'},
|
---|
125 | "graphic|g" => \$opts{'g'},
|
---|
126 | "version|V=s" => \$opts{'V'},
|
---|
127 | ) || pb_syntax(-1,0);
|
---|
128 |
|
---|
129 | if (defined $opts{'h'}) {
|
---|
130 | pb_syntax(0,1);
|
---|
131 | }
|
---|
132 | if (defined $opts{'man'}) {
|
---|
133 | pb_syntax(0,2);
|
---|
134 | }
|
---|
135 | $pbdebug = 0;
|
---|
136 | if (defined $opts{'v'}) {
|
---|
137 | $pbdebug = $opts{'v'};
|
---|
138 | }
|
---|
139 | if (defined $opts{'q'}) {
|
---|
140 | $pbdebug=-1;
|
---|
141 | }
|
---|
142 | open(LOG, "> $ENV{HOME}/.CDDBeditor.log") || die "Unable to open $ENV{HOME}/.CDDBeditor.log";
|
---|
143 | pb_log_init($pbdebug, \*LOG);
|
---|
144 |
|
---|
145 | Newt::Init();
|
---|
146 |
|
---|
147 | # String definitions
|
---|
148 | my $ce_title = "CDDBeditor";
|
---|
149 | my $ce_help = "(c) Bruno Cornec 2009 - All right reversed under the GPL v2";
|
---|
150 | my $artist_label = Newt::Label("Artist: ");
|
---|
151 | my $empty_label = Newt::Label(" ");
|
---|
152 | my $title_label = Newt::Label("Title: ");
|
---|
153 | my $year_label = Newt::Label("Year: ");
|
---|
154 | my $id_label = "Id: ";
|
---|
155 | my $rev_label = "Revision: ";
|
---|
156 | my $genre_label = Newt::Label("Genre: ");
|
---|
157 | my $category_label = Newt::Label("Category: ");
|
---|
158 | my $info_label = Newt::Label("Info: ");
|
---|
159 | my $tr_track_label = Newt::Label("Track");
|
---|
160 | my $tr_frames_label = Newt::Label("Frames");
|
---|
161 | my $tno_label = Newt::Label("Track #: ");
|
---|
162 | my $tr_title_label = Newt::Label("Title");
|
---|
163 | my $tr_author_label = Newt::Label("Author");
|
---|
164 | my $tr_length_label = Newt::Label("Length");
|
---|
165 |
|
---|
166 | my $host_label = Newt::Label("Host: ");
|
---|
167 | my $port_label = Newt::Label("Port: ");
|
---|
168 | my $mode_label = Newt::Label("Mode: ");
|
---|
169 | my $dev_label = Newt::Label("Device: ");
|
---|
170 | my $proxy_label = Newt::Label("Proxy: ");
|
---|
171 |
|
---|
172 | my $wait_label = Newt::Label("Please wait while searching ...");
|
---|
173 |
|
---|
174 | # To be put in conf file
|
---|
175 | my %ce_config;
|
---|
176 | $ce_config{"CDDB_HOST"}="freedb.freedb.org";
|
---|
177 | $ce_config{"CDDB_USER"}="freedb-submit\@freedb.org";
|
---|
178 | $ce_config{"CDDB_CC"}="bruno\@victoria.frmug.org";
|
---|
179 | $ce_config{"CDDB_PORT"}=888;
|
---|
180 | #$ce_config{"CDDB_PORT"}=80;
|
---|
181 | my %ce_cddb_mode;
|
---|
182 | $ce_cddb_mode{"0"} = "cddb";
|
---|
183 | $ce_cddb_mode{"1"} = "http";
|
---|
184 |
|
---|
185 | $ce_config{"CDDB_MODE"}=$ce_cddb_mode{"0"};
|
---|
186 | $ce_config{"CD_DEVICE"}="/dev/sr1";
|
---|
187 | $ce_config{"HTTP_PROXY"}=$ENV{http_proxy} if $ENV{http_proxy};
|
---|
188 | $ce_config{"input"}=0;
|
---|
189 | $ce_config{"multi"}=1;
|
---|
190 | $ce_config{"PROTO_VERSION"} = 6;
|
---|
191 | $ce_config{"DOMAIN"} = "musique-ancienne.org";
|
---|
192 | $ce_config{"USER"} = "bruno";
|
---|
193 | # Requires 4 words exactly
|
---|
194 | $ce_config{"HELLO_ID"} = "$ce_config{\"USER\"} $ce_config{\"DOMAIN\"} CDDBEditor 0.5";
|
---|
195 |
|
---|
196 | # Copied from CDDB.pm
|
---|
197 | # Determine whether we can submit changes by e-mail.
|
---|
198 |
|
---|
199 | my ($ce_sl, $ce_sh) = Newt::GetScreenSize();
|
---|
200 |
|
---|
201 | # First panel for configuration parameters
|
---|
202 | Newt::Cls();
|
---|
203 | Newt::DrawRootText(ce_center_string($ce_title), 1, $ce_title);
|
---|
204 | Newt::PushHelpLine($ce_help);
|
---|
205 | Newt::Refresh();
|
---|
206 |
|
---|
207 | my $flag = NEWT_ENTRY_SCROLL;
|
---|
208 | # Need 23 char for track and time
|
---|
209 | my $width = $ce_sl - 23;
|
---|
210 | # Other fields are limited to 5
|
---|
211 | my $width2 = 5;
|
---|
212 | my $host_entry = Newt::Entry($width, $flag, $ce_config{"CDDB_HOST"});
|
---|
213 | my $port_entry = Newt::Entry($width2, $flag, $ce_config{"CDDB_PORT"});
|
---|
214 | my $mode_group;
|
---|
215 | my $proxy_entry = undef;
|
---|
216 | if ($ce_config{"CDDB_MODE"} eq $ce_cddb_mode{"0"}) {
|
---|
217 | $mode_group = Newt::HRadiogroup($ce_cddb_mode{"0"}, $ce_cddb_mode{"1"});
|
---|
218 | } else {
|
---|
219 | $mode_group = Newt::HRadiogroup($ce_cddb_mode{"1"}, $ce_cddb_mode{"0"});
|
---|
220 | }
|
---|
221 | if ($ce_config{"CDDB_MODE"} eq "http" ) {
|
---|
222 | $proxy_entry = Newt::Entry($width, $flag, $ce_config{"HTTP_PROXY"});
|
---|
223 | }
|
---|
224 | my $dev_entry = Newt::Entry($width, $flag, $ce_config{"CD_DEVICE"});
|
---|
225 | my $user_group;
|
---|
226 | my $next_button = Newt::Button("Next");
|
---|
227 | $next_button->Tag("Next");
|
---|
228 | my $quit_button = Newt::Button("Quit");
|
---|
229 | $quit_button->Tag("Quit");
|
---|
230 |
|
---|
231 | my $ce_panel = Newt::Panel(2, 20, "CDDBeditor Configuration");
|
---|
232 | my $flage = NEWT_ANCHOR_RIGHT;
|
---|
233 | $ce_panel->Add(0, 0, $host_label, $flage);
|
---|
234 | $flage = NEWT_ANCHOR_LEFT;
|
---|
235 | $ce_panel->Add(1, 0, $host_entry, $flage);
|
---|
236 | $flage = NEWT_ANCHOR_RIGHT;
|
---|
237 | $ce_panel->Add(0, 1, $port_label, $flage);
|
---|
238 | $flage = NEWT_ANCHOR_LEFT;
|
---|
239 | $ce_panel->Add(1, 1, $port_entry, $flage);
|
---|
240 | $flage = NEWT_ANCHOR_RIGHT;
|
---|
241 | $ce_panel->Add(0, 2, $mode_label, $flage);
|
---|
242 | $flage = NEWT_ANCHOR_LEFT;
|
---|
243 | $ce_panel->Add(1, 2, $mode_group, $flage);
|
---|
244 | if ($ce_config{"CDDB_MODE"} eq "http" ) {
|
---|
245 | $flage = NEWT_ANCHOR_RIGHT;
|
---|
246 | $ce_panel->Add(0, 3, $proxy_label, $flage);
|
---|
247 | $flage = NEWT_ANCHOR_LEFT;
|
---|
248 | $ce_panel->Add(1, 3, $proxy_entry, $flage);
|
---|
249 | }
|
---|
250 | $flage = NEWT_ANCHOR_RIGHT;
|
---|
251 | $ce_panel->Add(0, 4, $dev_label, $flage);
|
---|
252 | $flage = NEWT_ANCHOR_LEFT;
|
---|
253 | $ce_panel->Add(1, 4, $dev_entry, $flage);
|
---|
254 | $flage = NEWT_ANCHOR_LEFT;
|
---|
255 | $ce_panel->Add(0, 6, $empty_label);
|
---|
256 | $ce_panel->Add(0, 7, $next_button);
|
---|
257 | $ce_panel->Add(1, 7, $quit_button);
|
---|
258 |
|
---|
259 | Newt::Refresh();
|
---|
260 | my ($reason, $data) = $ce_panel->Run();
|
---|
261 |
|
---|
262 | Newt::Cls();
|
---|
263 | cddbe_exit(0) if ($data->Tag() eq "Quit");
|
---|
264 |
|
---|
265 | if ($ce_config{"CDDB_MODE"} eq "http" ) {
|
---|
266 | $ce_config{"HTTP_PROXY"}=$proxy_entry->Get();
|
---|
267 | }
|
---|
268 | $ce_config{"CDDB_HOST"}=$host_entry->Get();
|
---|
269 | $ce_config{"CDDB_PORT"}=$port_entry->Get();
|
---|
270 | $ce_config{"CDDB_MODE"}=$ce_cddb_mode{$mode_group->Get()};
|
---|
271 | $ce_config{"CD_DEVICE"}=$dev_entry->Get();
|
---|
272 |
|
---|
273 | pb_log(1,"After first screen\n");
|
---|
274 | pb_log(1,"ce_config is:\n");
|
---|
275 | pb_log(1,Dumper(%ce_config)."\n");
|
---|
276 |
|
---|
277 | # Components
|
---|
278 | my $reload_button = Newt::Button("Reload");
|
---|
279 | $reload_button->Tag("Reload");
|
---|
280 | my $send_button = Newt::Button("Send");
|
---|
281 | $send_button->Tag("Send");
|
---|
282 |
|
---|
283 | my $firsttime = 1;
|
---|
284 | my @cecd;
|
---|
285 | my $ce_cd;
|
---|
286 | my $artist_entry;
|
---|
287 | my $title_entry;
|
---|
288 | my $category_entry;
|
---|
289 | my $genre_entry;
|
---|
290 | my $tno_entry;
|
---|
291 | my $year_entry;
|
---|
292 | my @track_entry;
|
---|
293 |
|
---|
294 | # Entering the loop
|
---|
295 | for (my $i=0 ; ; $i++) { # Second panel to make user wait
|
---|
296 | Newt::Cls();
|
---|
297 | Newt::DrawRootText(ce_center_string($ce_title), 1, $ce_title);
|
---|
298 | Newt::PushHelpLine($ce_help);
|
---|
299 | $ce_panel = Newt::Panel(3, 20, "CDDB Search");
|
---|
300 | $ce_panel->Add(0, 0, $wait_label);
|
---|
301 |
|
---|
302 | ($reason, $data) = $ce_panel->Draw();
|
---|
303 | Newt::Refresh();
|
---|
304 |
|
---|
305 | # CDDB query if first time
|
---|
306 | if ($firsttime == 1) {
|
---|
307 | @cecd = get_cddb(\%ce_config);
|
---|
308 | # by default use first one
|
---|
309 | $ce_cd = $cecd[0] if (defined $cecd[0]);
|
---|
310 | pb_log(1,"After get_cddb\n");
|
---|
311 | pb_log(1,"cecd is:\n");
|
---|
312 | pb_log(1,Dumper(@cecd)."\n");
|
---|
313 | }
|
---|
314 | $firsttime = 0;
|
---|
315 |
|
---|
316 | my @vradio;
|
---|
317 | my $ind = 0;
|
---|
318 | foreach my $entry (@cecd) {
|
---|
319 | my $cat = "";
|
---|
320 | my $tno = "";
|
---|
321 | my $title = "";
|
---|
322 | $cat = $entry->{cat} if (defined $entry->{cat});
|
---|
323 | $tno = $entry->{tno} if (defined $entry->{tno});
|
---|
324 | $title = $entry->{title} if (defined $entry->{title});
|
---|
325 | my $chain = undef;
|
---|
326 | $chain = sprintf("%02d (%s - %d tracks) - %s",$ind,$cat,$tno,$title) if ((defined $cat) && (defined $tno) && (defined $title));
|
---|
327 | push @vradio,$chain if (defined $chain);
|
---|
328 | $ind++;
|
---|
329 | }
|
---|
330 | pb_log(1,"ind is: $ind\n");
|
---|
331 |
|
---|
332 | if ($ind gt 1) {
|
---|
333 | # We have multiple entries chose the right one
|
---|
334 | # Second panel for configuration parameters
|
---|
335 | Newt::Cls();
|
---|
336 | Newt::DrawRootText(ce_center_string($ce_title), 1, $ce_title);
|
---|
337 | Newt::PushHelpLine($ce_help);
|
---|
338 | Newt::Refresh();
|
---|
339 |
|
---|
340 | my $user_group = Newt::VRadiogroup(@vradio);
|
---|
341 | my $quit_button = Newt::Button("Quit");
|
---|
342 | $quit_button->Tag("Quit");
|
---|
343 | my $next_button = Newt::Button("Next");
|
---|
344 | $next_button->Tag("Next");
|
---|
345 |
|
---|
346 | my $ce_panel = Newt::Panel(2, 20, "CD chooser");
|
---|
347 | $flage = NEWT_ANCHOR_LEFT;
|
---|
348 | $ce_panel->Add(0, 5, $user_group, $flage);
|
---|
349 | $ce_panel->Add(0, 10, $empty_label);
|
---|
350 | $ce_panel->Add(0, 11, $next_button);
|
---|
351 | $ce_panel->Add(1, 11, $quit_button);
|
---|
352 |
|
---|
353 | Newt::Refresh();
|
---|
354 | my ($reason, $data) = $ce_panel->Run();
|
---|
355 |
|
---|
356 | Newt::Cls();
|
---|
357 | cddbe_exit(0) if ($data->Tag() eq "Quit");
|
---|
358 |
|
---|
359 | $ind=$user_group->Get();
|
---|
360 | } else {
|
---|
361 | # if only one CD, back to its number which is 0
|
---|
362 | $ind--;
|
---|
363 | }
|
---|
364 | # Point now to the right CD
|
---|
365 | $ce_cd = $cecd[$ind];
|
---|
366 | pb_log(1,"After CD choice\n");
|
---|
367 | pb_log(1,"ce_cd is: \n");
|
---|
368 | pb_log(1,Dumper($ce_cd)."\n");
|
---|
369 |
|
---|
370 | if (not defined $ce_cd->{title}) {
|
---|
371 | # Get the disc id first
|
---|
372 | my $id = get_discids($ce_config{"CD_DEVICE"});
|
---|
373 | $ce_cd->{id} = sprintf "%08x", $id->[0];
|
---|
374 |
|
---|
375 | pb_log(1,"After get_discids\n");
|
---|
376 | pb_log(1,"id is:\n");
|
---|
377 | pb_log(1,Dumper($id)."\n");
|
---|
378 | pb_log(1,"ce_cd is:\n");
|
---|
379 | pb_log(1,Dumper($ce_cd)."\n");
|
---|
380 | # Try to find it locally
|
---|
381 | my @d = glob("$ENV{'HOME'}/.cddb/*/$ce_cd->{id}");
|
---|
382 | foreach my $d (@d) {
|
---|
383 | $ce_cd->{cat} = basename(dirname($d));
|
---|
384 | open(DISC,$d) || die "Unable to open $d";
|
---|
385 | # Idea taken from CDDB_get
|
---|
386 | while (<DISC>) {
|
---|
387 | push @{$ce_cd->{raw}},$_;
|
---|
388 | if (/^TTITLE(\d+)\=\s*(\S.*)/) {
|
---|
389 | chomp($2);
|
---|
390 | $ce_cd->{track}[$1]=$2;
|
---|
391 | } elsif(/^DTITLE=\s*(\S.*)/) {
|
---|
392 | my $t = $1;
|
---|
393 | if ($t =~ /\//) {
|
---|
394 | ($ce_cd->{artist},$ce_cd->{title}) = split(/\s\/\s/,$t);
|
---|
395 | } else {
|
---|
396 | $ce_cd->{artist}=$t;
|
---|
397 | $ce_cd->{title}=$t;
|
---|
398 | }
|
---|
399 | chomp($ce_cd->{title});
|
---|
400 | } elsif(/^DYEAR=\s*(\d+)/) {
|
---|
401 | $ce_cd->{year} = $1;
|
---|
402 | } elsif(/^DGENRE=\s*(\S.*)/) {
|
---|
403 | $ce_cd->{genre} = $1;
|
---|
404 | } elsif(/^\#\s+Revision:\s+(\d+)/) {
|
---|
405 | $ce_cd->{revision} = $1;
|
---|
406 | }
|
---|
407 | }
|
---|
408 | close(DISC);
|
---|
409 | }
|
---|
410 |
|
---|
411 | # Pre allocate from the physical media
|
---|
412 | my $device = Device::Cdio::Device->new(-source=>$ce_config{"CD_DEVICE"});
|
---|
413 | my $track = $device->get_last_track();
|
---|
414 | $ce_cd->{tno} = $track->{track};
|
---|
415 | my $n = 0;
|
---|
416 |
|
---|
417 | # If they were not found
|
---|
418 | $ce_cd->{artist} = "" if (not defined $ce_cd->{artist});
|
---|
419 | $ce_cd->{title} = "" if (not defined $ce_cd->{title});
|
---|
420 | $ce_cd->{genre} = "" if (not defined $ce_cd->{genre});
|
---|
421 | $ce_cd->{cat} = "" if (not defined $ce_cd->{cat});
|
---|
422 | $ce_cd->{year} = "" if (not defined $ce_cd->{year});
|
---|
423 | $ce_cd->{revision} = 0 if (not defined $ce_cd->{revision});
|
---|
424 |
|
---|
425 | # Going one track further for frame computation.
|
---|
426 | # Cf: http://www.gnu.org/software/libcdio/doxygen/track_8h.html
|
---|
427 | while ( $n <= $ce_cd->{tno}) {
|
---|
428 | $track->set_track($n+1);
|
---|
429 | # Again only if not found previously
|
---|
430 | $ce_cd->{track}[$n] = "" if (not defined $ce_cd->{track}[$n]);
|
---|
431 | my ($m, $s, $f) = split(/:/,$track->get_msf());
|
---|
432 | $ce_cd->{frames}[$n] = $f + 75*$s + 75*60*$m;
|
---|
433 | $n++;
|
---|
434 | }
|
---|
435 | }
|
---|
436 | # Modify enconding of some fields if proto < 5
|
---|
437 | #$ce_cd->{artist} = decode("iso8859-1",$ce_cd->{artist});
|
---|
438 | #$ce_cd->{title} = decode("iso8859-1",$ce_cd->{title});
|
---|
439 |
|
---|
440 | # Third panel to display CD Infos
|
---|
441 | Newt::DrawRootText(ce_center_string($ce_title), 1, $ce_title);
|
---|
442 | Newt::PushHelpLine($ce_help);
|
---|
443 |
|
---|
444 | # Components
|
---|
445 | $flag = NEWT_ENTRY_SCROLL;
|
---|
446 | $artist_entry = Newt::Entry($width, $flag, $ce_cd->{artist});
|
---|
447 | $title_entry = Newt::Entry($width, $flag, $ce_cd->{title});
|
---|
448 | # http://www.freedb.org/en/faq.3.html
|
---|
449 | # Category list is data, folk, jazz, misc, rock, country, blues, newage, reggae, classical, and soundtrack
|
---|
450 | $category_entry = Newt::Entry($width, $flag, $ce_cd->{cat});
|
---|
451 | $genre_entry = Newt::Entry($width, $flag, $ce_cd->{genre});
|
---|
452 | $tno_entry = Newt::Label($ce_cd->{tno}." - ".$id_label.$ce_cd->{id}." - ".$rev_label.$ce_cd->{revision});
|
---|
453 | $year_entry = Newt::Entry($width2, $flag, $ce_cd->{year});
|
---|
454 |
|
---|
455 | # Build interface
|
---|
456 | ($ce_sl, $ce_sh) = Newt::GetScreenSize();
|
---|
457 | $ce_panel = Newt::Panel(4, $ce_sh, "CDDB Info");
|
---|
458 | $flage = NEWT_ANCHOR_RIGHT;
|
---|
459 | $ce_panel->Add(0, 0, $artist_label,$flage);
|
---|
460 | $flage = NEWT_ANCHOR_LEFT;
|
---|
461 | $ce_panel->Add(1, 0, $artist_entry, $flage);
|
---|
462 | $flage = NEWT_ANCHOR_RIGHT;
|
---|
463 | $ce_panel->Add(0, 1, $title_label,$flage);
|
---|
464 | $flage = NEWT_ANCHOR_LEFT;
|
---|
465 | $ce_panel->Add(1, 1, $title_entry, $flage);
|
---|
466 | $flage = NEWT_ANCHOR_RIGHT;
|
---|
467 | $ce_panel->Add(0, 2, $year_label,$flage);
|
---|
468 | $flage = NEWT_ANCHOR_LEFT;
|
---|
469 | $ce_panel->Add(1, 2, $year_entry, $flage);
|
---|
470 | $flage = NEWT_ANCHOR_RIGHT;
|
---|
471 | $ce_panel->Add(0, 3, $category_label,$flage);
|
---|
472 | $flage = NEWT_ANCHOR_LEFT;
|
---|
473 | $ce_panel->Add(1, 3, $category_entry, $flage);
|
---|
474 | $flage = NEWT_ANCHOR_RIGHT;
|
---|
475 | $ce_panel->Add(0, 4, $genre_label,$flage);
|
---|
476 | $flage = NEWT_ANCHOR_LEFT;
|
---|
477 | $ce_panel->Add(1, 4, $genre_entry, $flage);
|
---|
478 | $flage = NEWT_ANCHOR_RIGHT;
|
---|
479 | $ce_panel->Add(0, 5, $tno_label,$flage);
|
---|
480 | $flage = NEWT_ANCHOR_LEFT;
|
---|
481 | $ce_panel->Add(1, 5, $tno_entry, $flage);
|
---|
482 |
|
---|
483 | my $n=0;
|
---|
484 | while ( $n < $ce_cd->{tno} ) {
|
---|
485 | last if ($n > $ce_sh - 9);
|
---|
486 | my $from=$ce_cd->{frames}[$n];
|
---|
487 | my $to=$ce_cd->{frames}[$n+1]-1;
|
---|
488 | my $dur=$to-$from;
|
---|
489 | my $min=int($dur/75/60);
|
---|
490 | my $sec=int($dur/75)-$min*60;
|
---|
491 | my $tr = sprintf "Track %2d: ", $n+1;
|
---|
492 | my $track_label = Newt::Label($tr);
|
---|
493 | $tr = sprintf " %2d':%.2d", $min, $sec;
|
---|
494 | # Adapt encoding of track if proto < 5
|
---|
495 | #$ce_cd->{track}[$n] = decode("iso8859-1",$ce_cd->{track}[$n]);
|
---|
496 |
|
---|
497 | my $dur_label = Newt::Label($tr);
|
---|
498 | $flag = NEWT_FLAG_WRAP|NEWT_ENTRY_SCROLL;
|
---|
499 | $track_entry[$n] = Newt::Entry($width, $flag, $ce_cd->{track}[$n]);
|
---|
500 | $flage = NEWT_ANCHOR_RIGHT;
|
---|
501 | $ce_panel->Add(0, 9+$n, $track_label,$flage);
|
---|
502 | $flage = NEWT_ANCHOR_LEFT;
|
---|
503 | $ce_panel->Add(1, 9+$n, $track_entry[$n], $flage);
|
---|
504 | $ce_panel->Add(2, 9+$n, $dur_label, $flage);
|
---|
505 | $n++;
|
---|
506 | }
|
---|
507 | $ce_panel->Add(0, 9+$n, $empty_label);
|
---|
508 |
|
---|
509 | my $eject_button = Newt::Button("Eject");
|
---|
510 | $eject_button->Tag("Eject");
|
---|
511 | my $ce_panel_button = Newt::Panel(4, $width);
|
---|
512 | $flage = NEWT_ANCHOR_LEFT;
|
---|
513 | $ce_panel_button->Add(0, 1, $send_button,$flage, 3, 0, 3, 0);
|
---|
514 | $ce_panel_button->Add(1, 1, $reload_button, $flage, 3, 0, 3, 0);
|
---|
515 | $flage = NEWT_ANCHOR_RIGHT;
|
---|
516 | $ce_panel_button->Add(2, 1, $quit_button, $flage, 3, 0, 3, 0);
|
---|
517 | $ce_panel_button->Add(3, 1, $eject_button,$flage, 3, 0, 3, 0);
|
---|
518 | $ce_panel->Add(0, 9+$n+1, $empty_label);
|
---|
519 | $ce_panel->Add(1, 9+$n+1, $ce_panel_button);
|
---|
520 |
|
---|
521 | Newt::Cls();
|
---|
522 | Newt::Refresh();
|
---|
523 |
|
---|
524 | # Build interface
|
---|
525 | ($reason, $data) = $ce_panel->Run();
|
---|
526 |
|
---|
527 | $ce_cd->{artist} = $artist_entry->Get();
|
---|
528 | $ce_cd->{title} = $title_entry->Get();
|
---|
529 | $ce_cd->{year} = $year_entry->Get();
|
---|
530 | $ce_cd->{cat} = $category_entry->Get();
|
---|
531 | $ce_cd->{genre} = $genre_entry->Get();
|
---|
532 | $n=1;
|
---|
533 | while ( $n <= $ce_cd->{tno} ) {
|
---|
534 | $ce_cd->{track}[$n-1] = $track_entry[$n-1]->Get();
|
---|
535 | $n++;
|
---|
536 | }
|
---|
537 | Newt::Refresh();
|
---|
538 | Newt::Cls();
|
---|
539 | cddbe_exit(0) if ($data->Tag() eq "Quit");
|
---|
540 | system("eject ".$ce_config{"CD_DEVICE"}) if ($data->Tag() eq "Eject");
|
---|
541 |
|
---|
542 | pb_log(1,"Before sending\n");
|
---|
543 | pb_log(1,"ce_cd is:\n");
|
---|
544 | pb_log(1,Dumper($ce_cd)."\n");
|
---|
545 |
|
---|
546 | # Send the data
|
---|
547 | if ($data->Tag() eq "Send") {
|
---|
548 | $flag = NEWT_FLAG_WRAP;
|
---|
549 | my $height = 10;
|
---|
550 |
|
---|
551 | Newt::DrawRootText(ce_center_string($ce_title), 1, $ce_title);
|
---|
552 | Newt::PushHelpLine($ce_help);
|
---|
553 |
|
---|
554 | my $txt = "Please wait while sending disc $ce_cd->{id} ($ce_cd->{cat}) to $ce_config{\"CDDB_USER\"}";
|
---|
555 | my $info_tb = Newt::Textbox($width, $height, $flag, $txt);
|
---|
556 |
|
---|
557 | Newt::Cls();
|
---|
558 | $ce_panel = Newt::Panel(3, $width, "CDDB Sending Infos");
|
---|
559 | $ce_panel->Add(0, 0, $info_tb);
|
---|
560 | $ce_panel->Add(0, 1, $quit_button);
|
---|
561 | Newt::Refresh();
|
---|
562 | # TODO: Mail::Sendmail ?
|
---|
563 | ce_prepare_mail($ce_cd);
|
---|
564 | pb_system("mutt -s \"cddb $ce_cd->{cat} $ce_cd->{id}\" -c $ce_config{\"CDDB_CC\"} $ce_config{\"CDDB_USER\"} < $ENV{'HOME'}/.cddb/$ce_cd->{cat}/$ce_cd->{id}", "quiet");
|
---|
565 | ($reason, $data) = $ce_panel->Run();
|
---|
566 |
|
---|
567 | # Force reloading info from cache
|
---|
568 | $ce_cd->{title} = undef;
|
---|
569 | }
|
---|
570 | if ($data->Tag() eq "Reload") {
|
---|
571 | # Then force CDDB query
|
---|
572 | $firsttime = 1;
|
---|
573 | }
|
---|
574 | }
|
---|
575 | Newt::Finished();
|
---|
576 | cddbe_exit(0);
|
---|
577 |
|
---|
578 | # return the char to start printing a centered string based on screen size
|
---|
579 | sub ce_center_string {
|
---|
580 |
|
---|
581 | my $string = shift || "";
|
---|
582 |
|
---|
583 | my $res = ($ce_sl / 2 ) - (length($string) / 2);
|
---|
584 | if ($res < 0 ) {
|
---|
585 | return 0;
|
---|
586 | } else {
|
---|
587 | return ($res);
|
---|
588 | }
|
---|
589 | }
|
---|
590 |
|
---|
591 | sub ce_prepare_mail() {
|
---|
592 |
|
---|
593 | my $ce_cd = shift;
|
---|
594 |
|
---|
595 | pb_mkdir_p("$ENV{'HOME'}/.cddb/$ce_cd->{cat}");
|
---|
596 | open(MAIL, "> $ENV{'HOME'}/.cddb/$ce_cd->{cat}/$ce_cd->{id}") || die "Unable to create $ENV{'HOME'}/.cddb/$ce_cd->{cat}/$ce_cd->{id}";
|
---|
597 | print MAIL "# xmcd CD database file\n#\n# Track frame offsets:\n";
|
---|
598 | my $n=0;
|
---|
599 | while ( $n < $ce_cd->{tno} ) {
|
---|
600 | print MAIL "# ".$ce_cd->{frames}[$n]."\n";
|
---|
601 | $n++;
|
---|
602 | }
|
---|
603 | #my $from=int($ce_cd->{frames}[0]/75);
|
---|
604 | my $sec=int($ce_cd->{frames}[$ce_cd->{tno}]/75);
|
---|
605 | #my $sec=$to-$from;
|
---|
606 | my $rev = $ce_cd->{revision} + 1;
|
---|
607 | # Taken from CDDB.pm
|
---|
608 | print MAIL "#\n# Disc length: $sec seconds\n#\n";
|
---|
609 | print MAIL "# Revision: $rev\n";
|
---|
610 | print MAIL "# Processed by: cddbd v1.5PL3 Copyright (c) Steve Scherf et al.\n";
|
---|
611 | print MAIL "# Submitted via: CDDBEditor $projver-$projrev\n";
|
---|
612 | print MAIL "DISCID=$ce_cd->{id}\n";
|
---|
613 | print MAIL "DTITLE=$ce_cd->{artist} / $ce_cd->{title}\n";
|
---|
614 | print MAIL "DYEAR=$ce_cd->{year}\n";
|
---|
615 | print MAIL "DGENRE=$ce_cd->{genre}\n";
|
---|
616 | $n=0;
|
---|
617 | while ( $n < $ce_cd->{tno} ) {
|
---|
618 | print MAIL "TTITLE$n=$ce_cd->{track}[$n]\n";
|
---|
619 | $n++;
|
---|
620 | }
|
---|
621 | print MAIL "EXTD=\n";
|
---|
622 | $n=0;
|
---|
623 | while ( $n < $ce_cd->{tno} ) {
|
---|
624 | print MAIL "EXTT$n=\n";
|
---|
625 | $n++;
|
---|
626 | }
|
---|
627 | print MAIL "PLAYORDER=\n";
|
---|
628 | close(MAIL);
|
---|
629 | }
|
---|
630 |
|
---|
631 | sub cddbe_exit {
|
---|
632 |
|
---|
633 | my $ret = shift;
|
---|
634 | close(LOG);
|
---|
635 | exit $ret
|
---|
636 | }
|
---|
637 |
|
---|
638 | 1;
|
---|