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

Last change on this file since 1797 was 1797, checked in by Bruno Cornec, 10 years ago
  • Remove debug for CDDBEditor
  • Property svn:executable set to *
File size: 17.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
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 File::Copy;
30use File::Basename;
31
32# Global variables
33my %opts; # CLI Options
34my $action; # action to realize
35
36my @date = pb_get_date();
37my $pbdate = strftime("%Y-%m-%d", @date);
38
39pb_temp_init();
40
41=pod
42
43=head1 NAME
44
45CDDBeditor, read, modidy and send your CDDB contrinutions
46
47=head1 DESCRIPTION
48
49CDDBeditor helps you read, modidy and send your CDDB contrinutions.
50
51=head1 SYNOPSIS
52
53CDDBeditor [-vhmq][-t|-g]
54
55CDDBeditor [--verbose][--help][--man][--quiet][--text|--graphic]
56
57=head1 OPTIONS
58
59=over 4
60
61=item B<-v|--verbose>
62
63Print a brief help message and exits.
64
65=item B<-q|--quiet>
66
67Do not print any output.
68
69=item B<-h|--help>
70
71Print a brief help message and exits.
72
73=item B<--man>
74
75Prints the manual page and exits.
76
77=item B<-t|--text>
78=item B<-g|--graphic>
79
80Interface is either text mode or graphical mode (newt based)
81
82=back
83
84=head1 ARGUMENTS
85
86=head1 WEB SITES
87
88The 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
92None exists for the moment.
93
94=head1 CONFIGURATION FILES
95
96=head1 AUTHORS
97
98The CDDBeditor team L<http://trac.project-builder.org/> lead by Bruno Cornec L<mailto:bruno@project-builder.org>.
99
100=head1 COPYRIGHT
101
102CDDBeditor is distributed under the GPL v2.0 license
103described in the file C<COPYING> included with the distribution.
104
105=cut
106
107# ---------------------------------------------------------------------------
108
109#Avoids an error from Newt
110no AutoLoader;
111
112
113# Initialize the syntax string
114
115my $projver = "PBVER";
116my $projrev = "PBREV";
117
118pb_syntax_init("CDDBeditor Version $projver-$projrev\n");
119
120GetOptions("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
129if (defined $opts{'h'}) {
130 pb_syntax(0,1);
131}
132if (defined $opts{'man'}) {
133 pb_syntax(0,2);
134}
135$pbdebug = 0;
136if (defined $opts{'v'}) {
137 $pbdebug = $opts{'v'};
138}
139if (defined $opts{'q'}) {
140 $pbdebug=-1;
141}
142open(LOG, "> $ENV{HOME}/.CDDBeditor.log") || die "Unable to open $ENV{HOME}/.CDDBeditor.log";
143pb_log_init($pbdebug, \*LOG);
144
145Newt::Init();
146
147# String definitions
148my $ce_title = "CDDBeditor";
149my $ce_help = "(c) Bruno Cornec 2009 - All right reversed under the GPL v2";
150my $artist_label = Newt::Label("Artist: ");
151my $empty_label = Newt::Label(" ");
152my $title_label = Newt::Label("Title: ");
153my $year_label = Newt::Label("Year: ");
154my $id_label = "Id: ";
155my $rev_label = "Revision: ";
156my $genre_label = Newt::Label("Genre: ");
157my $category_label = Newt::Label("Category: ");
158my $info_label = Newt::Label("Info: ");
159my $tr_track_label = Newt::Label("Track");
160my $tr_frames_label = Newt::Label("Frames");
161my $tno_label = Newt::Label("Track #: ");
162my $tr_title_label = Newt::Label("Title");
163my $tr_author_label = Newt::Label("Author");
164my $tr_length_label = Newt::Label("Length");
165
166my $host_label = Newt::Label("Host: ");
167my $port_label = Newt::Label("Port: ");
168my $mode_label = Newt::Label("Mode: ");
169my $dev_label = Newt::Label("Device: ");
170my $proxy_label = Newt::Label("Proxy: ");
171
172my $wait_label = Newt::Label("Please wait while searching ...");
173
174# To be put in conf file
175my %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;
181my %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
199my ($ce_sl, $ce_sh) = Newt::GetScreenSize();
200
201# First panel for configuration parameters
202Newt::Cls();
203Newt::DrawRootText(ce_center_string($ce_title), 1, $ce_title);
204Newt::PushHelpLine($ce_help);
205Newt::Refresh();
206
207my $flag = NEWT_ENTRY_SCROLL;
208# Need 23 char for track and time
209my $width = $ce_sl - 23;
210# Other fields are limited to 5
211my $width2 = 5;
212my $host_entry = Newt::Entry($width, $flag, $ce_config{"CDDB_HOST"});
213my $port_entry = Newt::Entry($width2, $flag, $ce_config{"CDDB_PORT"});
214my $mode_group;
215my $proxy_entry = undef;
216if ($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}
221if ($ce_config{"CDDB_MODE"} eq "http" ) {
222 $proxy_entry = Newt::Entry($width, $flag, $ce_config{"HTTP_PROXY"});
223}
224my $dev_entry = Newt::Entry($width, $flag, $ce_config{"CD_DEVICE"});
225my $user_group;
226my $next_button = Newt::Button("Next");
227$next_button->Tag("Next");
228my $quit_button = Newt::Button("Quit");
229$quit_button->Tag("Quit");
230
231my $ce_panel = Newt::Panel(2, 20, "CDDBeditor Configuration");
232my $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);
244if ($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
259Newt::Refresh();
260my ($reason, $data) = $ce_panel->Run();
261
262Newt::Cls();
263cddbe_exit(0) if ($data->Tag() eq "Quit");
264
265if ($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
273pb_log(1,"After first screen\n");
274pb_log(1,"ce_config is:\n");
275pb_log(1,Dumper(%ce_config)."\n");
276
277# Components
278my $reload_button = Newt::Button("Reload");
279$reload_button->Tag("Reload");
280my $send_button = Newt::Button("Send");
281$send_button->Tag("Send");
282
283my $firsttime = 1;
284my @cecd;
285my $ce_cd;
286my $artist_entry;
287my $title_entry;
288my $category_entry;
289my $genre_entry;
290my $tno_entry;
291my $year_entry;
292my @track_entry;
293
294# Entering the loop
295for (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}
575Newt::Finished();
576cddbe_exit(0);
577
578# return the char to start printing a centered string based on screen size
579sub 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
591sub ce_prepare_mail() {
592
593my $ce_cd = shift;
594
595pb_mkdir_p("$ENV{'HOME'}/.cddb/$ce_cd->{cat}");
596open(MAIL, "> $ENV{'HOME'}/.cddb/$ce_cd->{cat}/$ce_cd->{id}") || die "Unable to create $ENV{'HOME'}/.cddb/$ce_cd->{cat}/$ce_cd->{id}";
597print MAIL "# xmcd CD database file\n#\n# Track frame offsets:\n";
598my $n=0;
599while ( $n < $ce_cd->{tno} ) {
600 print MAIL "# ".$ce_cd->{frames}[$n]."\n";
601 $n++;
602}
603#my $from=int($ce_cd->{frames}[0]/75);
604my $sec=int($ce_cd->{frames}[$ce_cd->{tno}]/75);
605#my $sec=$to-$from;
606my $rev = $ce_cd->{revision} + 1;
607# Taken from CDDB.pm
608print MAIL "#\n# Disc length: $sec seconds\n#\n";
609print MAIL "# Revision: $rev\n";
610print MAIL "# Processed by: cddbd v1.5PL3 Copyright (c) Steve Scherf et al.\n";
611print MAIL "# Submitted via: CDDBEditor $projver-$projrev\n";
612print MAIL "DISCID=$ce_cd->{id}\n";
613print MAIL "DTITLE=$ce_cd->{artist} / $ce_cd->{title}\n";
614print MAIL "DYEAR=$ce_cd->{year}\n";
615print MAIL "DGENRE=$ce_cd->{genre}\n";
616$n=0;
617while ( $n < $ce_cd->{tno} ) {
618 print MAIL "TTITLE$n=$ce_cd->{track}[$n]\n";
619 $n++;
620}
621print MAIL "EXTD=\n";
622$n=0;
623while ( $n < $ce_cd->{tno} ) {
624 print MAIL "EXTT$n=\n";
625 $n++;
626}
627print MAIL "PLAYORDER=\n";
628close(MAIL);
629}
630
631sub cddbe_exit {
632
633my $ret = shift;
634close(LOG);
635exit $ret
636}
637
6381;
Note: See TracBrowser for help on using the repository browser.