Changeset 787 for grabbers/oztivo

Show
Ignore:
Timestamp:
06/21/07 06:51:03 (6 years ago)
Author:
paul
Message:

oztivo: checks for messages and retries

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • grabbers/oztivo

    r786 r787  
    33# OzTivo grabber 
    44 
    5 my $version = '1.01'; 
     5my $version = '1.02'; 
    66 
    77# Requires configuration! 
     
    114114if (!defined $raw_input) { 
    115115    my ($success, $status); 
    116     ($data, $success, $status) = Shepherd::Common::get_url(url => "http://$user:$pw\@minnie.tuhs.org/tivo-bin/xmlguide.pl", retries => 5, retry_delay => 20); 
    117     unless ($success) 
    118     { 
    119         if ($status =~ /401/) 
    120         { 
    121             print "Your OzTivo username and/or password may be incorrect!\n". 
    122                   "The username and password you supplied when configuring the oztivo grabber\n" . 
    123                   "must match your registration details on the OzTivo.com site.\n". 
    124                   "If this error persists, try reconfiguring: ". 
    125                   "  tv_grab_au --configure $progname\n"; 
    126             print "Download failed: $status\n"; 
    127         } 
    128         exit 5; 
     116    foreach my $tries (1 .. 3) { 
     117        ($data, $success, $status) = Shepherd::Common::get_url( 
     118                url => "http://$user:$pw\@minnie.tuhs.org/tivo-bin/xmlguide.pl", 
     119                retries => 5, retry_delay => 20); 
     120 
     121        unless ($success) 
     122        { 
     123            if ($status =~ /401/) 
     124            { 
     125                print "Your OzTivo username and/or password may be incorrect!\n". 
     126                        "The username and password you supplied when configuring the oztivo grabber\n" . 
     127                        "must match your registration details on the OzTivo.com site.\n". 
     128                        "If this error persists, try reconfiguring: ". 
     129                        "  tv_grab_au --configure $progname\n"; 
     130            } 
     131            print "Download failed: $status\n"; 
     132            exit 5; 
     133        } 
     134 
     135        my $bytes = do { use bytes; length($data) }; 
     136        last if $bytes > 1000 or $data !~ /<message>/i; 
     137        $data =~ /<message>(.*?)<\/message>/si; 
     138        print "OzTivo message: $1\n"; 
     139        exit 6 if $tries == 3; 
     140        my $sleep = int(30 + rand(30)); 
     141        print "Sleeping for $sleep\n"; 
     142        sleep($sleep); 
    129143    } 
    130144 
    131145    if (defined $raw_output) { 
    132         open(F,">$raw_output") || die "could not write raw output to $raw_output: $!\n"; 
    133         print F $data; 
    134         close(F); 
    135         print "Raw output saved in $raw_output.\n"; 
     146        open(F,">$raw_output") || die "could not write raw output to $raw_output: $!\n"; 
     147        print F $data; 
     148        close(F); 
     149        print "Raw output saved in $raw_output.\n"; 
    136150    } 
    137151} else { 
    138152    open(F,"<$raw_input") || die "could not read raw input from $raw_input: $!\n"; 
    139153    while(<F>) { 
    140         $data .= $_; 
     154        $data .= $_; 
    141155    } 
    142156    close(F);