source: ProjectBuilder/projects/CDDBeditor/devel/CDDBeditor/bin/CDDBeditor@ 2689

Last change on this file since 2689 was 2689, checked in by Bruno Cornec, 17 months ago

Use now GnuDB as target mail

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