[840] | 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);
|
---|
[847] | 20 | use Newt qw(NEWT_FLAG_WRAP NEWT_ENTRY_SCROLL NEWT_ANCHOR_LEFT NEWT_ANCHOR_RIGHT :entry :textbox :macros);
|
---|
[840] | 21 | use lib qw (lib);
|
---|
| 22 | use locale;
|
---|
[1650] | 23 | # >= 2.27
|
---|
[840] | 24 | use CDDB_get qw( get_cddb get_discids );
|
---|
[846] | 25 | use Encode;
|
---|
[860] | 26 | #use Linux::CDROM;
|
---|
| 27 | use Device::Cdio::Device;
|
---|
| 28 | use Device::Cdio::Track;
|
---|
| 29 | use File::Copy;
|
---|
| 30 | use File::Basename;
|
---|
[840] | 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 |
|
---|
[858] | 39 | pb_temp_init();
|
---|
| 40 |
|
---|
[840] | 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 | }
|
---|
[1797] | 135 | $pbdebug = 0;
|
---|
[840] | 136 | if (defined $opts{'v'}) {
|
---|
| 137 | $pbdebug = $opts{'v'};
|
---|
| 138 | }
|
---|
| 139 | if (defined $opts{'q'}) {
|
---|
| 140 | $pbdebug=-1;
|
---|
| 141 | }
|
---|
[1650] | 142 | open(LOG, "> $ENV{HOME}/.CDDBeditor.log") || die "Unable to open $ENV{HOME}/.CDDBeditor.log";
|
---|
| 143 | pb_log_init($pbdebug, \*LOG);
|
---|
[840] | 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: ");
|
---|
[847] | 151 | my $empty_label = Newt::Label(" ");
|
---|
[840] | 152 | my $title_label = Newt::Label("Title: ");
|
---|
| 153 | my $year_label = Newt::Label("Year: ");
|
---|
[860] | 154 | my $id_label = "Id: ";
|
---|
| 155 | my $rev_label = "Revision: ";
|
---|
[840] | 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");
|
---|
[843] | 160 | my $tr_frames_label = Newt::Label("Frames");
|
---|
[847] | 161 | my $tno_label = Newt::Label("Track #: ");
|
---|
[840] | 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";
|
---|
[860] | 177 | $ce_config{"CDDB_USER"}="freedb-submit\@freedb.org";
|
---|
| 178 | $ce_config{"CDDB_CC"}="bruno\@victoria.frmug.org";
|
---|
[855] | 179 | $ce_config{"CDDB_PORT"}=888;
|
---|
| 180 | #$ce_config{"CDDB_PORT"}=80;
|
---|
[840] | 181 | my %ce_cddb_mode;
|
---|
[855] | 182 | $ce_cddb_mode{"0"} = "cddb";
|
---|
| 183 | $ce_cddb_mode{"1"} = "http";
|
---|
[840] | 184 |
|
---|
[1641] | 185 | $ce_config{"CDDB_MODE"}=$ce_cddb_mode{"0"};
|
---|
[1004] | 186 | $ce_config{"CD_DEVICE"}="/dev/sr1";
|
---|
[840] | 187 | $ce_config{"HTTP_PROXY"}=$ENV{http_proxy} if $ENV{http_proxy};
|
---|
| 188 | $ce_config{"input"}=0;
|
---|
[1169] | 189 | $ce_config{"multi"}=1;
|
---|
[858] | 190 | $ce_config{"PROTO_VERSION"} = 6;
|
---|
[860] | 191 | $ce_config{"DOMAIN"} = "musique-ancienne.org";
|
---|
| 192 | $ce_config{"USER"} = "bruno";
|
---|
[1650] | 193 | # Requires 4 words exactly
|
---|
| 194 | $ce_config{"HELLO_ID"} = "$ce_config{\"USER\"} $ce_config{\"DOMAIN\"} CDDBEditor 0.5";
|
---|
[840] | 195 |
|
---|
[860] | 196 | # Copied from CDDB.pm
|
---|
| 197 | # Determine whether we can submit changes by e-mail.
|
---|
| 198 |
|
---|
[1175] | 199 | my ($ce_sl, $ce_sh) = Newt::GetScreenSize();
|
---|
| 200 |
|
---|
[840] | 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;
|
---|
[887] | 208 | # Need 23 char for track and time
|
---|
| 209 | my $width = $ce_sl - 23;
|
---|
[1650] | 210 | # Other fields are limited to 5
|
---|
[887] | 211 | my $width2 = 5;
|
---|
[840] | 212 | my $host_entry = Newt::Entry($width, $flag, $ce_config{"CDDB_HOST"});
|
---|
[887] | 213 | my $port_entry = Newt::Entry($width2, $flag, $ce_config{"CDDB_PORT"});
|
---|
[840] | 214 | my $mode_group;
|
---|
| 215 | my $proxy_entry = undef;
|
---|
[1641] | 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 | }
|
---|
[855] | 221 | if ($ce_config{"CDDB_MODE"} eq "http" ) {
|
---|
[840] | 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;
|
---|
[1641] | 226 | my $next_button = Newt::Button("Next");
|
---|
| 227 | $next_button->Tag("Next");
|
---|
[840] | 228 | my $quit_button = Newt::Button("Quit");
|
---|
| 229 | $quit_button->Tag("Quit");
|
---|
| 230 |
|
---|
| 231 | my $ce_panel = Newt::Panel(2, 20, "CDDBeditor Configuration");
|
---|
[847] | 232 | my $flage = NEWT_ANCHOR_RIGHT;
|
---|
[855] | 233 | $ce_panel->Add(0, 0, $host_label, $flage);
|
---|
[847] | 234 | $flage = NEWT_ANCHOR_LEFT;
|
---|
[844] | 235 | $ce_panel->Add(1, 0, $host_entry, $flage);
|
---|
[847] | 236 | $flage = NEWT_ANCHOR_RIGHT;
|
---|
[855] | 237 | $ce_panel->Add(0, 1, $port_label, $flage);
|
---|
[847] | 238 | $flage = NEWT_ANCHOR_LEFT;
|
---|
[844] | 239 | $ce_panel->Add(1, 1, $port_entry, $flage);
|
---|
[847] | 240 | $flage = NEWT_ANCHOR_RIGHT;
|
---|
[855] | 241 | $ce_panel->Add(0, 2, $mode_label, $flage);
|
---|
[847] | 242 | $flage = NEWT_ANCHOR_LEFT;
|
---|
[844] | 243 | $ce_panel->Add(1, 2, $mode_group, $flage);
|
---|
[855] | 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 | }
|
---|
[847] | 250 | $flage = NEWT_ANCHOR_RIGHT;
|
---|
[855] | 251 | $ce_panel->Add(0, 4, $dev_label, $flage);
|
---|
[847] | 252 | $flage = NEWT_ANCHOR_LEFT;
|
---|
[844] | 253 | $ce_panel->Add(1, 4, $dev_entry, $flage);
|
---|
[847] | 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);
|
---|
[840] | 258 |
|
---|
[844] | 259 | Newt::Refresh();
|
---|
[840] | 260 | my ($reason, $data) = $ce_panel->Run();
|
---|
[844] | 261 |
|
---|
[840] | 262 | Newt::Cls();
|
---|
[1650] | 263 | cddbe_exit(0) if ($data->Tag() eq "Quit");
|
---|
[840] | 264 |
|
---|
[855] | 265 | if ($ce_config{"CDDB_MODE"} eq "http" ) {
|
---|
| 266 | $ce_config{"HTTP_PROXY"}=$proxy_entry->Get();
|
---|
| 267 | }
|
---|
[840] | 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 |
|
---|
[1650] | 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 |
|
---|
[840] | 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 |
|
---|
[860] | 283 | my $firsttime = 1;
|
---|
[1169] | 284 | my @cecd;
|
---|
[860] | 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 |
|
---|
[840] | 294 | # Entering the loop
|
---|
[1650] | 295 | for (my $i=0 ; ; $i++) { # Second panel to make user wait
|
---|
[844] | 296 | Newt::Cls();
|
---|
[840] | 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);
|
---|
[844] | 301 |
|
---|
[846] | 302 | ($reason, $data) = $ce_panel->Draw();
|
---|
[844] | 303 | Newt::Refresh();
|
---|
[840] | 304 |
|
---|
[860] | 305 | # CDDB query if first time
|
---|
[864] | 306 | if ($firsttime == 1) {
|
---|
[1169] | 307 | @cecd = get_cddb(\%ce_config);
|
---|
| 308 | # by default use first one
|
---|
[1170] | 309 | $ce_cd = $cecd[0] if (defined $cecd[0]);
|
---|
[1650] | 310 | pb_log(1,"After get_cddb\n");
|
---|
| 311 | pb_log(1,"cecd is:\n");
|
---|
| 312 | pb_log(1,Dumper(@cecd)."\n");
|
---|
[860] | 313 | }
|
---|
| 314 | $firsttime = 0;
|
---|
[840] | 315 |
|
---|
[1169] | 316 | my @vradio;
|
---|
| 317 | my $ind = 0;
|
---|
| 318 | foreach my $entry (@cecd) {
|
---|
[1170] | 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});
|
---|
[1563] | 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);
|
---|
[1169] | 328 | $ind++;
|
---|
| 329 | }
|
---|
[1650] | 330 | pb_log(1,"ind is: $ind\n");
|
---|
[1169] | 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();
|
---|
[1650] | 357 | cddbe_exit(0) if ($data->Tag() eq "Quit");
|
---|
[1169] | 358 |
|
---|
| 359 | $ind=$user_group->Get();
|
---|
[1650] | 360 | } else {
|
---|
| 361 | # if only one CD, back to its number which is 0
|
---|
| 362 | $ind--;
|
---|
[1169] | 363 | }
|
---|
| 364 | # Point now to the right CD
|
---|
[1638] | 365 | $ce_cd = $cecd[$ind];
|
---|
[1650] | 366 | pb_log(1,"After CD choice\n");
|
---|
| 367 | pb_log(1,"ce_cd is: \n");
|
---|
| 368 | pb_log(1,Dumper($ce_cd)."\n");
|
---|
[1169] | 369 |
|
---|
[860] | 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 |
|
---|
[1650] | 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");
|
---|
[860] | 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 | }
|
---|
[858] | 436 | # Modify enconding of some fields if proto < 5
|
---|
[860] | 437 | #$ce_cd->{artist} = decode("iso8859-1",$ce_cd->{artist});
|
---|
| 438 | #$ce_cd->{title} = decode("iso8859-1",$ce_cd->{title});
|
---|
[846] | 439 |
|
---|
[840] | 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;
|
---|
[860] | 446 | $artist_entry = Newt::Entry($width, $flag, $ce_cd->{artist});
|
---|
| 447 | $title_entry = Newt::Entry($width, $flag, $ce_cd->{title});
|
---|
[855] | 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
|
---|
[860] | 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});
|
---|
[887] | 453 | $year_entry = Newt::Entry($width2, $flag, $ce_cd->{year});
|
---|
[840] | 454 |
|
---|
| 455 | # Build interface
|
---|
[1170] | 456 | ($ce_sl, $ce_sh) = Newt::GetScreenSize();
|
---|
[860] | 457 | $ce_panel = Newt::Panel(4, $ce_sh, "CDDB Info");
|
---|
[847] | 458 | $flage = NEWT_ANCHOR_RIGHT;
|
---|
| 459 | $ce_panel->Add(0, 0, $artist_label,$flage);
|
---|
| 460 | $flage = NEWT_ANCHOR_LEFT;
|
---|
[844] | 461 | $ce_panel->Add(1, 0, $artist_entry, $flage);
|
---|
[847] | 462 | $flage = NEWT_ANCHOR_RIGHT;
|
---|
| 463 | $ce_panel->Add(0, 1, $title_label,$flage);
|
---|
| 464 | $flage = NEWT_ANCHOR_LEFT;
|
---|
[844] | 465 | $ce_panel->Add(1, 1, $title_entry, $flage);
|
---|
[847] | 466 | $flage = NEWT_ANCHOR_RIGHT;
|
---|
| 467 | $ce_panel->Add(0, 2, $year_label,$flage);
|
---|
| 468 | $flage = NEWT_ANCHOR_LEFT;
|
---|
[844] | 469 | $ce_panel->Add(1, 2, $year_entry, $flage);
|
---|
[847] | 470 | $flage = NEWT_ANCHOR_RIGHT;
|
---|
| 471 | $ce_panel->Add(0, 3, $category_label,$flage);
|
---|
| 472 | $flage = NEWT_ANCHOR_LEFT;
|
---|
[844] | 473 | $ce_panel->Add(1, 3, $category_entry, $flage);
|
---|
[847] | 474 | $flage = NEWT_ANCHOR_RIGHT;
|
---|
| 475 | $ce_panel->Add(0, 4, $genre_label,$flage);
|
---|
| 476 | $flage = NEWT_ANCHOR_LEFT;
|
---|
[844] | 477 | $ce_panel->Add(1, 4, $genre_entry, $flage);
|
---|
[847] | 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);
|
---|
[843] | 482 |
|
---|
[860] | 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;
|
---|
[843] | 488 | my $dur=$to-$from;
|
---|
| 489 | my $min=int($dur/75/60);
|
---|
| 490 | my $sec=int($dur/75)-$min*60;
|
---|
[1745] | 491 | my $tr = sprintf "Track %2d: ", $n+1;
|
---|
[843] | 492 | my $track_label = Newt::Label($tr);
|
---|
[844] | 493 | $tr = sprintf " %2d':%.2d", $min, $sec;
|
---|
[858] | 494 | # Adapt encoding of track if proto < 5
|
---|
[860] | 495 | #$ce_cd->{track}[$n] = decode("iso8859-1",$ce_cd->{track}[$n]);
|
---|
[858] | 496 |
|
---|
[843] | 497 | my $dur_label = Newt::Label($tr);
|
---|
| 498 | $flag = NEWT_FLAG_WRAP|NEWT_ENTRY_SCROLL;
|
---|
[860] | 499 | $track_entry[$n] = Newt::Entry($width, $flag, $ce_cd->{track}[$n]);
|
---|
[1744] | 500 | $flage = NEWT_ANCHOR_RIGHT;
|
---|
| 501 | $ce_panel->Add(0, 9+$n, $track_label,$flage);
|
---|
| 502 | $flage = NEWT_ANCHOR_LEFT;
|
---|
[860] | 503 | $ce_panel->Add(1, 9+$n, $track_entry[$n], $flage);
|
---|
| 504 | $ce_panel->Add(2, 9+$n, $dur_label, $flage);
|
---|
[843] | 505 | $n++;
|
---|
[860] | 506 | }
|
---|
| 507 | $ce_panel->Add(0, 9+$n, $empty_label);
|
---|
[843] | 508 |
|
---|
[1744] | 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);
|
---|
[840] | 520 |
|
---|
[844] | 521 | Newt::Cls();
|
---|
| 522 | Newt::Refresh();
|
---|
[860] | 523 |
|
---|
[840] | 524 | # Build interface
|
---|
| 525 | ($reason, $data) = $ce_panel->Run();
|
---|
[843] | 526 |
|
---|
[860] | 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 | }
|
---|
[840] | 537 | Newt::Refresh();
|
---|
| 538 | Newt::Cls();
|
---|
[1650] | 539 | cddbe_exit(0) if ($data->Tag() eq "Quit");
|
---|
[1744] | 540 | system("eject ".$ce_config{"CD_DEVICE"}) if ($data->Tag() eq "Eject");
|
---|
[840] | 541 |
|
---|
[1650] | 542 | pb_log(1,"Before sending\n");
|
---|
| 543 | pb_log(1,"ce_cd is:\n");
|
---|
| 544 | pb_log(1,Dumper($ce_cd)."\n");
|
---|
| 545 |
|
---|
[840] | 546 | # Send the data
|
---|
| 547 | if ($data->Tag() eq "Send") {
|
---|
| 548 | $flag = NEWT_FLAG_WRAP;
|
---|
[860] | 549 | my $height = 10;
|
---|
[840] | 550 |
|
---|
| 551 | Newt::DrawRootText(ce_center_string($ce_title), 1, $ce_title);
|
---|
| 552 | Newt::PushHelpLine($ce_help);
|
---|
| 553 |
|
---|
[860] | 554 | my $txt = "Please wait while sending disc $ce_cd->{id} ($ce_cd->{cat}) to $ce_config{\"CDDB_USER\"}";
|
---|
[858] | 555 | my $info_tb = Newt::Textbox($width, $height, $flag, $txt);
|
---|
| 556 |
|
---|
[844] | 557 | Newt::Cls();
|
---|
[840] | 558 | $ce_panel = Newt::Panel(3, $width, "CDDB Sending Infos");
|
---|
[860] | 559 | $ce_panel->Add(0, 0, $info_tb);
|
---|
| 560 | $ce_panel->Add(0, 1, $quit_button);
|
---|
[844] | 561 | Newt::Refresh();
|
---|
[860] | 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");
|
---|
[840] | 565 | ($reason, $data) = $ce_panel->Run();
|
---|
[860] | 566 |
|
---|
| 567 | # Force reloading info from cache
|
---|
| 568 | $ce_cd->{title} = undef;
|
---|
[840] | 569 | }
|
---|
[860] | 570 | if ($data->Tag() eq "Reload") {
|
---|
| 571 | # Then force CDDB query
|
---|
| 572 | $firsttime = 1;
|
---|
| 573 | }
|
---|
[840] | 574 | }
|
---|
| 575 | Newt::Finished();
|
---|
[1650] | 576 | cddbe_exit(0);
|
---|
[840] | 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 |
|
---|
[858] | 591 | sub ce_prepare_mail() {
|
---|
| 592 |
|
---|
| 593 | my $ce_cd = shift;
|
---|
| 594 |
|
---|
[860] | 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}";
|
---|
[858] | 597 | print MAIL "# xmcd CD database file\n#\n# Track frame offsets:\n";
|
---|
[860] | 598 | my $n=0;
|
---|
| 599 | while ( $n < $ce_cd->{tno} ) {
|
---|
| 600 | print MAIL "# ".$ce_cd->{frames}[$n]."\n";
|
---|
[858] | 601 | $n++;
|
---|
| 602 | }
|
---|
[860] | 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;
|
---|
[858] | 606 | my $rev = $ce_cd->{revision} + 1;
|
---|
[860] | 607 | # Taken from CDDB.pm
|
---|
[858] | 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";
|
---|
[860] | 613 | print MAIL "DTITLE=$ce_cd->{artist} / $ce_cd->{title}\n";
|
---|
[858] | 614 | print MAIL "DYEAR=$ce_cd->{year}\n";
|
---|
| 615 | print MAIL "DGENRE=$ce_cd->{genre}\n";
|
---|
[860] | 616 | $n=0;
|
---|
| 617 | while ( $n < $ce_cd->{tno} ) {
|
---|
| 618 | print MAIL "TTITLE$n=$ce_cd->{track}[$n]\n";
|
---|
[858] | 619 | $n++;
|
---|
| 620 | }
|
---|
| 621 | print MAIL "EXTD=\n";
|
---|
[860] | 622 | $n=0;
|
---|
| 623 | while ( $n < $ce_cd->{tno} ) {
|
---|
[858] | 624 | print MAIL "EXTT$n=\n";
|
---|
| 625 | $n++;
|
---|
| 626 | }
|
---|
| 627 | print MAIL "PLAYORDER=\n";
|
---|
| 628 | close(MAIL);
|
---|
| 629 | }
|
---|
| 630 |
|
---|
[1650] | 631 | sub cddbe_exit {
|
---|
| 632 |
|
---|
| 633 | my $ret = shift;
|
---|
| 634 | close(LOG);
|
---|
| 635 | exit $ret
|
---|
| 636 | }
|
---|
| 637 |
|
---|
[840] | 638 | 1;
|
---|