[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;
|
---|
[840] | 26 |
|
---|
| 27 | # Global variables
|
---|
| 28 | my %opts; # CLI Options
|
---|
| 29 | my $action; # action to realize
|
---|
| 30 |
|
---|
| 31 | my @date = pb_get_date();
|
---|
| 32 | my $pbdate = strftime("%Y-%m-%d", @date);
|
---|
| 33 |
|
---|
[858] | 34 | pb_temp_init();
|
---|
| 35 |
|
---|
[840] | 36 | =pod
|
---|
| 37 |
|
---|
| 38 | =head1 NAME
|
---|
| 39 |
|
---|
| 40 | CDDBeditor, read, modidy and send your CDDB contrinutions
|
---|
| 41 |
|
---|
| 42 | =head1 DESCRIPTION
|
---|
| 43 |
|
---|
| 44 | CDDBeditor helps you read, modidy and send your CDDB contrinutions.
|
---|
| 45 |
|
---|
| 46 | =head1 SYNOPSIS
|
---|
| 47 |
|
---|
| 48 | CDDBeditor [-vhmq][-t|-g]
|
---|
| 49 |
|
---|
| 50 | CDDBeditor [--verbose][--help][--man][--quiet][--text|--graphic]
|
---|
| 51 |
|
---|
| 52 | =head1 OPTIONS
|
---|
| 53 |
|
---|
| 54 | =over 4
|
---|
| 55 |
|
---|
| 56 | =item B<-v|--verbose>
|
---|
| 57 |
|
---|
| 58 | Print a brief help message and exits.
|
---|
| 59 |
|
---|
| 60 | =item B<-q|--quiet>
|
---|
| 61 |
|
---|
| 62 | Do not print any output.
|
---|
| 63 |
|
---|
| 64 | =item B<-h|--help>
|
---|
| 65 |
|
---|
| 66 | Print a brief help message and exits.
|
---|
| 67 |
|
---|
| 68 | =item B<--man>
|
---|
| 69 |
|
---|
| 70 | Prints the manual page and exits.
|
---|
| 71 |
|
---|
| 72 | =item B<-t|--text>
|
---|
| 73 | =item B<-g|--graphic>
|
---|
| 74 |
|
---|
| 75 | Interface is either text mode or graphical mode (newt based)
|
---|
| 76 |
|
---|
| 77 | =back
|
---|
| 78 |
|
---|
| 79 | =head1 ARGUMENTS
|
---|
| 80 |
|
---|
| 81 | =head1 WEB SITES
|
---|
| 82 |
|
---|
| 83 | 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/>.
|
---|
| 84 |
|
---|
| 85 | =head1 USER MAILING LIST
|
---|
| 86 |
|
---|
| 87 | None exists for the moment.
|
---|
| 88 |
|
---|
| 89 | =head1 CONFIGURATION FILES
|
---|
| 90 |
|
---|
| 91 | =head1 AUTHORS
|
---|
| 92 |
|
---|
| 93 | The CDDBeditor team L<http://trac.project-builder.org/> lead by Bruno Cornec L<mailto:bruno@project-builder.org>.
|
---|
| 94 |
|
---|
| 95 | =head1 COPYRIGHT
|
---|
| 96 |
|
---|
| 97 | CDDBeditor is distributed under the GPL v2.0 license
|
---|
| 98 | described in the file C<COPYING> included with the distribution.
|
---|
| 99 |
|
---|
| 100 | =cut
|
---|
| 101 |
|
---|
| 102 | # ---------------------------------------------------------------------------
|
---|
| 103 |
|
---|
| 104 | #Avoids an error from Newt
|
---|
| 105 | no AutoLoader;
|
---|
| 106 |
|
---|
| 107 |
|
---|
| 108 | # Initialize the syntax string
|
---|
| 109 |
|
---|
| 110 | my $projver = "PBVER";
|
---|
| 111 | my $projrev = "PBREV";
|
---|
| 112 |
|
---|
| 113 | pb_syntax_init("CDDBeditor Version $projver-$projrev\n");
|
---|
| 114 |
|
---|
| 115 | GetOptions("help|?|h" => \$opts{'h'},
|
---|
| 116 | "man" => \$opts{'man'},
|
---|
| 117 | "verbose|v+" => \$opts{'v'},
|
---|
| 118 | "quiet|q" => \$opts{'q'},
|
---|
| 119 | "text|t" => \$opts{'t'},
|
---|
| 120 | "graphic|g" => \$opts{'g'},
|
---|
| 121 | "version|V=s" => \$opts{'V'},
|
---|
| 122 | ) || pb_syntax(-1,0);
|
---|
| 123 |
|
---|
| 124 | if (defined $opts{'h'}) {
|
---|
| 125 | pb_syntax(0,1);
|
---|
| 126 | }
|
---|
| 127 | if (defined $opts{'man'}) {
|
---|
| 128 | pb_syntax(0,2);
|
---|
| 129 | }
|
---|
| 130 | if (defined $opts{'v'}) {
|
---|
| 131 | $pbdebug = $opts{'v'};
|
---|
| 132 | }
|
---|
| 133 | if (defined $opts{'q'}) {
|
---|
| 134 | $pbdebug=-1;
|
---|
| 135 | }
|
---|
| 136 | pb_log_init($pbdebug, $pbLOG);
|
---|
| 137 |
|
---|
| 138 |
|
---|
| 139 | Newt::Init();
|
---|
| 140 | my ($ce_sl, $ce_sh) = Newt::GetScreenSize();
|
---|
| 141 |
|
---|
| 142 | # String definitions
|
---|
| 143 | my $ce_title = "CDDBeditor";
|
---|
| 144 | my $ce_help = "(c) Bruno Cornec 2009 - All right reversed under the GPL v2";
|
---|
| 145 | my $artist_label = Newt::Label("Artist: ");
|
---|
[847] | 146 | my $empty_label = Newt::Label(" ");
|
---|
| 147 | #my $data_label = Newt::Label("Data: ");
|
---|
| 148 | #my $raw_label = Newt::Label("Raw: ");
|
---|
[840] | 149 | my $title_label = Newt::Label("Title: ");
|
---|
| 150 | my $year_label = Newt::Label("Year: ");
|
---|
| 151 | my $id_label = Newt::Label("Id: ");
|
---|
| 152 | my $genre_label = Newt::Label("Genre: ");
|
---|
| 153 | my $category_label = Newt::Label("Category: ");
|
---|
| 154 | my $info_label = Newt::Label("Info: ");
|
---|
| 155 | my $tr_track_label = Newt::Label("Track");
|
---|
[843] | 156 | my $tr_frames_label = Newt::Label("Frames");
|
---|
[847] | 157 | my $tno_label = Newt::Label("Track #: ");
|
---|
[840] | 158 | my $tr_title_label = Newt::Label("Title");
|
---|
| 159 | my $tr_author_label = Newt::Label("Author");
|
---|
| 160 | my $tr_length_label = Newt::Label("Length");
|
---|
| 161 |
|
---|
| 162 | my $host_label = Newt::Label("Host: ");
|
---|
| 163 | my $port_label = Newt::Label("Port: ");
|
---|
| 164 | my $mode_label = Newt::Label("Mode: ");
|
---|
| 165 | my $dev_label = Newt::Label("Device: ");
|
---|
| 166 | my $proxy_label = Newt::Label("Proxy: ");
|
---|
[844] | 167 | my $user_label = Newt::Label("Multi CD: ");
|
---|
[840] | 168 |
|
---|
| 169 | my $wait_label = Newt::Label("Please wait while searching ...");
|
---|
| 170 |
|
---|
| 171 | # To be put in conf file
|
---|
| 172 | my %ce_config;
|
---|
| 173 | $ce_config{"CDDB_HOST"}="freedb.freedb.org";
|
---|
[855] | 174 | $ce_config{"CDDB_PORT"}=888;
|
---|
| 175 | #$ce_config{"CDDB_PORT"}=80;
|
---|
[840] | 176 | my %ce_cddb_mode;
|
---|
[855] | 177 | $ce_cddb_mode{"0"} = "cddb";
|
---|
| 178 | $ce_cddb_mode{"1"} = "http";
|
---|
[840] | 179 |
|
---|
[855] | 180 | $ce_config{"CDDB_MODE"}=$ce_cddb_mode{"1"};
|
---|
[840] | 181 | $ce_config{"CD_DEVICE"}="/dev/sr0";
|
---|
| 182 | $ce_config{"HTTP_PROXY"}=$ENV{http_proxy} if $ENV{http_proxy};
|
---|
| 183 | $ce_config{"input"}=0;
|
---|
[858] | 184 | $ce_config{"HELLO_ID"} = "bruno musique-ancienne.org fastrip 0.77";
|
---|
| 185 | $ce_config{"PROTO_VERSION"} = 6;
|
---|
[840] | 186 |
|
---|
| 187 | # First panel for configuration parameters
|
---|
| 188 | Newt::Cls();
|
---|
| 189 | Newt::DrawRootText(ce_center_string($ce_title), 1, $ce_title);
|
---|
| 190 | Newt::PushHelpLine($ce_help);
|
---|
| 191 | Newt::Refresh();
|
---|
| 192 |
|
---|
| 193 | my $flag = NEWT_ENTRY_SCROLL;
|
---|
| 194 | my $width = 40;
|
---|
| 195 | my $host_entry = Newt::Entry($width, $flag, $ce_config{"CDDB_HOST"});
|
---|
| 196 | $width = 5;
|
---|
| 197 | my $port_entry = Newt::Entry($width, $flag, $ce_config{"CDDB_PORT"});
|
---|
| 198 | my $mode_group;
|
---|
| 199 | my $proxy_entry = undef;
|
---|
[855] | 200 | $mode_group = Newt::HRadiogroup($ce_cddb_mode{"0"}, $ce_cddb_mode{"1"});
|
---|
| 201 | if ($ce_config{"CDDB_MODE"} eq "http" ) {
|
---|
[840] | 202 | $proxy_entry = Newt::Entry($width, $flag, $ce_config{"HTTP_PROXY"});
|
---|
| 203 | }
|
---|
| 204 | $width = 40;
|
---|
| 205 | my $dev_entry = Newt::Entry($width, $flag, $ce_config{"CD_DEVICE"});
|
---|
| 206 | my $user_group;
|
---|
| 207 | if ($ce_config{input} == 0 ) {
|
---|
| 208 | $user_group = Newt::HRadiogroup('FALSE', 'TRUE');
|
---|
| 209 | } else {
|
---|
| 210 | $user_group = Newt::HRadiogroup('TRUE', 'FALSE');
|
---|
| 211 | }
|
---|
| 212 | my $quit_button = Newt::Button("Quit");
|
---|
| 213 | $quit_button->Tag("Quit");
|
---|
| 214 | my $next_button = Newt::Button("Next");
|
---|
| 215 | $next_button->Tag("Next");
|
---|
| 216 |
|
---|
| 217 | my $ce_panel = Newt::Panel(2, 20, "CDDBeditor Configuration");
|
---|
[847] | 218 | my $flage = NEWT_ANCHOR_RIGHT;
|
---|
[855] | 219 | $ce_panel->Add(0, 0, $host_label, $flage);
|
---|
[847] | 220 | $flage = NEWT_ANCHOR_LEFT;
|
---|
[844] | 221 | $ce_panel->Add(1, 0, $host_entry, $flage);
|
---|
[847] | 222 | $flage = NEWT_ANCHOR_RIGHT;
|
---|
[855] | 223 | $ce_panel->Add(0, 1, $port_label, $flage);
|
---|
[847] | 224 | $flage = NEWT_ANCHOR_LEFT;
|
---|
[844] | 225 | $ce_panel->Add(1, 1, $port_entry, $flage);
|
---|
[847] | 226 | $flage = NEWT_ANCHOR_RIGHT;
|
---|
[855] | 227 | $ce_panel->Add(0, 2, $mode_label, $flage);
|
---|
[847] | 228 | $flage = NEWT_ANCHOR_LEFT;
|
---|
[844] | 229 | $ce_panel->Add(1, 2, $mode_group, $flage);
|
---|
[855] | 230 | if ($ce_config{"CDDB_MODE"} eq "http" ) {
|
---|
| 231 | $flage = NEWT_ANCHOR_RIGHT;
|
---|
| 232 | $ce_panel->Add(0, 3, $proxy_label, $flage);
|
---|
| 233 | $flage = NEWT_ANCHOR_LEFT;
|
---|
| 234 | $ce_panel->Add(1, 3, $proxy_entry, $flage);
|
---|
| 235 | }
|
---|
[847] | 236 | $flage = NEWT_ANCHOR_RIGHT;
|
---|
[855] | 237 | $ce_panel->Add(0, 4, $dev_label, $flage);
|
---|
[847] | 238 | $flage = NEWT_ANCHOR_LEFT;
|
---|
[844] | 239 | $ce_panel->Add(1, 4, $dev_entry, $flage);
|
---|
[847] | 240 | $flage = NEWT_ANCHOR_RIGHT;
|
---|
[855] | 241 | $ce_panel->Add(0, 5, $user_label, $flage);
|
---|
[847] | 242 | $flage = NEWT_ANCHOR_LEFT;
|
---|
[844] | 243 | $ce_panel->Add(1, 5, $user_group, $flage);
|
---|
[847] | 244 | $ce_panel->Add(0, 6, $empty_label);
|
---|
| 245 | $ce_panel->Add(0, 7, $next_button);
|
---|
| 246 | $ce_panel->Add(1, 7, $quit_button);
|
---|
[840] | 247 |
|
---|
[844] | 248 | Newt::Refresh();
|
---|
[840] | 249 | my ($reason, $data) = $ce_panel->Run();
|
---|
[844] | 250 |
|
---|
[840] | 251 | Newt::Cls();
|
---|
| 252 | exit 0 if ($data->Tag() eq "Quit");
|
---|
| 253 |
|
---|
[855] | 254 | if ($ce_config{"CDDB_MODE"} eq "http" ) {
|
---|
| 255 | $ce_config{"HTTP_PROXY"}=$proxy_entry->Get();
|
---|
| 256 | }
|
---|
[840] | 257 | $ce_config{"CDDB_HOST"}=$host_entry->Get();
|
---|
| 258 | $ce_config{"CDDB_PORT"}=$port_entry->Get();
|
---|
| 259 | $ce_config{"CDDB_MODE"}=$ce_cddb_mode{$mode_group->Get()};
|
---|
| 260 | $ce_config{"CD_DEVICE"}=$dev_entry->Get();
|
---|
| 261 | $ce_config{"input"}=$user_group->Get();
|
---|
| 262 |
|
---|
| 263 | # Components
|
---|
| 264 | my $reload_button = Newt::Button("Reload");
|
---|
| 265 | $reload_button->Tag("Reload");
|
---|
| 266 | my $send_button = Newt::Button("Send");
|
---|
| 267 | $send_button->Tag("Send");
|
---|
| 268 |
|
---|
| 269 | # Entering the loop
|
---|
| 270 | for (my $i=0 ; ; $i++) {
|
---|
| 271 | # Second panel to make user wait
|
---|
[844] | 272 | Newt::Cls();
|
---|
[840] | 273 | Newt::DrawRootText(ce_center_string($ce_title), 1, $ce_title);
|
---|
| 274 | Newt::PushHelpLine($ce_help);
|
---|
| 275 | $ce_panel = Newt::Panel(3, 20, "CDDB Search");
|
---|
| 276 | $ce_panel->Add(0, 0, $wait_label);
|
---|
[844] | 277 |
|
---|
[846] | 278 | ($reason, $data) = $ce_panel->Draw();
|
---|
[844] | 279 | Newt::Refresh();
|
---|
[840] | 280 |
|
---|
| 281 | # CDDB query
|
---|
| 282 | my %ce_cd = get_cddb(\%ce_config);
|
---|
| 283 |
|
---|
[858] | 284 | # Modify enconding of some fields if proto < 5
|
---|
| 285 | #$ce_cd{artist} = decode("iso8859-1",$ce_cd{artist});
|
---|
| 286 | #$ce_cd{title} = decode("iso8859-1",$ce_cd{title});
|
---|
[846] | 287 |
|
---|
[840] | 288 | # Third panel to display CD Infos
|
---|
| 289 | Newt::DrawRootText(ce_center_string($ce_title), 1, $ce_title);
|
---|
| 290 | Newt::PushHelpLine($ce_help);
|
---|
| 291 |
|
---|
| 292 | # Components
|
---|
| 293 | $flag = NEWT_ENTRY_SCROLL;
|
---|
| 294 | $width = 40;
|
---|
| 295 | my $artist_entry = Newt::Entry($width, $flag, $ce_cd{artist});
|
---|
| 296 | my $title_entry = Newt::Entry($width, $flag, $ce_cd{title});
|
---|
[855] | 297 | # http://www.freedb.org/en/faq.3.html
|
---|
| 298 | # Category list is data, folk, jazz, misc, rock, country, blues, newage, reggae, classical, and soundtrack
|
---|
[840] | 299 | my $category_entry = Newt::Entry($width, $flag, $ce_cd{cat});
|
---|
| 300 | my $genre_entry = Newt::Entry($width, $flag, $ce_cd{genre});
|
---|
[847] | 301 | #my $data_entry = Newt::Entry($width, $flag, Dumper(@{$ce_cd{data}}));
|
---|
| 302 | #my $raw_entry = Newt::Entry($width, $flag, Dumper(@{$ce_cd{raw}}));
|
---|
[843] | 303 | my $tno_entry = Newt::Label($ce_cd{tno});
|
---|
[844] | 304 | $width = 5;
|
---|
[840] | 305 | my $year_entry = Newt::Entry($width, $flag, $ce_cd{year});
|
---|
| 306 |
|
---|
| 307 | # Build interface
|
---|
[843] | 308 | $ce_panel = Newt::Panel(3, $ce_sh, "CDDB Info");
|
---|
[847] | 309 | $flage = NEWT_ANCHOR_RIGHT;
|
---|
| 310 | $ce_panel->Add(0, 0, $artist_label,$flage);
|
---|
| 311 | $flage = NEWT_ANCHOR_LEFT;
|
---|
[844] | 312 | $ce_panel->Add(1, 0, $artist_entry, $flage);
|
---|
[847] | 313 | $flage = NEWT_ANCHOR_RIGHT;
|
---|
| 314 | $ce_panel->Add(0, 1, $title_label,$flage);
|
---|
| 315 | $flage = NEWT_ANCHOR_LEFT;
|
---|
[844] | 316 | $ce_panel->Add(1, 1, $title_entry, $flage);
|
---|
[847] | 317 | $flage = NEWT_ANCHOR_RIGHT;
|
---|
| 318 | $ce_panel->Add(0, 2, $year_label,$flage);
|
---|
| 319 | $flage = NEWT_ANCHOR_LEFT;
|
---|
[844] | 320 | $ce_panel->Add(1, 2, $year_entry, $flage);
|
---|
[847] | 321 | $flage = NEWT_ANCHOR_RIGHT;
|
---|
| 322 | $ce_panel->Add(0, 3, $category_label,$flage);
|
---|
| 323 | $flage = NEWT_ANCHOR_LEFT;
|
---|
[844] | 324 | $ce_panel->Add(1, 3, $category_entry, $flage);
|
---|
[847] | 325 | $flage = NEWT_ANCHOR_RIGHT;
|
---|
| 326 | $ce_panel->Add(0, 4, $genre_label,$flage);
|
---|
| 327 | $flage = NEWT_ANCHOR_LEFT;
|
---|
[844] | 328 | $ce_panel->Add(1, 4, $genre_entry, $flage);
|
---|
[847] | 329 | $flage = NEWT_ANCHOR_RIGHT;
|
---|
| 330 | $ce_panel->Add(0, 5, $tno_label,$flage);
|
---|
| 331 | $flage = NEWT_ANCHOR_LEFT;
|
---|
| 332 | $ce_panel->Add(1, 5, $tno_entry, $flage);
|
---|
| 333 | #$ce_panel->Add(0, 5, $data_label);
|
---|
| 334 | #$ce_panel->Add(1, 5, $data_entry, $flage);
|
---|
| 335 | #$ce_panel->Add(0, 6, $raw_label);
|
---|
| 336 | #$ce_panel->Add(1, 6, $raw_entry, $flage);
|
---|
[843] | 337 | #$ce_panel->Add(0, 5, $info_label);
|
---|
[844] | 338 | #$ce_panel->Add(1, 5, $info_entry, $flage);
|
---|
[843] | 339 |
|
---|
| 340 | my $n=1;
|
---|
| 341 | $width = 40;
|
---|
| 342 | while ( $n <= $ce_cd{tno} ) {
|
---|
| 343 | last if ($n > $ce_sh - 8);
|
---|
| 344 | my $from=$ce_cd{frames}[$n-1];
|
---|
| 345 | my $to=$ce_cd{frames}[$n]-1;
|
---|
| 346 | my $dur=$to-$from;
|
---|
| 347 | my $min=int($dur/75/60);
|
---|
| 348 | my $sec=int($dur/75)-$min*60;
|
---|
[858] | 349 | #my $frm=($dur-$sec*75-$min*75*60)*100/75;
|
---|
[843] | 350 | my $tr = sprintf "Track %2d:", $n;
|
---|
| 351 | my $track_label = Newt::Label($tr);
|
---|
[844] | 352 | $tr = sprintf " %2d':%.2d", $min, $sec;
|
---|
[858] | 353 | # Adapt encoding of track if proto < 5
|
---|
| 354 | #$ce_cd{track}[$n -1] = decode("iso8859-1",$ce_cd{track}[$n -1]);
|
---|
| 355 |
|
---|
[843] | 356 | my $dur_label = Newt::Label($tr);
|
---|
| 357 | $flag = NEWT_FLAG_WRAP|NEWT_ENTRY_SCROLL;
|
---|
[844] | 358 | my $track_entry = Newt::Entry($width, $flag, $ce_cd{track}[$n-1]);
|
---|
[843] | 359 | $ce_panel->Add(0, 8+$n, $track_label);
|
---|
[844] | 360 | $ce_panel->Add(1, 8+$n, $track_entry, $flage);
|
---|
| 361 | $ce_panel->Add(2, 8+$n, $dur_label, $flage);
|
---|
[843] | 362 | $n++;
|
---|
| 363 | }
|
---|
[847] | 364 | $ce_panel->Add(0, 8+$n, $empty_label);
|
---|
[843] | 365 |
|
---|
[847] | 366 | $ce_panel->Add(0, 8+$n+1, $send_button);
|
---|
| 367 | $ce_panel->Add(1, 8+$n+1, $reload_button);
|
---|
| 368 | $ce_panel->Add(2, 8+$n+1, $quit_button);
|
---|
[840] | 369 |
|
---|
[844] | 370 | Newt::Cls();
|
---|
| 371 | Newt::Refresh();
|
---|
[840] | 372 | # Build interface
|
---|
| 373 | ($reason, $data) = $ce_panel->Run();
|
---|
[843] | 374 |
|
---|
[840] | 375 | $ce_cd{artist} = $artist_entry->Get();
|
---|
| 376 | $ce_cd{title} = $title_entry->Get();
|
---|
| 377 | $ce_cd{year} = $year_entry->Get();
|
---|
| 378 | $ce_cd{cat} = $category_entry->Get();
|
---|
| 379 | $ce_cd{genre} = $genre_entry->Get();
|
---|
| 380 | Newt::Refresh();
|
---|
| 381 | Newt::Cls();
|
---|
| 382 | exit 0 if ($data->Tag() eq "Quit");
|
---|
| 383 |
|
---|
| 384 | # Send the data
|
---|
| 385 | if ($data->Tag() eq "Send") {
|
---|
| 386 | $flag = NEWT_FLAG_WRAP;
|
---|
| 387 | $width = 40;
|
---|
[843] | 388 | my $height = 25;
|
---|
[840] | 389 |
|
---|
| 390 | Newt::DrawRootText(ce_center_string($ce_title), 1, $ce_title);
|
---|
| 391 | Newt::PushHelpLine($ce_help);
|
---|
| 392 |
|
---|
[858] | 393 | ce_prepare_mail(\%ce_cd);
|
---|
| 394 | open(TEXT,"$ENV{'PBTMP'}/mail.txt") || die "Unable to open $ENV{'PBTMP'}/mail.txt";
|
---|
| 395 | my $txt = "";
|
---|
| 396 | #my $txt = pb_get_content("$ENV{'PBTMP'}/mail.txt");
|
---|
| 397 | while (<TEXT>) {
|
---|
| 398 | next if (/^#/);
|
---|
| 399 | $txt .= $_;
|
---|
| 400 | }
|
---|
| 401 | my $info_tb = Newt::Textbox($width, $height, $flag, $txt);
|
---|
| 402 |
|
---|
[844] | 403 | Newt::Cls();
|
---|
[840] | 404 | $ce_panel = Newt::Panel(3, $width, "CDDB Sending Infos");
|
---|
| 405 | $ce_panel->Add(0, 0, $wait_label);
|
---|
| 406 | $ce_panel->Add(0, 1, $info_tb);
|
---|
| 407 | $ce_panel->Add(0, 2, $quit_button);
|
---|
[844] | 408 | Newt::Refresh();
|
---|
[840] | 409 | ($reason, $data) = $ce_panel->Run();
|
---|
| 410 | }
|
---|
| 411 | }
|
---|
| 412 | Newt::Finished();
|
---|
| 413 | exit 0;
|
---|
| 414 |
|
---|
| 415 | # return the char to start printing a centered string based on screen size
|
---|
| 416 | sub ce_center_string {
|
---|
| 417 |
|
---|
| 418 | my $string = shift || "";
|
---|
| 419 |
|
---|
| 420 | my $res = ($ce_sl / 2 ) - (length($string) / 2);
|
---|
| 421 | if ($res < 0 ) {
|
---|
| 422 | return 0;
|
---|
| 423 | } else {
|
---|
| 424 | return ($res);
|
---|
| 425 | }
|
---|
| 426 | }
|
---|
| 427 |
|
---|
[858] | 428 | sub ce_prepare_mail() {
|
---|
| 429 |
|
---|
| 430 | my $ce_cd = shift;
|
---|
| 431 |
|
---|
| 432 | open(MAIL, "> $ENV{'PBTMP'}/mail.txt") || die "Unable to create $ENV{'PBTMP'}/mail.txt";
|
---|
| 433 | print MAIL "# xmcd CD database file\n#\n# Track frame offsets:\n";
|
---|
| 434 | my $n=1;
|
---|
| 435 | while ( $n <= $ce_cd->{tno} ) {
|
---|
| 436 | print MAIL "# ".$ce_cd->{frames}[$n-1]."\n";
|
---|
| 437 | $n++;
|
---|
| 438 | }
|
---|
| 439 | my $from=$ce_cd->{frames}[0];
|
---|
| 440 | my $to=$ce_cd->{frames}[$ce_cd->{tno}];
|
---|
| 441 | my $dur=$to-$from;
|
---|
| 442 | my $sec=int($dur/75);
|
---|
| 443 | my $rev = $ce_cd->{revision} + 1;
|
---|
| 444 | print MAIL "#\n# Disc length: $sec seconds\n#\n";
|
---|
| 445 | print MAIL "# Revision: $rev\n";
|
---|
| 446 | print MAIL "# Processed by: cddbd v1.5PL3 Copyright (c) Steve Scherf et al.\n";
|
---|
| 447 | print MAIL "# Submitted via: CDDBEditor $projver-$projrev\n";
|
---|
| 448 | print MAIL "DISCID=$ce_cd->{id}\n";
|
---|
| 449 | print MAIL "DTITLE=$ce_cd->{title}\n";
|
---|
| 450 | print MAIL "DYEAR=$ce_cd->{year}\n";
|
---|
| 451 | print MAIL "DGENRE=$ce_cd->{genre}\n";
|
---|
| 452 | $n=1;
|
---|
| 453 | while ( $n <= $ce_cd->{tno} ) {
|
---|
| 454 | print MAIL "TTITLE$n=$ce_cd->{track}[$n-1]\n";
|
---|
| 455 | $n++;
|
---|
| 456 | }
|
---|
| 457 | print MAIL "EXTD=\n";
|
---|
| 458 | $n=1;
|
---|
| 459 | while ( $n <= $ce_cd->{tno} ) {
|
---|
| 460 | print MAIL "EXTT$n=\n";
|
---|
| 461 | $n++;
|
---|
| 462 | }
|
---|
| 463 | print MAIL "PLAYORDER=\n";
|
---|
| 464 | close(MAIL);
|
---|
| 465 | }
|
---|
| 466 |
|
---|
[840] | 467 | 1;
|
---|