Changeset 481

Show
Ignore:
Timestamp:
02/01/07 15:29:27 (6 years ago)
Author:
max
Message:

Micrograb support for Rex

Files:
3 modified

Legend:

Unmodified
Added
Removed
  • grabbers/rex

    r423 r481  
    33# "Rex" 
    44 
    5 my $version  = '3.3.9'; 
     5my $version  = '3.4.0'; 
    66 
    77# An Australian TV Guide Grabber (a.k.a. tv_grab_au) 
     
    7171# 3.3.8   : Bugfix : better handling of failed downloads & parses 
    7272# 3.3.9   : Bugfix : more descriptive dies 
     73# 3.4.0   : Feature: micrograbbing (--gaps_file) 
    7374 
    7475use strict; 
     
    8384use JavaScript; 
    8485use Storable; 
    85 use Cwd; 
     86use POSIX; 
    8687 
    8788use XMLTV; 
     
    110111my $channels = {}; 
    111112my $opt_channels = {}; 
     113my $gaps; 
    112114my %chanid; 
    113115my $cached; 
     116my $lastpids; 
    114117my $precache; 
    115118my $ua; 
     
    140143 
    141144read_channels_file(); 
     145read_gaps_file(); 
    142146 
    143147if ($opt->{test}) 
     
    407411  if ($ua) 
    408412  { 
     413     print stats() if ($debug and $opt->{stats}); 
    409414     print "Sleeping...\n" if ($debug); 
    410415     sleep 5 + int(rand(20)); 
     
    652657          if ($start) 
    653658          { 
    654             addme($pid, $title, $start, $pextra); 
     659            addme($pid, $title, $start, $pextra, $curchan); 
    655660            $pextra = undef; 
    656661            $title = undef; 
     
    682687      if ($pid) 
    683688      { 
    684         addme($pid, $title, $start, $pextra); 
     689        addme($pid, $title, $start, $pextra, $curchan); 
    685690      } 
    686691      else 
     
    695700sub addme 
    696701{ 
    697   my ($pid, $title, $start, $pextra) = @_; 
     702  my ($pid, $title, $start, $pextra, $curchan) = @_; 
    698703   
    699704  if ($precache->{$pid}) 
     
    714719                          'sub-title' => $pextra 
    715720                        }; 
     721    my $lastpid = $lastpids->{$curchan}; 
     722    if ($lastpid) 
     723    { 
     724        $precache->{$lastpid}->{stop} = $start; 
     725        if ($start < $precache->{$lastpid}->{start})  
     726        { 
     727            die "Logical error in stop time processing: pid $pid"; 
     728        } 
     729        if ($gaps) 
     730        { 
     731            if (is_outside_gaps($curchan, $precache->{$lastpid}->{start}, $precache->{$lastpid}->{stop})) 
     732            { 
     733                delete $precache->{$lastpid}; 
     734            } 
     735        } 
     736    } 
     737    $lastpids->{$curchan} = $pid; 
    716738  } 
    717739} 
     
    903925} 
    904926 
     927sub is_outside_gaps 
     928{ 
     929  my ($ch, $start, $stop) = @_; 
     930 
     931  $start = udate_to_epoch($start); 
     932  $stop = udate_to_epoch($stop); 
     933 
     934  print "Gap check: $start to $stop vs:\n"; 
     935  foreach my $gap (@{$gaps->{$ch}}) 
     936  { 
     937      if ($gap =~ /(\d+)-(\d+)/) 
     938      { 
     939          print " - $1 - $2\n"; 
     940          return 0 if ($stop > $1 and $start < $2); 
     941      } 
     942  } 
     943  return 1; 
     944} 
     945 
     946sub udate_to_epoch 
     947{ 
     948    my $udate = shift; 
     949 
     950    if ($udate =~ /(\d\d\d\d)(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)/) 
     951    { 
     952        my ($year, $month, $day, $hour, $minute, $second) = ($1, $2, $3, $4, $5, $6); 
     953        $month--; 
     954        $year -= 1900; 
     955        return POSIX::strftime("%s", $second, $minute, $hour, $day, $month, $year); 
     956    } 
     957    die "Unable to parse udate $udate!"; 
     958} 
     959 
    905960sub readjs { 
    906961  my $data = shift; 
     
    915970  
    916971sub read_channels_file  
    917 {    
    918     print "Reading channels file: $opt->{channels_file}\n"; 
    919     if (-r $opt->{channels_file}) 
    920     { 
    921         local (@ARGV, $/) = ($opt->{channels_file}); 
     972{ 
     973    read_config_file('channels', 'channels_file'); 
     974} 
     975 
     976sub read_gaps_file 
     977{ 
     978    read_config_file('gaps', 'gaps_file'); 
     979#    foreach my $ch (keys %$gaps) 
     980#    { 
     981#       foreach my $gap (@{$gaps->{$ch}}) 
     982#       { 
     983#           if ($gap =~ /(\d+)-(\d+)/) 
     984#           { 
     985#               my ($start, $end) = ($1, $2); 
     986#               $gap = epoch 
     987 
     988 
     989} 
     990 
     991sub read_config_file 
     992{ 
     993    my ($name, $arg) = @_; 
     994 
     995    return unless ($opt->{$arg}); 
     996    print "Reading $name file: $opt->{$arg}\n"; 
     997    if (-r $opt->{$arg}) 
     998    { 
     999        local (@ARGV, $/) = ($opt->{$arg}); 
    9221000        no warnings 'all'; 
    9231001        eval <>; 
    924         die "Can't parse channels file: $@" if ($@); 
     1002        die "Can't parse $name file: $@" if ($@); 
    9251003    } 
    9261004    else 
    9271005    { 
    928         print "Unable to read config file.\n"; 
     1006        print "Unable to read $name file.\n"; 
    9291007    } 
    9301008} 
     
    9481026                        config-file=s 
    9491027                        channels_file=s 
     1028                        gaps_file=s 
    9501029                        stats=i 
    9511030                        test 
     
    9801059          "Output file: " . ($opt->{output} ? $opt->{output} : "None") . "\n" . 
    9811060          "Chann file : $opt->{channels_file}\n" . 
     1061          ($opt->{gaps_file} ? "Gaps file  : " . $opt->{gaps_file} . "\n" : '') . 
    9821062          "Statistics : " . ($opt->{stats} ? "every " . $opt->{stats} . " seconds" : "off") . "\n"; 
    9831063  } 
     
    10141094          'region' => 94, 
    10151095          'stats' => 300, 
    1016           'output' => cwd() . '/output.xmltv', 
    1017           'cache-file' => cwd() . '/cache.dat', 
    1018           'channels_file' => cwd() . '/channels.conf' 
     1096          'output' => getcwd() . '/output.xmltv', 
     1097          'cache-file' => getcwd() . '/cache.dat', 
     1098          'channels_file' => getcwd() . '/channels.conf' 
    10191099  }; 
    10201100                                               
     
    10661146    --output <file>        Write XML into the specified file 
    10671147    --channels_file <file> Read channel subscriptions from file 
     1148    --gaps_file <file>     Read gaps from file 
    10681149 
    10691150    --region <n>           Grab data for region code <n> 
  • grabbers/rex.conf

    r453 r481  
    1515                }, 
    1616            'max_runtime' => '240', 
    17             'option_days' => '--days' 
     17            'option_days' => '--days', 
     18            'micrograbs' => 1 
    1819          }; 
  • status

    r480 r481  
    11application     shepherd            0.4.39 
    22grabber         yahoo7widget        1.77 
    3 grabber         rex                 3.3.9-r1 
     3grabber         rex                 3.4.0 
    44grabber         abc_website         2.05 
    55grabber         abc2_website        2.05