[840] | 1 | #!/usr/bin/perl -w
|
---|
| 2 | #
|
---|
| 3 | # Reads CDDB info, allow modifications and send back to CDDB server
|
---|
| 4 | #
|
---|
| 5 | # $Id$
|
---|
| 6 | #
|
---|
[2667] | 7 | # Copyright B. Cornec 2009-2021
|
---|
[840] | 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;
|
---|
[2666] | 29 | use perlcdio;
|
---|
[860] | 30 | use File::Copy;
|
---|
| 31 | use File::Basename;
|
---|
[840] | 32 |
|
---|
| 33 | # Global variables
|
---|
| 34 | my %opts; # CLI Options
|
---|
| 35 | my $action; # action to realize
|
---|
| 36 |
|
---|
| 37 | my @date = pb_get_date();
|
---|
| 38 | my $pbdate = strftime("%Y-%m-%d", @date);
|
---|
| 39 |
|
---|
[858] | 40 | pb_temp_init();
|
---|
| 41 |
|
---|
[840] | 42 | =pod
|
---|
| 43 |
|
---|
| 44 | =head1 NAME
|
---|
| 45 |
|
---|
| 46 | CDDBeditor, read, modidy and send your CDDB contrinutions
|
---|
| 47 |
|
---|
| 48 | =head1 DESCRIPTION
|
---|
| 49 |
|
---|
| 50 | CDDBeditor helps you read, modidy and send your CDDB contrinutions.
|
---|
| 51 |
|
---|
| 52 | =head1 SYNOPSIS
|
---|
| 53 |
|
---|
| 54 | CDDBeditor [-vhmq][-t|-g]
|
---|
| 55 |
|
---|
| 56 | CDDBeditor [--verbose][--help][--man][--quiet][--text|--graphic]
|
---|
| 57 |
|
---|
| 58 | =head1 OPTIONS
|
---|
| 59 |
|
---|
| 60 | =over 4
|
---|
| 61 |
|
---|
| 62 | =item B<-v|--verbose>
|
---|
| 63 |
|
---|
| 64 | Print a brief help message and exits.
|
---|
| 65 |
|
---|
| 66 | =item B<-q|--quiet>
|
---|
| 67 |
|
---|
| 68 | Do not print any output.
|
---|
| 69 |
|
---|
| 70 | =item B<-h|--help>
|
---|
| 71 |
|
---|
| 72 | Print a brief help message and exits.
|
---|
| 73 |
|
---|
| 74 | =item B<--man>
|
---|
| 75 |
|
---|
| 76 | Prints the manual page and exits.
|
---|
| 77 |
|
---|
| 78 | =item B<-t|--text>
|
---|
| 79 | =item B<-g|--graphic>
|
---|
| 80 |
|
---|
| 81 | Interface is either text mode or graphical mode (newt based)
|
---|
| 82 |
|
---|
| 83 | =back
|
---|
| 84 |
|
---|
| 85 | =head1 ARGUMENTS
|
---|
| 86 |
|
---|
| 87 | =head1 WEB SITES
|
---|
| 88 |
|
---|
| 89 | 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/>.
|
---|
| 90 |
|
---|
| 91 | =head1 USER MAILING LIST
|
---|
| 92 |
|
---|
| 93 | None exists for the moment.
|
---|
| 94 |
|
---|
| 95 | =head1 CONFIGURATION FILES
|
---|
| 96 |
|
---|
| 97 | =head1 AUTHORS
|
---|
| 98 |
|
---|
| 99 | The CDDBeditor team L<http://trac.project-builder.org/> lead by Bruno Cornec L<mailto:bruno@project-builder.org>.
|
---|
| 100 |
|
---|
| 101 | =head1 COPYRIGHT
|
---|
| 102 |
|
---|
| 103 | CDDBeditor is distributed under the GPL v2.0 license
|
---|
| 104 | described in the file C<COPYING> included with the distribution.
|
---|
| 105 |
|
---|
| 106 | =cut
|
---|
| 107 |
|
---|
| 108 | # ---------------------------------------------------------------------------
|
---|
| 109 |
|
---|
| 110 | #Avoids an error from Newt
|
---|
| 111 | no AutoLoader;
|
---|
| 112 |
|
---|
| 113 |
|
---|
| 114 | # Initialize the syntax string
|
---|
| 115 |
|
---|
| 116 | my $projver = "PBVER";
|
---|
| 117 | my $projrev = "PBREV";
|
---|
| 118 |
|
---|
| 119 | pb_syntax_init("CDDBeditor Version $projver-$projrev\n");
|
---|
| 120 |
|
---|
| 121 | GetOptions("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 |
|
---|
| 130 | if (defined $opts{'h'}) {
|
---|
| 131 | pb_syntax(0,1);
|
---|
| 132 | }
|
---|
| 133 | if (defined $opts{'man'}) {
|
---|
| 134 | pb_syntax(0,2);
|
---|
| 135 | }
|
---|
[1797] | 136 | $pbdebug = 0;
|
---|
[840] | 137 | if (defined $opts{'v'}) {
|
---|
| 138 | $pbdebug = $opts{'v'};
|
---|
| 139 | }
|
---|
| 140 | if (defined $opts{'q'}) {
|
---|
| 141 | $pbdebug=-1;
|
---|
| 142 | }
|
---|
[1650] | 143 | open(LOG, "> $ENV{HOME}/.CDDBeditor.log") || die "Unable to open $ENV{HOME}/.CDDBeditor.log";
|
---|
| 144 | pb_log_init($pbdebug, \*LOG);
|
---|
[840] | 145 |
|
---|
| 146 | Newt::Init();
|
---|
| 147 |
|
---|
| 148 | # String definitions
|
---|
| 149 | my $ce_title = "CDDBeditor";
|
---|
[2667] | 150 | my $ce_help = "(c) Bruno Cornec 2009-2021 - All right reversed under the GPL v2";
|
---|
[840] | 151 | my $artist_label = Newt::Label("Artist: ");
|
---|
[847] | 152 | my $empty_label = Newt::Label(" ");
|
---|
[840] | 153 | my $title_label = Newt::Label("Title: ");
|
---|
| 154 | my $year_label = Newt::Label("Year: ");
|
---|
[860] | 155 | my $id_label = "Id: ";
|
---|
| 156 | my $rev_label = "Revision: ";
|
---|
[840] | 157 | my $genre_label = Newt::Label("Genre: ");
|
---|
| 158 | my $category_label = Newt::Label("Category: ");
|
---|
| 159 | my $info_label = Newt::Label("Info: ");
|
---|
| 160 | my $tr_track_label = Newt::Label("Track");
|
---|
[843] | 161 | my $tr_frames_label = Newt::Label("Frames");
|
---|
[847] | 162 | my $tno_label = Newt::Label("Track #: ");
|
---|
[840] | 163 | my $tr_title_label = Newt::Label("Title");
|
---|
| 164 | my $tr_author_label = Newt::Label("Author");
|
---|
| 165 | my $tr_length_label = Newt::Label("Length");
|
---|
| 166 |
|
---|
| 167 | my $host_label = Newt::Label("Host: ");
|
---|
| 168 | my $port_label = Newt::Label("Port: ");
|
---|
| 169 | my $mode_label = Newt::Label("Mode: ");
|
---|
| 170 | my $dev_label = Newt::Label("Device: ");
|
---|
| 171 | my $proxy_label = Newt::Label("Proxy: ");
|
---|
| 172 |
|
---|
| 173 | my $wait_label = Newt::Label("Please wait while searching ...");
|
---|
| 174 |
|
---|
| 175 | # To be put in conf file
|
---|
| 176 | my %ce_config;
|
---|
[2658] | 177 | $ce_config{"CDDB_HOST"}="freedb.dmz.musique-ancienne.org";
|
---|
[2689] | 178 | $ce_config{"CDDB_USER"}="submit\@gnudb.org";
|
---|
[860] | 179 | $ce_config{"CDDB_CC"}="bruno\@victoria.frmug.org";
|
---|
[2635] | 180 | $ce_config{"CDDB_PORT"}=8000;
|
---|
[855] | 181 | #$ce_config{"CDDB_PORT"}=80;
|
---|
[840] | 182 | my %ce_cddb_mode;
|
---|
[855] | 183 | $ce_cddb_mode{"0"} = "cddb";
|
---|
| 184 | $ce_cddb_mode{"1"} = "http";
|
---|
[840] | 185 |
|
---|
[1641] | 186 | $ce_config{"CDDB_MODE"}=$ce_cddb_mode{"0"};
|
---|
[1004] | 187 | $ce_config{"CD_DEVICE"}="/dev/sr1";
|
---|
[840] | 188 | $ce_config{"HTTP_PROXY"}=$ENV{http_proxy} if $ENV{http_proxy};
|
---|
| 189 | $ce_config{"input"}=0;
|
---|
[1169] | 190 | $ce_config{"multi"}=1;
|
---|
[858] | 191 | $ce_config{"PROTO_VERSION"} = 6;
|
---|
[860] | 192 | $ce_config{"DOMAIN"} = "musique-ancienne.org";
|
---|
| 193 | $ce_config{"USER"} = "bruno";
|
---|
[1650] | 194 | # Requires 4 words exactly
|
---|
[2667] | 195 | $ce_config{"HELLO_ID"} = "$ce_config{\"USER\"} $ce_config{\"DOMAIN\"} CDDBEditor 0.6";
|
---|
[840] | 196 |
|
---|
[2667] | 197 | # Inspired by CDDB.pm
|
---|
[860] | 198 | # Determine whether we can submit changes by e-mail.
|
---|
| 199 |
|
---|
[1175] | 200 | my ($ce_sl, $ce_sh) = Newt::GetScreenSize();
|
---|
| 201 |
|
---|
[840] | 202 | # First panel for configuration parameters
|
---|
| 203 | Newt::Cls();
|
---|
| 204 | Newt::DrawRootText(ce_center_string($ce_title), 1, $ce_title);
|
---|
| 205 | Newt::PushHelpLine($ce_help);
|
---|
| 206 | Newt::Refresh();
|
---|
| 207 |
|
---|
| 208 | my $flag = NEWT_ENTRY_SCROLL;
|
---|
[887] | 209 | # Need 23 char for track and time
|
---|
| 210 | my $width = $ce_sl - 23;
|
---|
[1650] | 211 | # Other fields are limited to 5
|
---|
[887] | 212 | my $width2 = 5;
|
---|
[840] | 213 | my $host_entry = Newt::Entry($width, $flag, $ce_config{"CDDB_HOST"});
|
---|
[887] | 214 | my $port_entry = Newt::Entry($width2, $flag, $ce_config{"CDDB_PORT"});
|
---|
[840] | 215 | my $mode_group;
|
---|
| 216 | my $proxy_entry = undef;
|
---|
[1641] | 217 | if ($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 | }
|
---|
[855] | 222 | if ($ce_config{"CDDB_MODE"} eq "http" ) {
|
---|
[840] | 223 | $proxy_entry = Newt::Entry($width, $flag, $ce_config{"HTTP_PROXY"});
|
---|
| 224 | }
|
---|
| 225 | my $dev_entry = Newt::Entry($width, $flag, $ce_config{"CD_DEVICE"});
|
---|
| 226 | my $user_group;
|
---|
[1641] | 227 | my $next_button = Newt::Button("Next");
|
---|
| 228 | $next_button->Tag("Next");
|
---|
[840] | 229 | my $quit_button = Newt::Button("Quit");
|
---|
| 230 | $quit_button->Tag("Quit");
|
---|
| 231 |
|
---|
| 232 | my $ce_panel = Newt::Panel(2, 20, "CDDBeditor Configuration");
|
---|
[847] | 233 | my $flage = NEWT_ANCHOR_RIGHT;
|
---|
[855] | 234 | $ce_panel->Add(0, 0, $host_label, $flage);
|
---|
[847] | 235 | $flage = NEWT_ANCHOR_LEFT;
|
---|
[844] | 236 | $ce_panel->Add(1, 0, $host_entry, $flage);
|
---|
[847] | 237 | $flage = NEWT_ANCHOR_RIGHT;
|
---|
[855] | 238 | $ce_panel->Add(0, 1, $port_label, $flage);
|
---|
[847] | 239 | $flage = NEWT_ANCHOR_LEFT;
|
---|
[844] | 240 | $ce_panel->Add(1, 1, $port_entry, $flage);
|
---|
[847] | 241 | $flage = NEWT_ANCHOR_RIGHT;
|
---|
[855] | 242 | $ce_panel->Add(0, 2, $mode_label, $flage);
|
---|
[847] | 243 | $flage = NEWT_ANCHOR_LEFT;
|
---|
[844] | 244 | $ce_panel->Add(1, 2, $mode_group, $flage);
|
---|
[855] | 245 | if ($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 | }
|
---|
[847] | 251 | $flage = NEWT_ANCHOR_RIGHT;
|
---|
[855] | 252 | $ce_panel->Add(0, 4, $dev_label, $flage);
|
---|
[847] | 253 | $flage = NEWT_ANCHOR_LEFT;
|
---|
[844] | 254 | $ce_panel->Add(1, 4, $dev_entry, $flage);
|
---|
[847] | 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);
|
---|
[840] | 259 |
|
---|
[844] | 260 | Newt::Refresh();
|
---|
[840] | 261 | my ($reason, $data) = $ce_panel->Run();
|
---|
[844] | 262 |
|
---|
[840] | 263 | Newt::Cls();
|
---|
[1650] | 264 | cddbe_exit(0) if ($data->Tag() eq "Quit");
|
---|
[840] | 265 |
|
---|
[855] | 266 | if ($ce_config{"CDDB_MODE"} eq "http" ) {
|
---|
| 267 | $ce_config{"HTTP_PROXY"}=$proxy_entry->Get();
|
---|
| 268 | }
|
---|
[840] | 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 |
|
---|
[1650] | 274 | pb_log(1,"After first screen\n");
|
---|
| 275 | pb_log(1,"ce_config is:\n");
|
---|
| 276 | pb_log(1,Dumper(%ce_config)."\n");
|
---|
| 277 |
|
---|
[840] | 278 | # Components
|
---|
| 279 | my $reload_button = Newt::Button("Reload");
|
---|
| 280 | $reload_button->Tag("Reload");
|
---|
| 281 | my $send_button = Newt::Button("Send");
|
---|
| 282 | $send_button->Tag("Send");
|
---|
| 283 |
|
---|
[860] | 284 | my $firsttime = 1;
|
---|
[1169] | 285 | my @cecd;
|
---|
[860] | 286 | my $ce_cd;
|
---|
| 287 | my $artist_entry;
|
---|
| 288 | my $title_entry;
|
---|
| 289 | my $category_entry;
|
---|
| 290 | my $genre_entry;
|
---|
| 291 | my $tno_entry;
|
---|
| 292 | my $year_entry;
|
---|
| 293 | my @track_entry;
|
---|
| 294 |
|
---|
[840] | 295 | # Entering the loop
|
---|
[1650] | 296 | for (my $i=0 ; ; $i++) { # Second panel to make user wait
|
---|
[844] | 297 | Newt::Cls();
|
---|
[840] | 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);
|
---|
[844] | 302 |
|
---|
[846] | 303 | ($reason, $data) = $ce_panel->Draw();
|
---|
[844] | 304 | Newt::Refresh();
|
---|
[840] | 305 |
|
---|
[860] | 306 | # CDDB query if first time
|
---|
[864] | 307 | if ($firsttime == 1) {
|
---|
[1169] | 308 | @cecd = get_cddb(\%ce_config);
|
---|
| 309 | # by default use first one
|
---|
[1170] | 310 | $ce_cd = $cecd[0] if (defined $cecd[0]);
|
---|
[1650] | 311 | pb_log(1,"After get_cddb\n");
|
---|
| 312 | pb_log(1,"cecd is:\n");
|
---|
| 313 | pb_log(1,Dumper(@cecd)."\n");
|
---|
[860] | 314 | }
|
---|
| 315 | $firsttime = 0;
|
---|
[840] | 316 |
|
---|
[1169] | 317 | my @vradio;
|
---|
| 318 | my $ind = 0;
|
---|
| 319 | foreach my $entry (@cecd) {
|
---|
[1170] | 320 | my $cat = "";
|
---|
[1923] | 321 | my $tno = 1;
|
---|
[1170] | 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});
|
---|
[1563] | 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);
|
---|
[1169] | 329 | $ind++;
|
---|
| 330 | }
|
---|
[1650] | 331 | pb_log(1,"ind is: $ind\n");
|
---|
[1169] | 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();
|
---|
[1650] | 358 | cddbe_exit(0) if ($data->Tag() eq "Quit");
|
---|
[1169] | 359 |
|
---|
| 360 | $ind=$user_group->Get();
|
---|
[1650] | 361 | } else {
|
---|
| 362 | # if only one CD, back to its number which is 0
|
---|
| 363 | $ind--;
|
---|
[1169] | 364 | }
|
---|
[2666] | 365 |
|
---|
[1169] | 366 | # Point now to the right CD
|
---|
[1638] | 367 | $ce_cd = $cecd[$ind];
|
---|
[1650] | 368 | pb_log(1,"After CD choice\n");
|
---|
| 369 | pb_log(1,"ce_cd is: \n");
|
---|
| 370 | pb_log(1,Dumper($ce_cd)."\n");
|
---|
[1169] | 371 |
|
---|
[860] | 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 |
|
---|
[1650] | 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");
|
---|
[860] | 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();
|
---|
[2666] | 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);
|
---|
[860] | 419 | $ce_cd->{tno} = $track->{track};
|
---|
| 420 | my $n = 0;
|
---|
| 421 |
|
---|
[2666] | 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});
|
---|
[860] | 424 | $ce_cd->{artist} = "" if (not defined $ce_cd->{artist});
|
---|
[2666] | 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});
|
---|
[860] | 427 | $ce_cd->{title} = "" if (not defined $ce_cd->{title});
|
---|
[2666] | 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});
|
---|
[860] | 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
|
---|
[2666] | 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 | }
|
---|
[860] | 447 | my ($m, $s, $f) = split(/:/,$track->get_msf());
|
---|
| 448 | $ce_cd->{frames}[$n] = $f + 75*$s + 75*60*$m;
|
---|
| 449 | $n++;
|
---|
| 450 | }
|
---|
| 451 | }
|
---|
[858] | 452 | # Modify enconding of some fields if proto < 5
|
---|
[860] | 453 | #$ce_cd->{artist} = decode("iso8859-1",$ce_cd->{artist});
|
---|
| 454 | #$ce_cd->{title} = decode("iso8859-1",$ce_cd->{title});
|
---|
[846] | 455 |
|
---|
[840] | 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;
|
---|
[860] | 462 | $artist_entry = Newt::Entry($width, $flag, $ce_cd->{artist});
|
---|
| 463 | $title_entry = Newt::Entry($width, $flag, $ce_cd->{title});
|
---|
[855] | 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
|
---|
[860] | 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});
|
---|
[887] | 469 | $year_entry = Newt::Entry($width2, $flag, $ce_cd->{year});
|
---|
[840] | 470 |
|
---|
| 471 | # Build interface
|
---|
[1170] | 472 | ($ce_sl, $ce_sh) = Newt::GetScreenSize();
|
---|
[860] | 473 | $ce_panel = Newt::Panel(4, $ce_sh, "CDDB Info");
|
---|
[847] | 474 | $flage = NEWT_ANCHOR_RIGHT;
|
---|
| 475 | $ce_panel->Add(0, 0, $artist_label,$flage);
|
---|
| 476 | $flage = NEWT_ANCHOR_LEFT;
|
---|
[844] | 477 | $ce_panel->Add(1, 0, $artist_entry, $flage);
|
---|
[847] | 478 | $flage = NEWT_ANCHOR_RIGHT;
|
---|
| 479 | $ce_panel->Add(0, 1, $title_label,$flage);
|
---|
| 480 | $flage = NEWT_ANCHOR_LEFT;
|
---|
[844] | 481 | $ce_panel->Add(1, 1, $title_entry, $flage);
|
---|
[847] | 482 | $flage = NEWT_ANCHOR_RIGHT;
|
---|
| 483 | $ce_panel->Add(0, 2, $year_label,$flage);
|
---|
| 484 | $flage = NEWT_ANCHOR_LEFT;
|
---|
[844] | 485 | $ce_panel->Add(1, 2, $year_entry, $flage);
|
---|
[847] | 486 | $flage = NEWT_ANCHOR_RIGHT;
|
---|
| 487 | $ce_panel->Add(0, 3, $category_label,$flage);
|
---|
| 488 | $flage = NEWT_ANCHOR_LEFT;
|
---|
[844] | 489 | $ce_panel->Add(1, 3, $category_entry, $flage);
|
---|
[847] | 490 | $flage = NEWT_ANCHOR_RIGHT;
|
---|
| 491 | $ce_panel->Add(0, 4, $genre_label,$flage);
|
---|
| 492 | $flage = NEWT_ANCHOR_LEFT;
|
---|
[844] | 493 | $ce_panel->Add(1, 4, $genre_entry, $flage);
|
---|
[847] | 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);
|
---|
[843] | 498 |
|
---|
[860] | 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;
|
---|
[843] | 504 | my $dur=$to-$from;
|
---|
| 505 | my $min=int($dur/75/60);
|
---|
| 506 | my $sec=int($dur/75)-$min*60;
|
---|
[1745] | 507 | my $tr = sprintf "Track %2d: ", $n+1;
|
---|
[843] | 508 | my $track_label = Newt::Label($tr);
|
---|
[844] | 509 | $tr = sprintf " %2d':%.2d", $min, $sec;
|
---|
[858] | 510 | # Adapt encoding of track if proto < 5
|
---|
[860] | 511 | #$ce_cd->{track}[$n] = decode("iso8859-1",$ce_cd->{track}[$n]);
|
---|
[858] | 512 |
|
---|
[843] | 513 | my $dur_label = Newt::Label($tr);
|
---|
| 514 | $flag = NEWT_FLAG_WRAP|NEWT_ENTRY_SCROLL;
|
---|
[860] | 515 | $track_entry[$n] = Newt::Entry($width, $flag, $ce_cd->{track}[$n]);
|
---|
[1744] | 516 | $flage = NEWT_ANCHOR_RIGHT;
|
---|
| 517 | $ce_panel->Add(0, 9+$n, $track_label,$flage);
|
---|
| 518 | $flage = NEWT_ANCHOR_LEFT;
|
---|
[860] | 519 | $ce_panel->Add(1, 9+$n, $track_entry[$n], $flage);
|
---|
| 520 | $ce_panel->Add(2, 9+$n, $dur_label, $flage);
|
---|
[843] | 521 | $n++;
|
---|
[860] | 522 | }
|
---|
| 523 | $ce_panel->Add(0, 9+$n, $empty_label);
|
---|
[843] | 524 |
|
---|
[1744] | 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);
|
---|
[840] | 536 |
|
---|
[844] | 537 | Newt::Cls();
|
---|
| 538 | Newt::Refresh();
|
---|
[860] | 539 |
|
---|
[840] | 540 | # Build interface
|
---|
| 541 | ($reason, $data) = $ce_panel->Run();
|
---|
[843] | 542 |
|
---|
[860] | 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 | }
|
---|
[840] | 553 | Newt::Refresh();
|
---|
| 554 | Newt::Cls();
|
---|
[1650] | 555 | cddbe_exit(0) if ($data->Tag() eq "Quit");
|
---|
[1744] | 556 | system("eject ".$ce_config{"CD_DEVICE"}) if ($data->Tag() eq "Eject");
|
---|
[840] | 557 |
|
---|
[1650] | 558 | pb_log(1,"Before sending\n");
|
---|
| 559 | pb_log(1,"ce_cd is:\n");
|
---|
| 560 | pb_log(1,Dumper($ce_cd)."\n");
|
---|
| 561 |
|
---|
[840] | 562 | # Send the data
|
---|
| 563 | if ($data->Tag() eq "Send") {
|
---|
| 564 | $flag = NEWT_FLAG_WRAP;
|
---|
[860] | 565 | my $height = 10;
|
---|
[840] | 566 |
|
---|
| 567 | Newt::DrawRootText(ce_center_string($ce_title), 1, $ce_title);
|
---|
| 568 | Newt::PushHelpLine($ce_help);
|
---|
| 569 |
|
---|
[860] | 570 | my $txt = "Please wait while sending disc $ce_cd->{id} ($ce_cd->{cat}) to $ce_config{\"CDDB_USER\"}";
|
---|
[858] | 571 | my $info_tb = Newt::Textbox($width, $height, $flag, $txt);
|
---|
| 572 |
|
---|
[844] | 573 | Newt::Cls();
|
---|
[840] | 574 | $ce_panel = Newt::Panel(3, $width, "CDDB Sending Infos");
|
---|
[860] | 575 | $ce_panel->Add(0, 0, $info_tb);
|
---|
| 576 | $ce_panel->Add(0, 1, $quit_button);
|
---|
[844] | 577 | Newt::Refresh();
|
---|
[860] | 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");
|
---|
[840] | 581 | ($reason, $data) = $ce_panel->Run();
|
---|
[860] | 582 |
|
---|
| 583 | # Force reloading info from cache
|
---|
| 584 | $ce_cd->{title} = undef;
|
---|
[840] | 585 | }
|
---|
[860] | 586 | if ($data->Tag() eq "Reload") {
|
---|
| 587 | # Then force CDDB query
|
---|
| 588 | $firsttime = 1;
|
---|
| 589 | }
|
---|
[840] | 590 | }
|
---|
| 591 | Newt::Finished();
|
---|
[1650] | 592 | cddbe_exit(0);
|
---|
[840] | 593 |
|
---|
| 594 | # return the char to start printing a centered string based on screen size
|
---|
| 595 | sub 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 |
|
---|
[858] | 607 | sub ce_prepare_mail() {
|
---|
| 608 |
|
---|
| 609 | my $ce_cd = shift;
|
---|
| 610 |
|
---|
[860] | 611 | pb_mkdir_p("$ENV{'HOME'}/.cddb/$ce_cd->{cat}");
|
---|
| 612 | 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] | 613 | print MAIL "# xmcd CD database file\n#\n# Track frame offsets:\n";
|
---|
[860] | 614 | my $n=0;
|
---|
| 615 | while ( $n < $ce_cd->{tno} ) {
|
---|
| 616 | print MAIL "# ".$ce_cd->{frames}[$n]."\n";
|
---|
[858] | 617 | $n++;
|
---|
| 618 | }
|
---|
[860] | 619 | #my $from=int($ce_cd->{frames}[0]/75);
|
---|
| 620 | my $sec=int($ce_cd->{frames}[$ce_cd->{tno}]/75);
|
---|
| 621 | #my $sec=$to-$from;
|
---|
[858] | 622 | my $rev = $ce_cd->{revision} + 1;
|
---|
[860] | 623 | # Taken from CDDB.pm
|
---|
[858] | 624 | print MAIL "#\n# Disc length: $sec seconds\n#\n";
|
---|
| 625 | print MAIL "# Revision: $rev\n";
|
---|
| 626 | print MAIL "# Processed by: cddbd v1.5PL3 Copyright (c) Steve Scherf et al.\n";
|
---|
| 627 | print MAIL "# Submitted via: CDDBEditor $projver-$projrev\n";
|
---|
| 628 | print MAIL "DISCID=$ce_cd->{id}\n";
|
---|
[860] | 629 | print MAIL "DTITLE=$ce_cd->{artist} / $ce_cd->{title}\n";
|
---|
[858] | 630 | print MAIL "DYEAR=$ce_cd->{year}\n";
|
---|
| 631 | print MAIL "DGENRE=$ce_cd->{genre}\n";
|
---|
[860] | 632 | $n=0;
|
---|
| 633 | while ( $n < $ce_cd->{tno} ) {
|
---|
| 634 | print MAIL "TTITLE$n=$ce_cd->{track}[$n]\n";
|
---|
[858] | 635 | $n++;
|
---|
| 636 | }
|
---|
| 637 | print MAIL "EXTD=\n";
|
---|
[860] | 638 | $n=0;
|
---|
| 639 | while ( $n < $ce_cd->{tno} ) {
|
---|
[858] | 640 | print MAIL "EXTT$n=\n";
|
---|
| 641 | $n++;
|
---|
| 642 | }
|
---|
| 643 | print MAIL "PLAYORDER=\n";
|
---|
| 644 | close(MAIL);
|
---|
| 645 | }
|
---|
| 646 |
|
---|
[1650] | 647 | sub cddbe_exit {
|
---|
| 648 |
|
---|
| 649 | my $ret = shift;
|
---|
| 650 | close(LOG);
|
---|
| 651 | exit $ret
|
---|
| 652 | }
|
---|
| 653 |
|
---|
[840] | 654 | 1;
|
---|