Changeset 74
- Timestamp:
- 10/16/06 17:20:07 (7 years ago)
- Files:
-
- 2 modified
-
reconcilers/reconciler_mk2 (modified) (18 diffs)
-
status (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
reconcilers/reconciler_mk2
r73 r74 16 16 # 0.04 17aug06 bug fix: use our own parse_xmltv_date, Date::Manip seems broken 17 17 # bug fix: correctly parse some XMLTV rare fields 18 # 0.05 17aug06 enhancement: compress logfiles automatically since they are quite large 18 19 19 20 # … … 75 76 76 77 my $progname = "reconciler_mk2"; 77 my $version = "0.0 4_15aug06";78 my $version = "0.05_17aug06"; 78 79 79 80 use LWP::UserAgent; … … 197 198 'lang=s' => \$opt->{lang}, 198 199 'option=s' => \%reclogic, 200 201 'no-log' => \$opt->{nolog}, 199 202 200 203 'print_listing' => \$reclogic{debug_print_programme_list}, … … 256 259 257 260 # go go go! 258 open(LOG_FILE,">$opt->{log_file}") || die "can't open log file $opt->{log_file} for writing: $!\n"; 259 open(ALT_TITLE_FILE,">$opt->{alt_title_file}") || die "can't open alt-title-file $opt->{alt_title_file} for writing: $!\n"; 261 unless ($opt->{nolog}) { 262 &rotate_logfiles; 263 264 open(LOG_FILE,">$opt->{log_file}") || die "can't open log file $opt->{log_file} for writing: $!\n"; 265 open(ALT_TITLE_FILE,">$opt->{alt_title_file}") || die "can't open alt-title-file $opt->{alt_title_file} for writing: $!\n"; 266 267 printf ALT_TITLE_FILE "$progname $version\n"; 268 printf ALT_TITLE_FILE "This log file contains lists of what title matches were attempted (but didn't match).\n"; 269 printf ALT_TITLE_FILE "The intent of this is to keep a log that we can (hopefully) interpret in order to\n"; 270 printf ALT_TITLE_FILE "improve the alternateTitle() logic.\n\n"; 271 } 260 272 261 273 &log(1,(sprintf "started: %s%soutput %s", … … 263 275 ($opt->{config_file} ? "default overrides in $opt->{config_file}, " : ""), 264 276 ($opt->{output_file}))); 265 &log(1,(sprintf " logging to %s, alternate titles to %s",$opt->{log_file},$opt->{alt_title_file})); 266 267 printf ALT_TITLE_FILE "$progname $version\n"; 268 printf ALT_TITLE_FILE "This log file contains lists of what title matches were attempted (but didn't match).\n"; 269 printf ALT_TITLE_FILE "The intent of this is to keep a log that we can (hopefully) interpret in order to\n"; 270 printf ALT_TITLE_FILE "improve the alternateTitle() logic.\n\n"; 277 &log(1,(sprintf " logging to %s, alternate titles to %s",$opt->{log_file},$opt->{alt_title_file})) unless $opt->{nolog}; 271 278 272 279 &override_settings; … … 293 300 &print_stats; 294 301 295 close(LOG_FILE); 296 close(ALT_TITLE_FILE); 302 unless ($opt->{nolog}) { 303 close(LOG_FILE); 304 close(ALT_TITLE_FILE); 305 306 compress_file($opt->{log_file}); 307 compress_file($opt->{alt_title_file}); 308 } 297 309 298 310 exit(0); … … 360 372 361 373 ###################################################################################################### 374 375 sub rotate_logfiles 376 { 377 # keep last 4 log files 378 foreach my $file ($opt->{log_file}, $opt->{alt_title_file}) { 379 my $num; 380 for ($num = 4; $num > 0; $num--) { 381 my $f1 = sprintf "%s.%d.gz",$file,$num; 382 my $f2 = sprintf "%s.%d.gz",$file,$num+1; 383 unlink($f2); 384 rename($f1,$f2); 385 } 386 387 my $f1 = sprintf "%s.gz",$file; 388 my $f2 = sprintf "%s.1.gz",$file; 389 rename($f1,$f2); 390 } 391 } 392 393 ###################################################################################################### 394 395 sub compress_file 396 { 397 my $infile = shift; 398 my $outfile = sprintf "%s.gz",$infile; 399 my $gz; 400 401 if (!(open(INFILE,"<$infile"))) { 402 warn "could not open file $infile for reading: $!\n"; 403 return; 404 } 405 406 if (!($gz = gzopen($outfile,"wb"))) { 407 warn "could not open file $outfile for writing: $!\n"; 408 return; 409 } 410 411 while (<INFILE>) { 412 my $byteswritten = $gz->gzwrite($_); 413 if ($byteswritten == 0) { 414 warn "error writing to compressed file: error $gz->gzerror"; 415 } 416 } 417 close(INFILE); 418 $gz->gzclose(); 419 unlink($infile); 420 } 421 422 ###################################################################################################### 362 423 # if we are supplied a channels_file, then fill in channels we know about from that. 363 424 # this is useful because some grabbers (e.g. oztivo) don't supply a <channels></channels> … … 386 447 my ($log_to_screen,$entry) = @_; 387 448 printf STDERR "%s [%d] %s\n",$progname, time,$entry if ($log_to_screen); 388 printf LOG_FILE "%s [%d] %s\n",$progname, time,$entry ;449 printf LOG_FILE "%s [%d] %s\n",$progname, time,$entry unless $opt->{nolog}; 389 450 } 390 451 … … 760 821 if (($t2 - $t1) > $reclogic{max_programme_length}) { 761 822 &log($reclogic{warn_on_invalid_time_in_prog}, 762 (sprintf "WARNING: programme '%s' on channel '%s' from %s had a programme duration (%d) that exceeded max_programme_length (%d): start '%s' stop '%s'; ignored. \n",823 (sprintf "WARNING: programme '%s' on channel '%s' from %s had a programme duration (%d) that exceeded max_programme_length (%d): start '%s' stop '%s'; ignored.", 763 824 $prog_title, $prog_chan, $datafile, ($t2-$t1), $reclogic{max_programme_length}, 764 825 ($prog->{start} ? $prog->{start} : "undef"), ($prog->{stop} ? $prog->{stop} : "undef"))); … … 806 867 &log($warn,(sprintf "WARNING: file contained more than one programme in same timeslot: channel '%s' start %s, stop %s, programs \"%s\" and \"%s\"; ignored.", 807 868 $prog_chan, 808 (strftime "%a %e %b%H:%M",localtime($t1)),809 (strftime "% H:%M",localtime($t2)),869 (strftime "%a%e%b%H:%M",localtime($t1)), 870 (strftime "%a%e%b%H:%M",localtime($t2)), 810 871 $prog_title, 811 872 $in->{dupcheck}->{$source}->{$prog_chan}->{$prog_key})); … … 878 939 printf "%-10s %s - %s: %-30s {src %s}\n", 879 940 $in->{channels}->{$chan_id}->{pref_desc}, 880 (strftime "%a%e%b %H:%M", localtime($prog->{start_epoch})),881 (strftime "% H:%M", localtime($prog->{stop_epoch})),941 (strftime "%a%e%b%H:%M", localtime($prog->{start_epoch})), 942 (strftime "%a%e%b%H:%M", localtime($prog->{stop_epoch})), 882 943 $progname, 883 944 $prog->{datasources} … … 903 964 &log($reclogic{debug_add_logic}, 904 965 (sprintf "add_one_programme: adding programme %s-%s \"%s\" with data from %d programmes", 905 (strftime "%a %e %b%H:%M",localtime(($m->[0]->{start_epoch}))),906 (strftime "% H:%M",localtime(($m->[0]->{stop_epoch}))),966 (strftime "%a%e%b%H:%M",localtime(($m->[0]->{start_epoch}))), 967 (strftime "%a%e%b%H:%M",localtime(($m->[0]->{stop_epoch}))), 907 968 $m->[0]->{title}->[0]->[0], $num_matching)); 908 969 … … 1114 1175 &log($reclogic{debug_delete_logic}, 1115 1176 (sprintf " - deleting \"%s\" (%s-%s, grabber %d) - within window", 1116 $prog_title, (strftime "%a%e%b %H:%M", localtime($prog_start)),1117 (strftime "% H:%M", localtime($prog_stop)), $prog_grabber));1177 $prog_title, (strftime "%a%e%b%H:%M", localtime($prog_start)), 1178 (strftime "%a%e%b%H:%M", localtime($prog_stop)), $prog_grabber)); 1118 1179 } elsif (($prog_start < $del_start) && ($prog_stop > $del_stop)) { 1119 1180 # … … 1132 1193 &log($reclogic{debug_delete_logic}, 1133 1194 (sprintf " - deleting \"%s\" (%s-%s, grabber %d) - within window +/- delete_window_smaller_than_prog_window_threshold (%d)", 1134 $prog_title, (strftime "%a%e%b %H:%M", localtime($prog_start)),1135 (strftime "% H:%M", localtime($prog_stop)), $prog_grabber,1195 $prog_title, (strftime "%a%e%b%H:%M", localtime($prog_start)), 1196 (strftime "%a%e%b%H:%M", localtime($prog_stop)), $prog_grabber, 1136 1197 $reclogic{delete_window_smaller_than_prog_window_threshold})); 1137 1198 $stats{prog_del_overwindow_close_enough}++; … … 1322 1383 my $alternate_titles = sprintf "channel %s timeslot %s-%s, preferred grabber %d\n", 1323 1384 $in->{channels}->{$chan_id}->{pref_desc}, 1324 (strftime "%a %e %b%H:%M",localtime(($prog->{start_epoch}))),1325 (strftime "% H:%M",localtime(($prog->{stop_epoch}))),1385 (strftime "%a%e%b%H:%M",localtime(($prog->{start_epoch}))), 1386 (strftime "%a%e%b%H:%M",localtime(($prog->{stop_epoch}))), 1326 1387 $prog->{grabber_num}; 1327 1388 … … 1400 1461 &log($reclogic{debug_reconcile_pass1}, 1401 1462 (sprintf "reconcile: %d programs between %s - %s", 1402 $num_progs_in_slot, (strftime "%a %e %b%H:%M",localtime($this_prog_start)),1403 (strftime "% H:%M",localtime($this_prog_stop))));1463 $num_progs_in_slot, (strftime "%a%e%b%H:%M",localtime($this_prog_start)), 1464 (strftime "%a%e%b%H:%M",localtime($this_prog_stop)))); 1404 1465 1405 1466 $stats{rec_start_stop_match}++; … … 1439 1500 (sprintf "reconcile: (%d to go) chose programme for %s-%s: \"%s\", looking for alternatives between %s-%s", 1440 1501 $in->{total_progs}->{$chan_id}, 1441 (strftime "%a %e %b%H:%M",localtime($found_prog->{start_epoch})),1442 (strftime "% H:%M",localtime($found_prog->{stop_epoch})), $found_prog->{title}->[0]->[0],1443 (strftime "% H:%M",localtime($start_window)),1444 (strftime "% H:%M",localtime($stop_window))));1502 (strftime "%a%e%b%H:%M",localtime($found_prog->{start_epoch})), 1503 (strftime "%a%e%b%H:%M",localtime($found_prog->{stop_epoch})), $found_prog->{title}->[0]->[0], 1504 (strftime "%a%e%b%H:%M",localtime($start_window)), 1505 (strftime "%a%e%b%H:%M",localtime($stop_window)))); 1445 1506 1446 1507 foreach my $prog_key2 ( sort { $in->{tree}->{$chan_id}->{$a} <=> $in->{tree}->{$chan_id}->{$b} } keys %{($in->{tree}->{$chan_id})} ) { … … 1459 1520 &log($reclogic{debug_reconcile_pass2}, 1460 1521 (sprintf "reconcile: found alternative prog: %s-%s, \"%s\"", 1461 (strftime "%a%e%b %H:%M",localtime($check_prog->{start_epoch})),1462 (strftime "% H:%M",localtime($check_prog->{stop_epoch})),1522 (strftime "%a%e%b%H:%M",localtime($check_prog->{start_epoch})), 1523 (strftime "%a%e%b%H:%M",localtime($check_prog->{stop_epoch})), 1463 1524 $check_prog->{title}->[0]->[0])); 1464 1525 } -
status
r73 r74 7 7 jrobbo:0.03-r2:grabber 8 8 d1:0.6.2.3-r2:grabber 9 reconciler_mk2:0.0 4:reconciler9 reconciler_mk2:0.05:reconciler 10 10 imdb_augment_data:0.01:postprocessor
