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