/usr/bin/tv_augment is in xmltv-util 0.5.67-0.1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 | #!/usr/bin/perl -w
eval 'exec /usr/bin/perl -w -S $0 ${1+"$@"}'
if 0; # not running under some shell
eval 'exec /usr/bin/perl -w -S $0 ${1+"$@"}'
if 0; # not running under some shell
=pod
=head1 NAME
tv_augment - Augment XMLTV listings files with automatic and user-defined rules.
=head1 SYNOPSIS
tv_augment [--rule <file>] [--config <file>]
[--input <file>] [--output <file>]
[--log <file>] [--nostats]
[--debug <level>]
tv_augment [-r <file>] [-c <file>]
[-i <file>] [-o <file>]
[-l <file>] [-n]
[-d <level>]
=head1 DESCRIPTION
Augment an XMLTV xml file by applying corrections ("fixups") to programmes
matching defined criteria ("rules").
Two types of rules are actioned: (i) automatic, (ii) user-defined.
Automatic rules use pre-programmed input and output to modify the input
programmes. E.g. removing a "title" where it is repeated in a "sub-title"
(e.g. "Horizon" / "Horizon: Star Wars"), or trying to identify and extract
series/episode numbers from the programme title, sub-title or description.
User-defined rules use the content of a "rules" file which allows programmes
matching certain user-defined criteria to be corrected/enhanced with the user
data supplied (e.g. adding/changing categories for all episodes of "Horizon",
or fixing misspellings in titles, etc.)
(see "perldoc -F Augment.pm" for more detail)
B<--input FILE> read from FILE rather than standard input.
B<--output FILE> write to FILE rather than standard output.
B<--rule FILE> file containing the user-defined rules.
B<--config FILE> configuration file containing a list of which rules
you want to run.
B<--nostats> do not print the summary log of actions performed, or list of
suggested fixups.
B<--log FILE> output the stats to this FILE (default = augment.log).
B<--debug LEVEL> print debug info to STDERR (debug level > 3 is not
likely to be of much use (it generates a lot of output))
=head1 SEE ALSO
L<xmltv(5)>
=head1 AUTHOR
Geoff Westcott, honir.at.gmail.dot.com, Dec. 2014.
=cut
use strict;
use XMLTV::Version '$Id: tv_augment,v 1.1 2015/07/12 16:46:09 bilbo_uk Exp $ ';
use Data::Dumper;
use Getopt::Long;
use XMLTV;
use XMLTV::Data::Recursive::Encode;
# simplify testing by also looking for package in current directory
eval 'use XMLTV::Augment';
if ($@ ne '') { eval 'use Augment'; }
use XMLTV::Usage <<END
$0: Augment programme listings with automatic and user-defined rules
$0 [--rule <file>] [--config <file>] [--input <file>] [--output <file>] [--nostats] [--log <file>] [--debug (1-10)]
$0 [-r <file>] [-c <file>] [-i <file>] [-o <file>] [-n] [-l <file>] [-d (1-10)]
END
;
my (
$opt_help,
$opt_input,
$opt_output,
$opt_rule,
$opt_config,
$opt_nostats,
$opt_log,
$opt_debug,
$opt_do,
);
GetOptions(
'h|help' => \$opt_help,
'i|input=s' => \$opt_input,
'o|output=s' => \$opt_output,
'r|rule=s' => \$opt_rule,
'c|config|config-file=s' => \$opt_config,
'n|nostats' => \$opt_nostats,
'l|log=s' => \$opt_log,
'd|debug:i' => \$opt_debug,
'do:i' => \$opt_do,
) or usage(0);
usage(1) if $opt_help;
#rule is now optional if using Supplement via config
# usage(0) if !$opt_rule;
$opt_input = '-' if ( !defined($opt_input) );
#$opt_output = 'STDOUT' if ( !defined($opt_output) );
$opt_debug = 0 if ( !defined($opt_debug) );
my $opt_stats = ( !defined($opt_nostats) ? 1 : !$opt_nostats );
# object construction & open log file
my $augment = new XMLTV::Augment(
'rule' => $opt_rule,
'config' => $opt_config,
'debug' => $opt_debug,
'stats' => $opt_stats,
'log' => $opt_log,
)
|| eval { print STDERR "Failed to create XMLTV::Augment object \n"; exit 1; };
my %w_args = ();
if (defined $opt_output) {
my $fh = new IO::File ">$opt_output";
die "cannot write to $opt_output\n" if not $fh;
%w_args = (OUTPUT => $fh);
}
# our XMLTV::Writer object
my $w;
# store the input file's encoding
my $encoding;
# count of input records
my $in_count = 0;
# parsefiles_callback needs an array
my @files = ( $opt_input );
XMLTV::parsefiles_callback(\&encoding_cb, \&credits_cb, \&channel_cb, \&programme_cb, @files);
# note: we only get a Writer if the encoding callback gets called
if ( $w ) {
$w->end();
}
# log the stats
$augment->printInfo();
# close the log file
$augment->end();
exit(0);
# callbacks used by parsefiles_callback
#
sub encoding_cb( $ ) {
die if defined $w;
$encoding = shift; # callback returns the file's encoding
$w = new XMLTV::Writer(%w_args, encoding => $encoding);
$augment->setEncoding($encoding);
}
#
sub credits_cb( $ ) {
$w->start(shift);
}
#
sub channel_cb( $ ) {
my $ch = shift;
# store the channel details
$augment->inputChannel( $ch );
# write the channel element to the output xml
$w->write_channel($ch);
}
#
sub programme_cb( $ ) {
my $prog = shift;
$in_count++;
# developer's option to only process a few records in input file and then stop
if ( defined($opt_do) && $in_count > $opt_do ) { return; }
# decode the incoming programme
$prog = XMLTV::Data::Recursive::Encode->decode($encoding, $prog);
# augmentProgramme will now do any requested processing of the input xml
$prog = $augment->augmentProgramme( $prog );
# re-code the modified programme back to original encoding
$prog = XMLTV::Data::Recursive::Encode->encode($encoding, $prog);
# output the augmented programme
$w->write_programme($prog);
}
#
|