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