/usr/bin/tv_grab_il is in xmltv-util 0.5.69-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 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 | #!/usr/bin/perl -w
=pod
=head1 NAME
tv_grab_il - Grab TV listings for Israel.
=head1 SYNOPSIS
tv_grab_il --help
tv_grab_il --version
tv_grab_il --capabilities
tv_grab_il --description
tv_grab_il [--config-file FILE]
[--days N] [--offset N] [--slow]
[--output FILE] [--quiet] [--debug]
tv_grab_il --configure [--config-file FILE]
tv_grab_il --configure-api [--stage NAME]
[--config-file FILE]
[--output FILE]
tv_grab_il --list-channels [--config-file FILE]
[--output FILE] [--quiet] [--debug]
=head1 DESCRIPTION
Output TV listings in XMLTV format for many channels available in Israel.
The data comes from tv-guide.walla.co.il.
First you must run B<tv_grab_il --configure> to choose which channels
you want to receive.
Then running B<tv_grab_il> with no arguments will get a listings in XML
format for the channels you chose for available days including today.
=head1 OPTIONS
B<--configure> Prompt for which channels to download and write the
configuration file.
B<--config-file FILE> Set the name of the configuration file, the
default is B<~/.xmltv/tv_grab_il.conf>. This is the file written by
B<--configure> and read when grabbing.
B<--output FILE> When grabbing, write output to FILE rather than
standard output.
B<--days N> When grabbing, grab N days rather than all available days.
B<--offset N> Start grabbing at today + N days. N may be negative.
B<--slow> Get programme descriptions as well as title. (Will take a
long time with lots of channels selected.)
B<--quiet> Suppress the progress-bar normally shown on standard error.
B<--debug> Provide more information on progress to stderr to help in
debugging.
B<--list-channels> Write output giving <channel> elements for every
channel available (ignoring the config file), but no programmes.
B<--capabilities> Show which capabilities the grabber supports. For more
information, see L<http://wiki.xmltv.org/index.php/XmltvCapabilities>
B<--version> Show the version of the grabber.
B<--help> Print a help message and exit.
=head1 ERROR HANDLING
If the grabber fails to download data for some channel on a specific day,
it will print an errormessage to STDERR and then continue with the other
channels and days. The grabber will exit with a status code of 1 to indicate
that the data is incomplete.
=head1 ENVIRONMENT VARIABLES
The environment variable HOME can be set to change where configuration
files are stored. All configuration is stored in $HOME/.xmltv/. On Windows,
it might be necessary to set HOME to a path without spaces in it.
=head1 SUPPORTED CHANNELS
For information on supported channels, see http://tv-guide.walla.co.il/
=head1 AUTHOR
lightpriest. This documentation and parts of the code
based on various other tv_grabbers from the XMLTV-project.
=head1 SEE ALSO
L<xmltv(5)>.
=cut
use strict;
use Encode;
use XMLTV::Options qw/ParseOptions/;
use XMLTV::ProgressBar;
use XMLTV::Configure::Writer;
use XMLTV::Get_nice qw(get_nice_tree);
use POSIX qw(strftime);
use DateTime;
# only used while testing the 'slow' option
##$XMLTV::Get_nice::Delay = 0;
##use HTTP::Cache::Transparent;
##HTTP::Cache::Transparent::init( {
## BasePath => '/root/.xmltv/cache',
## NoUpdate => 60*60, # cache time in seconds
## MaxAge => 24, # flush time in hours
## Verbose => 1,
##} );
my $channel_link_regexp = "\\?w=\\/\\/\\/[0-9]*\\/\\/[A-Za-z]*\\/1";
my $channel_link_id = "\\?w=\\/\\/\\/([0-9]*)\\/\\/[A-Za-z]*\\/1";
# Use XMLTV::Options::ParseOptions to parse the options and take care of the basic capabilities that a tv_grabber should
my ($opt, $conf) = ParseOptions({
grabber_name => "tv_grab_il",
version => '$Id: tv_grab_il,v 1.28 2015/06/28 08:40:31 knowledgejunkie Exp $',
capabilities => [qw/baseline manualconfig apiconfig/],
stage_sub => \&config_stage,
listchannels_sub => \&write_channels,
description => "Israel (tv-guide.walla.co.il)",
extra_options => [qw/slow/], # grab descriptions from sub-page
});
sub config_stage {
my ($stage, $conf) = @_;
die "Unknown stage $stage" unless $stage eq "start";
my $result;
my $writer = new XMLTV::Configure::Writer(OUTPUT => \$result, encoding => 'utf-8');
$writer->start({'generator-info-name' => 'tv_grab_il'});
$writer->end('select-channels');
return $result;
}
sub fetch_channels {
my ($opt, $conf) = @_;
my $channels = {};
my $bar = new XMLTV::ProgressBar({
name => "Fetching channels",
count => 1
}) unless ($opt->{quiet} || $opt->{debug});
# Get the page containing the list of channels
my $tree = XMLTV::Get_nice::get_nice_tree('http://tv-guide.walla.co.il', undef, 'windows-1255');
my @channels = $tree->look_down("_tag", "a",
"href", qr/$channel_link_regexp/,
sub { !$_[0]->look_down('_tag', 'img') }
);
$bar->update() && $bar->finish && undef $bar if defined $bar;
$bar = new XMLTV::ProgressBar({
name => "Parsing result",
count => scalar @channels
}) unless ($opt->{quiet} || $opt->{debug});
# Browse through the downloaded list of channels and map them to a hash XMLTV::Writer would understand
foreach my $channel (@channels) {
if ($channel->as_text()) {
my ($id) = $channel->attr('href') =~ /$channel_link_id/;
# Try to fetch the icon
my $icon = $channel->parent();
$icon = $icon->right if $icon;
$icon = $icon->look_down('_tag', 'a', 'href', qr/$channel_link_regexp/) if $icon;
$icon = $icon->look_down('_tag', 'img') if $icon;
$icon = $icon->attr('src') if $icon;
$channels->{"$id.tv-guide.walla.co.il"} = {
id => "$id.tv-guide.walla.co.il",
'display-name' => [[ encode( 'utf-8', $channel->as_text()) ]],
url => [ $channel->attr('href') ]
};
$channels->{"$id.tv-guide.walla.co.il"}->{icon} = [ {src => ($icon || '')} ] if ($icon)
}
$bar->update() if defined $bar;
}
$bar->finish() && undef $bar if defined $bar;
# Notifying the user :)
$bar = new XMLTV::ProgressBar({
name => "Reformatting",
count => 1
}) unless ($opt->{quiet} || $opt->{debug});
$bar->update() && $bar->finish() if defined $bar;
return $channels;
}
sub write_channels {
my $channels = fetch_channels($opt, $conf);
# Let XMLTV::Writer format the results as a valid xmltv file
my $result;
my $writer = new XMLTV::Writer(OUTPUT => \$result, encoding => 'utf-8');
$writer->start({'generator-info-name' => 'tv_grab_il'});
$writer->write_channels($channels);
$writer->end();
return $result;
}
# Fetch the channels again to see what's available
my $channels = fetch_channels($opt, $conf);
# Configure initial elements for XMLTV::Writer
#
# Create a new hash for the channels so that channels without programmes
# won't appear in the final XML
my $encoding = 'UTF-8';
my $credits = {'generator-info-name' => 'tv_grab_il'};
my $w_channels = {};
my $programmes = [];
# Progress Bar :)
my $bar = new XMLTV::ProgressBar({
name => "Fetching channels listings",
count => (scalar @{$conf->{channel}}) * $opt->{days}
}) unless ($opt->{quiet} || $opt->{debug});
# Fetch listings per channel
foreach my $channel_id (@{$conf->{channel}}) {
# Check each channel still exists in walla's channels page
if ($channels->{$channel_id}) {
my ($walla_id) = ($channel_id =~ /^([0-9]*)\..*$/);
# Now grab listings for each channel on each day, according to the options in $opt
for (my $i=$opt->{offset}; $i < ($opt->{offset} + $opt->{days}); $i++) {
my $theday = DateTime->today()->add (days => $i)->set_time_zone('Asia/Jerusalem');
my $url = "http://tv-guide.walla.co.il/?w=/4//$walla_id//" . $theday->day_name() . "/1";
my $tree = XMLTV::Get_nice::get_nice_tree($url, undef, 'windows-1255');
if ($tree) {
my @shows = $tree->look_down('_tag', 'table', 'width', '100%', 'dir', 'ltr', 'cellpadding', '2', 'border', '0');
if (@shows) {
foreach my $show (@shows) {
my $title = $show->look_down('_tag', 'a', 'class', 'w3b');
my $show_hour_element = $show->look_down('_tag', 'span', 'class', 'w3b txt-w');
my @show_hour = split(/:/, $show_hour_element->as_text());
my $show_time = $theday->clone();
if ($show_hour[0] < 6) {
$show_time->add (days => 1);
}
$show_time->set(hour => $show_hour[0], minute => $show_hour[1], second => 0);
# If user wants descriptions then get them from the sub-page
# (can also get stop time while we're there!)
my ($start, $stop, $desc) = ('', '', ''); my $stop_time;
if ( defined $opt->{slow} && $opt->{slow} ) {
if ( my $detailtree = XMLTV::Get_nice::get_nice_tree('http://tv-guide.walla.co.il/'.$title->attr('href'), undef, 'windows-1255') ) {
if ( my $table = $detailtree->look_down('_tag', 'table', 'class', 'wp-0-b') ) { # get 1st "wp-0-b" table
if ( my $td = $table->look_down('_tag', 'td', 'class', 'w2b', sub{ !$_[0]->look_down('_tag', 'h2') } ) ) {
($start, $stop) = $td->as_text() =~ /(\d\d:\d\d).*(\d\d:\d\d)/;
}
if ( my $td = $table->look_down('_tag', 'td', 'class', 'w3') ) {
$desc = $td->as_text();
}
}
}
if ( $stop ne '' ) {
my @stop_hour = split(/:/, $stop);
$stop_time = $show_time->clone();
$stop_time->add (days => 1) if ( $stop_hour[0] < $show_hour[0] ); # assumes prog not last > 24hours!
$stop_time->set(hour => $stop_hour[0], minute => $stop_hour[1], second => 0);
}
}
my $prog= {
start => $show_time->strftime("%Y%m%d%H%M%S %z"),
title => [[ encode( 'utf-8', $title->as_text()) ]],
channel => $channel_id
};
$prog->{'stop'} = $stop_time->strftime("%Y%m%d%H%M%S %z") if defined $stop_time;
$prog->{'desc'} = [[ encode( 'utf-8', $desc) ]] if $desc ne '';
push @{$programmes}, $prog;
}
# Add this channel to the finalized XML
$w_channels->{$channel_id} = $channels->{$channel_id} unless $w_channels->{$channel_id};
} else {
}
} else {
}
$bar->update if defined $bar;
}
}
}
$bar->finish() && undef $bar if defined $bar;
my %w_args;
if (($opt->{offset} != 0) || ($opt->{days} != -999)) {
$w_args{offset} = $opt->{offset};
$w_args{days} = ($opt->{days} == -999) ? 100 : $opt->{days};
$w_args{cutoff} = '060000';
}
my $data = [];
$data->[0] = $encoding;
$data->[1] = $credits;
$data->[2] = $w_channels;
$data->[3] = $programmes;
XMLTV::write_data($data, %w_args);
|