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

Last change on this file since 1744 was 1744, checked in by Bruno Cornec, 11 years ago
  • Adds an eject button at end to avoid switching window just for that.
  • 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}
135if (defined $opts{'v'}) {
136 $pbdebug = $opts{'v'};
137}
138if (defined $opts{'q'}) {
139 $pbdebug=-1;
140}
141open(LOG, "> $ENV{HOME}/.CDDBeditor.log") || die "Unable to open $ENV{HOME}/.CDDBeditor.log";
142pb_log_init($pbdebug, \*LOG);
143
144Newt::Init();
145
146# String definitions
147my $ce_title = "CDDBeditor";
148my $ce_help = "(c) Bruno Cornec 2009 - All right reversed under the GPL v2";
149my $artist_label = Newt::Label("Artist: ");
150my $empty_label = Newt::Label(" ");
151my $title_label = Newt::Label("Title: ");
152my $year_label = Newt::Label("Year: ");
153my $id_label = "Id: ";
154my $rev_label = "Revision: ";
155my $genre_label = Newt::Label("Genre: ");
156my $category_label = Newt::Label("Category: ");
157my $info_label = Newt::Label("Info: ");
158my $tr_track_label = Newt::Label("Track");
159my $tr_frames_label = Newt::Label("Frames");
160my $tno_label = Newt::Label("Track #: ");
161my $tr_title_label = Newt::Label("Title");
162my $tr_author_label = Newt::Label("Author");
163my $tr_length_label = Newt::Label("Length");
164
165my $host_label = Newt::Label("Host: ");
166my $port_label = Newt::Label("Port: ");
167my $mode_label = Newt::Label("Mode: ");
168my $dev_label = Newt::Label("Device: ");
169my $proxy_label = Newt::Label("Proxy: ");
170
171my $wait_label = Newt::Label("Please wait while searching ...");
172
173# To be put in conf file
174my %ce_config;
175$ce_config{"CDDB_HOST"}="freedb.freedb.org";
176$ce_config{"CDDB_USER"}="freedb-submit\@freedb.org";
177$ce_config{"CDDB_CC"}="bruno\@victoria.frmug.org";
178$ce_config{"CDDB_PORT"}=888;
179#$ce_config{"CDDB_PORT"}=80;
180my %ce_cddb_mode;
181$ce_cddb_mode{"0"} = "cddb";
182$ce_cddb_mode{"1"} = "http";
183
184$ce_config{"CDDB_MODE"}=$ce_cddb_mode{"0"};
185$ce_config{"CD_DEVICE"}="/dev/sr1";
186$ce_config{"HTTP_PROXY"}=$ENV{http_proxy} if $ENV{http_proxy};
187$ce_config{"input"}=0;
188$ce_config{"multi"}=1;
189$ce_config{"PROTO_VERSION"} = 6;
190$ce_config{"DOMAIN"} = "musique-ancienne.org";
191$ce_config{"USER"} = "bruno";
192# Requires 4 words exactly
193$ce_config{"HELLO_ID"} = "$ce_config{\"USER\"} $ce_config{\"DOMAIN\"} CDDBEditor 0.5";
194
195# Copied from CDDB.pm
196# Determine whether we can submit changes by e-mail.
197
198my ($ce_sl, $ce_sh) = Newt::GetScreenSize();
199
200# First panel for configuration parameters
201Newt::Cls();
202Newt::DrawRootText(ce_center_string($ce_title), 1, $ce_title);
203Newt::PushHelpLine($ce_help);
204Newt::Refresh();
205
206my $flag = NEWT_ENTRY_SCROLL;
207# Need 23 char for track and time
208my $width = $ce_sl - 23;
209# Other fields are limited to 5
210my $width2 = 5;
211my $host_entry = Newt::Entry($width, $flag, $ce_config{"CDDB_HOST"});
212my $port_entry = Newt::Entry($width2, $flag, $ce_config{"CDDB_PORT"});
213my $mode_group;
214my $proxy_entry = undef;
215if ($ce_config{"CDDB_MODE"} eq $ce_cddb_mode{"0"}) {
216 $mode_group = Newt::HRadiogroup($ce_cddb_mode{"0"}, $ce_cddb_mode{"1"});
217} else {
218 $mode_group = Newt::HRadiogroup($ce_cddb_mode{"1"}, $ce_cddb_mode{"0"});
219}
220if ($ce_config{"CDDB_MODE"} eq "http" ) {
221 $proxy_entry = Newt::Entry($width, $flag, $ce_config{"HTTP_PROXY"});
222}
223my $dev_entry = Newt::Entry($width, $flag, $ce_config{"CD_DEVICE"});
224my $user_group;
225my $next_button = Newt::Button("Next");
226$next_button->Tag("Next");
227my $quit_button = Newt::Button("Quit");
228$quit_button->Tag("Quit");
229
230my $ce_panel = Newt::Panel(2, 20, "CDDBeditor Configuration");
231my $flage = NEWT_ANCHOR_RIGHT;
232$ce_panel->Add(0, 0, $host_label, $flage);
233$flage = NEWT_ANCHOR_LEFT;
234$ce_panel->Add(1, 0, $host_entry, $flage);
235$flage = NEWT_ANCHOR_RIGHT;
236$ce_panel->Add(0, 1, $port_label, $flage);
237$flage = NEWT_ANCHOR_LEFT;
238$ce_panel->Add(1, 1, $port_entry, $flage);
239$flage = NEWT_ANCHOR_RIGHT;
240$ce_panel->Add(0, 2, $mode_label, $flage);
241$flage = NEWT_ANCHOR_LEFT;
242$ce_panel->Add(1, 2, $mode_group, $flage);
243if ($ce_config{"CDDB_MODE"} eq "http" ) {
244 $flage = NEWT_ANCHOR_RIGHT;
245 $ce_panel->Add(0, 3, $proxy_label, $flage);
246 $flage = NEWT_ANCHOR_LEFT;
247 $ce_panel->Add(1, 3, $proxy_entry, $flage);
248 }
249$flage = NEWT_ANCHOR_RIGHT;
250$ce_panel->Add(0, 4, $dev_label, $flage);
251$flage = NEWT_ANCHOR_LEFT;
252$ce_panel->Add(1, 4, $dev_entry, $flage);
253$flage = NEWT_ANCHOR_LEFT;
254$ce_panel->Add(0, 6, $empty_label);
255$ce_panel->Add(0, 7, $next_button);
256$ce_panel->Add(1, 7, $quit_button);
257
258Newt::Refresh();
259my ($reason, $data) = $ce_panel->Run();
260
261Newt::Cls();
262cddbe_exit(0) if ($data->Tag() eq "Quit");
263
264if ($ce_config{"CDDB_MODE"} eq "http" ) {
265 $ce_config{"HTTP_PROXY"}=$proxy_entry->Get();
266 }
267$ce_config{"CDDB_HOST"}=$host_entry->Get();
268$ce_config{"CDDB_PORT"}=$port_entry->Get();
269$ce_config{"CDDB_MODE"}=$ce_cddb_mode{$mode_group->Get()};
270$ce_config{"CD_DEVICE"}=$dev_entry->Get();
271
272pb_log(1,"After first screen\n");
273pb_log(1,"ce_config is:\n");
274pb_log(1,Dumper(%ce_config)."\n");
275
276# Components
277my $reload_button = Newt::Button("Reload");
278$reload_button->Tag("Reload");
279my $send_button = Newt::Button("Send");
280$send_button->Tag("Send");
281
282my $firsttime = 1;
283my @cecd;
284my $ce_cd;
285my $artist_entry;
286my $title_entry;
287my $category_entry;
288my $genre_entry;
289my $tno_entry;
290my $year_entry;
291my @track_entry;
292
293# Entering the loop
294for (my $i=0 ; ; $i++) { # Second panel to make user wait
295 Newt::Cls();
296 Newt::DrawRootText(ce_center_string($ce_title), 1, $ce_title);
297 Newt::PushHelpLine($ce_help);
298 $ce_panel = Newt::Panel(3, 20, "CDDB Search");
299 $ce_panel->Add(0, 0, $wait_label);
300
301 ($reason, $data) = $ce_panel->Draw();
302 Newt::Refresh();
303
304 # CDDB query if first time
305 if ($firsttime == 1) {
306 @cecd = get_cddb(\%ce_config);
307 # by default use first one
308 $ce_cd = $cecd[0] if (defined $cecd[0]);
309 pb_log(1,"After get_cddb\n");
310 pb_log(1,"cecd is:\n");
311 pb_log(1,Dumper(@cecd)."\n");
312 }
313 $firsttime = 0;
314
315 my @vradio;
316 my $ind = 0;
317 foreach my $entry (@cecd) {
318 my $cat = "";
319 my $tno = "";
320 my $title = "";
321 $cat = $entry->{cat} if (defined $entry->{cat});
322 $tno = $entry->{tno} if (defined $entry->{tno});
323 $title = $entry->{title} if (defined $entry->{title});
324 my $chain = undef;
325 $chain = sprintf("%02d (%s - %d tracks) - %s",$ind,$cat,$tno,$title) if ((defined $cat) && (defined $tno) && (defined $title));
326 push @vradio,$chain if (defined $chain);
327 $ind++;
328 }
329 pb_log(1,"ind is: $ind\n");
330
331 if ($ind gt 1) {
332 # We have multiple entries chose the right one
333 # Second panel for configuration parameters
334 Newt::Cls();
335 Newt::DrawRootText(ce_center_string($ce_title), 1, $ce_title);
336 Newt::PushHelpLine($ce_help);
337 Newt::Refresh();
338
339 my $user_group = Newt::VRadiogroup(@vradio);
340 my $quit_button = Newt::Button("Quit");
341 $quit_button->Tag("Quit");
342 my $next_button = Newt::Button("Next");
343 $next_button->Tag("Next");
344
345 my $ce_panel = Newt::Panel(2, 20, "CD chooser");
346 $flage = NEWT_ANCHOR_LEFT;
347 $ce_panel->Add(0, 5, $user_group, $flage);
348 $ce_panel->Add(0, 10, $empty_label);
349 $ce_panel->Add(0, 11, $next_button);
350 $ce_panel->Add(1, 11, $quit_button);
351
352 Newt::Refresh();
353 my ($reason, $data) = $ce_panel->Run();
354
355 Newt::Cls();
356 cddbe_exit(0) if ($data->Tag() eq "Quit");
357
358 $ind=$user_group->Get();
359 } else {
360 # if only one CD, back to its number which is 0
361 $ind--;
362 }
363 # Point now to the right CD
364 $ce_cd = $cecd[$ind];
365 pb_log(1,"After CD choice\n");
366 pb_log(1,"ce_cd is: \n");
367 pb_log(1,Dumper($ce_cd)."\n");
368
369 if (not defined $ce_cd->{title}) {
370 # Get the disc id first
371 my $id = get_discids($ce_config{"CD_DEVICE"});
372 $ce_cd->{id} = sprintf "%08x", $id->[0];
373
374 pb_log(1,"After get_discids\n");
375 pb_log(1,"id is:\n");
376 pb_log(1,Dumper($id)."\n");
377 pb_log(1,"ce_cd is:\n");
378 pb_log(1,Dumper($ce_cd)."\n");
379 # Try to find it locally
380 my @d = glob("$ENV{'HOME'}/.cddb/*/$ce_cd->{id}");
381 foreach my $d (@d) {
382 $ce_cd->{cat} = basename(dirname($d));
383 open(DISC,$d) || die "Unable to open $d";
384 # Idea taken from CDDB_get
385 while (<DISC>) {
386 push @{$ce_cd->{raw}},$_;
387 if (/^TTITLE(\d+)\=\s*(\S.*)/) {
388 chomp($2);
389 $ce_cd->{track}[$1]=$2;
390 } elsif(/^DTITLE=\s*(\S.*)/) {
391 my $t = $1;
392 if ($t =~ /\//) {
393 ($ce_cd->{artist},$ce_cd->{title}) = split(/\s\/\s/,$t);
394 } else {
395 $ce_cd->{artist}=$t;
396 $ce_cd->{title}=$t;
397 }
398 chomp($ce_cd->{title});
399 } elsif(/^DYEAR=\s*(\d+)/) {
400 $ce_cd->{year} = $1;
401 } elsif(/^DGENRE=\s*(\S.*)/) {
402 $ce_cd->{genre} = $1;
403 } elsif(/^\#\s+Revision:\s+(\d+)/) {
404 $ce_cd->{revision} = $1;
405 }
406 }
407 close(DISC);
408 }
409
410 # Pre allocate from the physical media
411 my $device = Device::Cdio::Device->new(-source=>$ce_config{"CD_DEVICE"});
412 my $track = $device->get_last_track();
413 $ce_cd->{tno} = $track->{track};
414 my $n = 0;
415
416 # If they were not found
417 $ce_cd->{artist} = "" if (not defined $ce_cd->{artist});
418 $ce_cd->{title} = "" if (not defined $ce_cd->{title});
419 $ce_cd->{genre} = "" if (not defined $ce_cd->{genre});
420 $ce_cd->{cat} = "" if (not defined $ce_cd->{cat});
421 $ce_cd->{year} = "" if (not defined $ce_cd->{year});
422 $ce_cd->{revision} = 0 if (not defined $ce_cd->{revision});
423
424 # Going one track further for frame computation.
425 # Cf: http://www.gnu.org/software/libcdio/doxygen/track_8h.html
426 while ( $n <= $ce_cd->{tno}) {
427 $track->set_track($n+1);
428 # Again only if not found previously
429 $ce_cd->{track}[$n] = "" if (not defined $ce_cd->{track}[$n]);
430 my ($m, $s, $f) = split(/:/,$track->get_msf());
431 $ce_cd->{frames}[$n] = $f + 75*$s + 75*60*$m;
432 $n++;
433 }
434 }
435 # Modify enconding of some fields if proto < 5
436 #$ce_cd->{artist} = decode("iso8859-1",$ce_cd->{artist});
437 #$ce_cd->{title} = decode("iso8859-1",$ce_cd->{title});
438
439 # Third panel to display CD Infos
440 Newt::DrawRootText(ce_center_string($ce_title), 1, $ce_title);
441 Newt::PushHelpLine($ce_help);
442
443 # Components
444 $flag = NEWT_ENTRY_SCROLL;
445 $artist_entry = Newt::Entry($width, $flag, $ce_cd->{artist});
446 $title_entry = Newt::Entry($width, $flag, $ce_cd->{title});
447 # http://www.freedb.org/en/faq.3.html
448 # Category list is data, folk, jazz, misc, rock, country, blues, newage, reggae, classical, and soundtrack
449 $category_entry = Newt::Entry($width, $flag, $ce_cd->{cat});
450 $genre_entry = Newt::Entry($width, $flag, $ce_cd->{genre});
451 $tno_entry = Newt::Label($ce_cd->{tno}." - ".$id_label.$ce_cd->{id}." - ".$rev_label.$ce_cd->{revision});
452 $year_entry = Newt::Entry($width2, $flag, $ce_cd->{year});
453
454 # Build interface
455 ($ce_sl, $ce_sh) = Newt::GetScreenSize();
456 $ce_panel = Newt::Panel(4, $ce_sh, "CDDB Info");
457 $flage = NEWT_ANCHOR_RIGHT;
458 $ce_panel->Add(0, 0, $artist_label,$flage);
459 $flage = NEWT_ANCHOR_LEFT;
460 $ce_panel->Add(1, 0, $artist_entry, $flage);
461 $flage = NEWT_ANCHOR_RIGHT;
462 $ce_panel->Add(0, 1, $title_label,$flage);
463 $flage = NEWT_ANCHOR_LEFT;
464 $ce_panel->Add(1, 1, $title_entry, $flage);
465 $flage = NEWT_ANCHOR_RIGHT;
466 $ce_panel->Add(0, 2, $year_label,$flage);
467 $flage = NEWT_ANCHOR_LEFT;
468 $ce_panel->Add(1, 2, $year_entry, $flage);
469 $flage = NEWT_ANCHOR_RIGHT;
470 $ce_panel->Add(0, 3, $category_label,$flage);
471 $flage = NEWT_ANCHOR_LEFT;
472 $ce_panel->Add(1, 3, $category_entry, $flage);
473 $flage = NEWT_ANCHOR_RIGHT;
474 $ce_panel->Add(0, 4, $genre_label,$flage);
475 $flage = NEWT_ANCHOR_LEFT;
476 $ce_panel->Add(1, 4, $genre_entry, $flage);
477 $flage = NEWT_ANCHOR_RIGHT;
478 $ce_panel->Add(0, 5, $tno_label,$flage);
479 $flage = NEWT_ANCHOR_LEFT;
480 $ce_panel->Add(1, 5, $tno_entry, $flage);
481
482 my $n=0;
483 while ( $n < $ce_cd->{tno} ) {
484 last if ($n > $ce_sh - 9);
485 my $from=$ce_cd->{frames}[$n];
486 my $to=$ce_cd->{frames}[$n+1]-1;
487 my $dur=$to-$from;
488 my $min=int($dur/75/60);
489 my $sec=int($dur/75)-$min*60;
490 my $tr = sprintf "Track %2d:", $n+1;
491 my $track_label = Newt::Label($tr);
492 $tr = sprintf " %2d':%.2d", $min, $sec;
493 # Adapt encoding of track if proto < 5
494 #$ce_cd->{track}[$n] = decode("iso8859-1",$ce_cd->{track}[$n]);
495
496 my $dur_label = Newt::Label($tr);
497 $flag = NEWT_FLAG_WRAP|NEWT_ENTRY_SCROLL;
498 $track_entry[$n] = Newt::Entry($width, $flag, $ce_cd->{track}[$n]);
499 $flage = NEWT_ANCHOR_RIGHT;
500 $ce_panel->Add(0, 9+$n, $track_label,$flage);
501 $flage = NEWT_ANCHOR_LEFT;
502 $ce_panel->Add(1, 9+$n, $track_entry[$n], $flage);
503 $ce_panel->Add(2, 9+$n, $dur_label, $flage);
504 $n++;
505 }
506 $ce_panel->Add(0, 9+$n, $empty_label);
507
508 my $eject_button = Newt::Button("Eject");
509 $eject_button->Tag("Eject");
510 my $ce_panel_button = Newt::Panel(4, $width);
511 $flage = NEWT_ANCHOR_LEFT;
512 $ce_panel_button->Add(0, 1, $send_button,$flage, 3, 0, 3, 0);
513 $ce_panel_button->Add(1, 1, $reload_button, $flage, 3, 0, 3, 0);
514 $flage = NEWT_ANCHOR_RIGHT;
515 $ce_panel_button->Add(2, 1, $quit_button, $flage, 3, 0, 3, 0);
516 $ce_panel_button->Add(3, 1, $eject_button,$flage, 3, 0, 3, 0);
517 $ce_panel->Add(0, 9+$n+1, $empty_label);
518 $ce_panel->Add(1, 9+$n+1, $ce_panel_button);
519
520 Newt::Cls();
521 Newt::Refresh();
522
523 # Build interface
524 ($reason, $data) = $ce_panel->Run();
525
526 $ce_cd->{artist} = $artist_entry->Get();
527 $ce_cd->{title} = $title_entry->Get();
528 $ce_cd->{year} = $year_entry->Get();
529 $ce_cd->{cat} = $category_entry->Get();
530 $ce_cd->{genre} = $genre_entry->Get();
531 $n=1;
532 while ( $n <= $ce_cd->{tno} ) {
533 $ce_cd->{track}[$n-1] = $track_entry[$n-1]->Get();
534 $n++;
535 }
536 Newt::Refresh();
537 Newt::Cls();
538 cddbe_exit(0) if ($data->Tag() eq "Quit");
539 system("eject ".$ce_config{"CD_DEVICE"}) if ($data->Tag() eq "Eject");
540
541 pb_log(1,"Before sending\n");
542 pb_log(1,"ce_cd is:\n");
543 pb_log(1,Dumper($ce_cd)."\n");
544
545 # Send the data
546 if ($data->Tag() eq "Send") {
547 $flag = NEWT_FLAG_WRAP;
548 my $height = 10;
549
550 Newt::DrawRootText(ce_center_string($ce_title), 1, $ce_title);
551 Newt::PushHelpLine($ce_help);
552
553 my $txt = "Please wait while sending disc $ce_cd->{id} ($ce_cd->{cat}) to $ce_config{\"CDDB_USER\"}";
554 my $info_tb = Newt::Textbox($width, $height, $flag, $txt);
555
556 Newt::Cls();
557 $ce_panel = Newt::Panel(3, $width, "CDDB Sending Infos");
558 $ce_panel->Add(0, 0, $info_tb);
559 $ce_panel->Add(0, 1, $quit_button);
560 Newt::Refresh();
561 # TODO: Mail::Sendmail ?
562 ce_prepare_mail($ce_cd);
563 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");
564 ($reason, $data) = $ce_panel->Run();
565
566 # Force reloading info from cache
567 $ce_cd->{title} = undef;
568 }
569 if ($data->Tag() eq "Reload") {
570 # Then force CDDB query
571 $firsttime = 1;
572 }
573}
574Newt::Finished();
575cddbe_exit(0);
576
577# return the char to start printing a centered string based on screen size
578sub ce_center_string {
579
580 my $string = shift || "";
581
582 my $res = ($ce_sl / 2 ) - (length($string) / 2);
583 if ($res < 0 ) {
584 return 0;
585 } else {
586 return ($res);
587 }
588}
589
590sub ce_prepare_mail() {
591
592my $ce_cd = shift;
593
594pb_mkdir_p("$ENV{'HOME'}/.cddb/$ce_cd->{cat}");
595open(MAIL, "> $ENV{'HOME'}/.cddb/$ce_cd->{cat}/$ce_cd->{id}") || die "Unable to create $ENV{'HOME'}/.cddb/$ce_cd->{cat}/$ce_cd->{id}";
596print MAIL "# xmcd CD database file\n#\n# Track frame offsets:\n";
597my $n=0;
598while ( $n < $ce_cd->{tno} ) {
599 print MAIL "# ".$ce_cd->{frames}[$n]."\n";
600 $n++;
601}
602#my $from=int($ce_cd->{frames}[0]/75);
603my $sec=int($ce_cd->{frames}[$ce_cd->{tno}]/75);
604#my $sec=$to-$from;
605my $rev = $ce_cd->{revision} + 1;
606# Taken from CDDB.pm
607print MAIL "#\n# Disc length: $sec seconds\n#\n";
608print MAIL "# Revision: $rev\n";
609print MAIL "# Processed by: cddbd v1.5PL3 Copyright (c) Steve Scherf et al.\n";
610print MAIL "# Submitted via: CDDBEditor $projver-$projrev\n";
611print MAIL "DISCID=$ce_cd->{id}\n";
612print MAIL "DTITLE=$ce_cd->{artist} / $ce_cd->{title}\n";
613print MAIL "DYEAR=$ce_cd->{year}\n";
614print MAIL "DGENRE=$ce_cd->{genre}\n";
615$n=0;
616while ( $n < $ce_cd->{tno} ) {
617 print MAIL "TTITLE$n=$ce_cd->{track}[$n]\n";
618 $n++;
619}
620print MAIL "EXTD=\n";
621$n=0;
622while ( $n < $ce_cd->{tno} ) {
623 print MAIL "EXTT$n=\n";
624 $n++;
625}
626print MAIL "PLAYORDER=\n";
627close(MAIL);
628}
629
630sub cddbe_exit {
631
632my $ret = shift;
633close(LOG);
634exit $ret
635}
636
6371;
Note: See TracBrowser for help on using the repository browser.