[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);
|
---|
| 20 | use Newt qw(NEWT_FLAG_WRAP :entry :textbox :macros);
|
---|
| 21 | use lib qw (lib);
|
---|
| 22 | use locale;
|
---|
| 23 | use CDDB_get qw( get_cddb get_discids );
|
---|
| 24 | use CDDB;
|
---|
| 25 |
|
---|
| 26 | # Global variables
|
---|
| 27 | my %opts; # CLI Options
|
---|
| 28 | my $action; # action to realize
|
---|
| 29 |
|
---|
| 30 | my @date = pb_get_date();
|
---|
| 31 | my $pbdate = strftime("%Y-%m-%d", @date);
|
---|
| 32 |
|
---|
| 33 | =pod
|
---|
| 34 |
|
---|
| 35 | =head1 NAME
|
---|
| 36 |
|
---|
| 37 | CDDBeditor, read, modidy and send your CDDB contrinutions
|
---|
| 38 |
|
---|
| 39 | =head1 DESCRIPTION
|
---|
| 40 |
|
---|
| 41 | CDDBeditor helps you read, modidy and send your CDDB contrinutions.
|
---|
| 42 |
|
---|
| 43 | =head1 SYNOPSIS
|
---|
| 44 |
|
---|
| 45 | CDDBeditor [-vhmq][-t|-g]
|
---|
| 46 |
|
---|
| 47 | CDDBeditor [--verbose][--help][--man][--quiet][--text|--graphic]
|
---|
| 48 |
|
---|
| 49 | =head1 OPTIONS
|
---|
| 50 |
|
---|
| 51 | =over 4
|
---|
| 52 |
|
---|
| 53 | =item B<-v|--verbose>
|
---|
| 54 |
|
---|
| 55 | Print a brief help message and exits.
|
---|
| 56 |
|
---|
| 57 | =item B<-q|--quiet>
|
---|
| 58 |
|
---|
| 59 | Do not print any output.
|
---|
| 60 |
|
---|
| 61 | =item B<-h|--help>
|
---|
| 62 |
|
---|
| 63 | Print a brief help message and exits.
|
---|
| 64 |
|
---|
| 65 | =item B<--man>
|
---|
| 66 |
|
---|
| 67 | Prints the manual page and exits.
|
---|
| 68 |
|
---|
| 69 | =item B<-t|--text>
|
---|
| 70 | =item B<-g|--graphic>
|
---|
| 71 |
|
---|
| 72 | Interface is either text mode or graphical mode (newt based)
|
---|
| 73 |
|
---|
| 74 | =back
|
---|
| 75 |
|
---|
| 76 | =head1 ARGUMENTS
|
---|
| 77 |
|
---|
| 78 | =head1 WEB SITES
|
---|
| 79 |
|
---|
| 80 | 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/>.
|
---|
| 81 |
|
---|
| 82 | =head1 USER MAILING LIST
|
---|
| 83 |
|
---|
| 84 | None exists for the moment.
|
---|
| 85 |
|
---|
| 86 | =head1 CONFIGURATION FILES
|
---|
| 87 |
|
---|
| 88 | =head1 AUTHORS
|
---|
| 89 |
|
---|
| 90 | The CDDBeditor team L<http://trac.project-builder.org/> lead by Bruno Cornec L<mailto:bruno@project-builder.org>.
|
---|
| 91 |
|
---|
| 92 | =head1 COPYRIGHT
|
---|
| 93 |
|
---|
| 94 | CDDBeditor is distributed under the GPL v2.0 license
|
---|
| 95 | described in the file C<COPYING> included with the distribution.
|
---|
| 96 |
|
---|
| 97 | =cut
|
---|
| 98 |
|
---|
| 99 | # ---------------------------------------------------------------------------
|
---|
| 100 |
|
---|
| 101 | #Avoids an error from Newt
|
---|
| 102 | no AutoLoader;
|
---|
| 103 |
|
---|
| 104 |
|
---|
| 105 | # Initialize the syntax string
|
---|
| 106 |
|
---|
| 107 | my $projver = "PBVER";
|
---|
| 108 | my $projrev = "PBREV";
|
---|
| 109 |
|
---|
| 110 | pb_syntax_init("CDDBeditor Version $projver-$projrev\n");
|
---|
| 111 |
|
---|
| 112 | GetOptions("help|?|h" => \$opts{'h'},
|
---|
| 113 | "man" => \$opts{'man'},
|
---|
| 114 | "verbose|v+" => \$opts{'v'},
|
---|
| 115 | "quiet|q" => \$opts{'q'},
|
---|
| 116 | "text|t" => \$opts{'t'},
|
---|
| 117 | "graphic|g" => \$opts{'g'},
|
---|
| 118 | "version|V=s" => \$opts{'V'},
|
---|
| 119 | ) || pb_syntax(-1,0);
|
---|
| 120 |
|
---|
| 121 | if (defined $opts{'h'}) {
|
---|
| 122 | pb_syntax(0,1);
|
---|
| 123 | }
|
---|
| 124 | if (defined $opts{'man'}) {
|
---|
| 125 | pb_syntax(0,2);
|
---|
| 126 | }
|
---|
| 127 | if (defined $opts{'v'}) {
|
---|
| 128 | $pbdebug = $opts{'v'};
|
---|
| 129 | }
|
---|
| 130 | if (defined $opts{'q'}) {
|
---|
| 131 | $pbdebug=-1;
|
---|
| 132 | }
|
---|
| 133 | pb_log_init($pbdebug, $pbLOG);
|
---|
| 134 |
|
---|
| 135 |
|
---|
| 136 | Newt::Init();
|
---|
| 137 | my ($ce_sl, $ce_sh) = Newt::GetScreenSize();
|
---|
| 138 |
|
---|
| 139 | # String definitions
|
---|
| 140 | my $ce_title = "CDDBeditor";
|
---|
| 141 | my $ce_help = "(c) Bruno Cornec 2009 - All right reversed under the GPL v2";
|
---|
| 142 | my $artist_label = Newt::Label("Artist: ");
|
---|
[843] | 143 | my $data_label = Newt::Label("Data: ");
|
---|
| 144 | my $raw_label = Newt::Label("Raw: ");
|
---|
[840] | 145 | my $title_label = Newt::Label("Title: ");
|
---|
| 146 | my $year_label = Newt::Label("Year: ");
|
---|
| 147 | my $id_label = Newt::Label("Id: ");
|
---|
| 148 | my $genre_label = Newt::Label("Genre: ");
|
---|
| 149 | my $category_label = Newt::Label("Category: ");
|
---|
| 150 | my $info_label = Newt::Label("Info: ");
|
---|
| 151 | my $tr_track_label = Newt::Label("Track");
|
---|
[843] | 152 | my $tr_frames_label = Newt::Label("Frames");
|
---|
| 153 | my $tno_label = Newt::Label("Track #:");
|
---|
[840] | 154 | my $tr_title_label = Newt::Label("Title");
|
---|
| 155 | my $tr_author_label = Newt::Label("Author");
|
---|
| 156 | my $tr_length_label = Newt::Label("Length");
|
---|
| 157 |
|
---|
| 158 | my $host_label = Newt::Label("Host: ");
|
---|
| 159 | my $port_label = Newt::Label("Port: ");
|
---|
| 160 | my $mode_label = Newt::Label("Mode: ");
|
---|
| 161 | my $dev_label = Newt::Label("Device: ");
|
---|
| 162 | my $proxy_label = Newt::Label("Proxy: ");
|
---|
| 163 | my $user_label = Newt::Label("Multiple CD proposal: ");
|
---|
| 164 |
|
---|
| 165 | my $wait_label = Newt::Label("Please wait while searching ...");
|
---|
| 166 |
|
---|
| 167 | # To be put in conf file
|
---|
| 168 | my %ce_config;
|
---|
| 169 | $ce_config{"CDDB_HOST"}="freedb.freedb.org";
|
---|
| 170 | $ce_config{"CDDB_PORT"}=80;
|
---|
| 171 | my %ce_cddb_mode;
|
---|
| 172 | $ce_cddb_mode{"0"} = "http";
|
---|
| 173 | $ce_cddb_mode{"1"} = "cddb";
|
---|
| 174 |
|
---|
| 175 | $ce_config{"CDDB_MODE"}=$ce_cddb_mode{"0"};
|
---|
| 176 | $ce_config{"CD_DEVICE"}="/dev/sr0";
|
---|
| 177 | $ce_config{"HTTP_PROXY"}=$ENV{http_proxy} if $ENV{http_proxy};
|
---|
| 178 | $ce_config{"input"}=0;
|
---|
| 179 |
|
---|
| 180 | # First panel for configuration parameters
|
---|
| 181 | Newt::Cls();
|
---|
| 182 | Newt::DrawRootText(ce_center_string($ce_title), 1, $ce_title);
|
---|
| 183 | Newt::PushHelpLine($ce_help);
|
---|
| 184 | Newt::Refresh();
|
---|
| 185 |
|
---|
| 186 | my $flag = NEWT_ENTRY_SCROLL;
|
---|
| 187 | my $width = 40;
|
---|
| 188 | my $host_entry = Newt::Entry($width, $flag, $ce_config{"CDDB_HOST"});
|
---|
| 189 | $width = 5;
|
---|
| 190 | my $port_entry = Newt::Entry($width, $flag, $ce_config{"CDDB_PORT"});
|
---|
| 191 | my $mode_group;
|
---|
| 192 | my $proxy_entry = undef;
|
---|
| 193 | if ($ce_config{"CDDB_MODE"} eq $ce_cddb_mode{"0"} ) {
|
---|
| 194 | $mode_group = Newt::HRadiogroup($ce_cddb_mode{"0"}, $ce_cddb_mode{"1"});
|
---|
| 195 | $proxy_entry = Newt::Entry($width, $flag, $ce_config{"HTTP_PROXY"});
|
---|
| 196 | } else {
|
---|
| 197 | $mode_group = Newt::HRadiogroup($ce_cddb_mode{"1"}, $ce_cddb_mode{"0"});
|
---|
| 198 | }
|
---|
| 199 | $width = 40;
|
---|
| 200 | my $dev_entry = Newt::Entry($width, $flag, $ce_config{"CD_DEVICE"});
|
---|
| 201 | my $user_group;
|
---|
| 202 | if ($ce_config{input} == 0 ) {
|
---|
| 203 | $user_group = Newt::HRadiogroup('FALSE', 'TRUE');
|
---|
| 204 | } else {
|
---|
| 205 | $user_group = Newt::HRadiogroup('TRUE', 'FALSE');
|
---|
| 206 | }
|
---|
| 207 | my $quit_button = Newt::Button("Quit");
|
---|
| 208 | $quit_button->Tag("Quit");
|
---|
| 209 | my $next_button = Newt::Button("Next");
|
---|
| 210 | $next_button->Tag("Next");
|
---|
| 211 |
|
---|
| 212 | my $ce_panel = Newt::Panel(2, 20, "CDDBeditor Configuration");
|
---|
| 213 | $ce_panel->Add(0, 0, $host_label);
|
---|
| 214 | $ce_panel->Add(1, 0, $host_entry);
|
---|
| 215 | $ce_panel->Add(0, 1, $port_label);
|
---|
| 216 | $ce_panel->Add(1, 1, $port_entry);
|
---|
| 217 | $ce_panel->Add(0, 2, $mode_label);
|
---|
| 218 | $ce_panel->Add(1, 2, $mode_group);
|
---|
| 219 | $ce_panel->Add(0, 3, $proxy_label);
|
---|
| 220 | $ce_panel->Add(1, 3, $proxy_entry);
|
---|
| 221 | $ce_panel->Add(0, 4, $dev_label);
|
---|
| 222 | $ce_panel->Add(1, 4, $dev_entry);
|
---|
| 223 | $ce_panel->Add(0, 5, $user_label);
|
---|
| 224 | $ce_panel->Add(1, 5, $user_group);
|
---|
| 225 | $ce_panel->Add(0, 6, $next_button);
|
---|
| 226 | $ce_panel->Add(1, 6, $quit_button);
|
---|
| 227 |
|
---|
| 228 | my ($reason, $data) = $ce_panel->Run();
|
---|
| 229 | Newt::Refresh();
|
---|
| 230 | Newt::Cls();
|
---|
| 231 |
|
---|
| 232 | exit 0 if ($data->Tag() eq "Quit");
|
---|
| 233 |
|
---|
| 234 | $ce_config{"CDDB_HOST"}=$host_entry->Get();
|
---|
| 235 | $ce_config{"CDDB_PORT"}=$port_entry->Get();
|
---|
| 236 | $ce_config{"CDDB_MODE"}=$ce_cddb_mode{$mode_group->Get()};
|
---|
| 237 | $ce_config{"CD_DEVICE"}=$dev_entry->Get();
|
---|
| 238 | $ce_config{"HTTP_PROXY"}=$proxy_entry->Get();
|
---|
| 239 | $ce_config{"input"}=$user_group->Get();
|
---|
| 240 |
|
---|
| 241 | # Components
|
---|
| 242 | my $reload_button = Newt::Button("Reload");
|
---|
| 243 | $reload_button->Tag("Reload");
|
---|
| 244 | my $send_button = Newt::Button("Send");
|
---|
| 245 | $send_button->Tag("Send");
|
---|
| 246 |
|
---|
| 247 | # Entering the loop
|
---|
| 248 | for (my $i=0 ; ; $i++) {
|
---|
| 249 | # Second panel to make user wait
|
---|
| 250 | Newt::DrawRootText(ce_center_string($ce_title), 1, $ce_title);
|
---|
| 251 | Newt::PushHelpLine($ce_help);
|
---|
| 252 | $ce_panel = Newt::Panel(3, 20, "CDDB Search");
|
---|
| 253 | $ce_panel->Add(0, 0, $wait_label);
|
---|
| 254 | ($reason, $data) = $ce_panel->Draw();
|
---|
| 255 |
|
---|
| 256 | # CDDB query
|
---|
| 257 | my %ce_cd = get_cddb(\%ce_config);
|
---|
| 258 |
|
---|
| 259 | Newt::Refresh();
|
---|
| 260 | Newt::Cls();
|
---|
| 261 |
|
---|
| 262 | # Third panel to display CD Infos
|
---|
| 263 | Newt::DrawRootText(ce_center_string($ce_title), 1, $ce_title);
|
---|
| 264 | Newt::PushHelpLine($ce_help);
|
---|
| 265 |
|
---|
| 266 | # Components
|
---|
| 267 | $flag = NEWT_ENTRY_SCROLL;
|
---|
| 268 | $width = 40;
|
---|
| 269 | my $artist_entry = Newt::Entry($width, $flag, $ce_cd{artist});
|
---|
| 270 | my $title_entry = Newt::Entry($width, $flag, $ce_cd{title});
|
---|
| 271 | my $category_entry = Newt::Entry($width, $flag, $ce_cd{cat});
|
---|
| 272 | my $genre_entry = Newt::Entry($width, $flag, $ce_cd{genre});
|
---|
[843] | 273 | my $data_entry = Newt::Entry($width, $flag, Dumper($ce_cd{data}));
|
---|
| 274 | my $raw_entry = Newt::Entry($width, $flag, Dumper($ce_cd{raw}));
|
---|
| 275 | my $tno_entry = Newt::Label($ce_cd{tno});
|
---|
[840] | 276 | $width = 4;
|
---|
| 277 | $flag = 0;
|
---|
| 278 | my $year_entry = Newt::Entry($width, $flag, $ce_cd{year});
|
---|
| 279 |
|
---|
| 280 | # Build interface
|
---|
[843] | 281 | $ce_panel = Newt::Panel(3, $ce_sh, "CDDB Info");
|
---|
[840] | 282 | $ce_panel->Add(0, 0, $artist_label);
|
---|
| 283 | $ce_panel->Add(1, 0, $artist_entry);
|
---|
| 284 | $ce_panel->Add(0, 1, $title_label);
|
---|
| 285 | $ce_panel->Add(1, 1, $title_entry);
|
---|
| 286 | $ce_panel->Add(0, 2, $year_label);
|
---|
| 287 | $ce_panel->Add(1, 2, $year_entry);
|
---|
| 288 | $ce_panel->Add(0, 3, $category_label);
|
---|
| 289 | $ce_panel->Add(1, 3, $category_entry);
|
---|
| 290 | $ce_panel->Add(0, 4, $genre_label);
|
---|
| 291 | $ce_panel->Add(1, 4, $genre_entry);
|
---|
[843] | 292 | $ce_panel->Add(0, 5, $data_label);
|
---|
| 293 | $ce_panel->Add(1, 5, $data_entry);
|
---|
| 294 | $ce_panel->Add(0, 6, $raw_label);
|
---|
| 295 | $ce_panel->Add(1, 6, $raw_entry);
|
---|
| 296 | $ce_panel->Add(0, 7, $tno_label);
|
---|
| 297 | $ce_panel->Add(1, 7, $tno_entry);
|
---|
| 298 | #$ce_panel->Add(0, 5, $info_label);
|
---|
| 299 | #$ce_panel->Add(1, 5, $info_entry);
|
---|
| 300 |
|
---|
| 301 | my $n=1;
|
---|
| 302 | $width = 40;
|
---|
| 303 | while ( $n <= $ce_cd{tno} ) {
|
---|
| 304 | last if ($n > $ce_sh - 8);
|
---|
| 305 | my $from=$ce_cd{frames}[$n-1];
|
---|
| 306 | my $to=$ce_cd{frames}[$n]-1;
|
---|
| 307 | my $dur=$to-$from;
|
---|
| 308 | my $min=int($dur/75/60);
|
---|
| 309 | my $sec=int($dur/75)-$min*60;
|
---|
| 310 | my $frm=($dur-$sec*75-$min*75*60)*100/75;
|
---|
| 311 | my $tr = sprintf "Track %2d:", $n;
|
---|
| 312 | my $track_label = Newt::Label($tr);
|
---|
| 313 | $tr = sprintf "%2d':%.2d", $min, $sec;
|
---|
| 314 | my $dur_label = Newt::Label($tr);
|
---|
| 315 | $flag = NEWT_FLAG_WRAP|NEWT_ENTRY_SCROLL;
|
---|
| 316 | my $track_entry = Newt::Entry($width, $flag, Dumper($ce_cd{track}));
|
---|
| 317 | $ce_panel->Add(0, 8+$n, $track_label);
|
---|
| 318 | $ce_panel->Add(1, 8+$n, $dur_label);
|
---|
| 319 | $ce_panel->Add(2, 8+$n, $track_entry);
|
---|
| 320 | $n++;
|
---|
| 321 | }
|
---|
| 322 |
|
---|
| 323 | $ce_panel->Add(0, 8+$n, $send_button);
|
---|
| 324 | $ce_panel->Add(1, 8+$n, $reload_button);
|
---|
| 325 | $ce_panel->Add(2, 8+$n, $quit_button);
|
---|
[840] | 326 |
|
---|
| 327 | # Build interface
|
---|
| 328 | ($reason, $data) = $ce_panel->Run();
|
---|
[843] | 329 |
|
---|
[840] | 330 | $ce_cd{artist} = $artist_entry->Get();
|
---|
| 331 | $ce_cd{title} = $title_entry->Get();
|
---|
| 332 | $ce_cd{year} = $year_entry->Get();
|
---|
| 333 | $ce_cd{cat} = $category_entry->Get();
|
---|
| 334 | $ce_cd{genre} = $genre_entry->Get();
|
---|
| 335 | Newt::Refresh();
|
---|
| 336 | Newt::Cls();
|
---|
| 337 | exit 0 if ($data->Tag() eq "Quit");
|
---|
| 338 |
|
---|
| 339 | # Send the data
|
---|
| 340 | if ($data->Tag() eq "Send") {
|
---|
| 341 | $flag = NEWT_FLAG_WRAP;
|
---|
| 342 | $width = 40;
|
---|
[843] | 343 | my $height = 25;
|
---|
| 344 | my $info_tb = Newt::Textbox($width, $height, $flag, Dumper(keys %ce_cd));
|
---|
[840] | 345 |
|
---|
| 346 | Newt::DrawRootText(ce_center_string($ce_title), 1, $ce_title);
|
---|
| 347 | Newt::PushHelpLine($ce_help);
|
---|
| 348 |
|
---|
| 349 | $ce_panel = Newt::Panel(3, $width, "CDDB Sending Infos");
|
---|
| 350 | $ce_panel->Add(0, 0, $wait_label);
|
---|
| 351 | $ce_panel->Add(0, 1, $info_tb);
|
---|
| 352 | $ce_panel->Add(0, 2, $quit_button);
|
---|
| 353 | ($reason, $data) = $ce_panel->Run();
|
---|
| 354 | Newt::Refresh();
|
---|
| 355 | Newt::Cls();
|
---|
| 356 | }
|
---|
| 357 | }
|
---|
| 358 | Newt::Finished();
|
---|
| 359 | exit 0;
|
---|
| 360 |
|
---|
| 361 | # return the char to start printing a centered string based on screen size
|
---|
| 362 | sub ce_center_string {
|
---|
| 363 |
|
---|
| 364 | my $string = shift || "";
|
---|
| 365 |
|
---|
| 366 | my $res = ($ce_sl / 2 ) - (length($string) / 2);
|
---|
| 367 | if ($res < 0 ) {
|
---|
| 368 | return 0;
|
---|
| 369 | } else {
|
---|
| 370 | return ($res);
|
---|
| 371 | }
|
---|
| 372 | }
|
---|
| 373 |
|
---|
| 374 | 1;
|
---|