Changeset 346

Show
Ignore:
Timestamp:
12/09/06 18:30:15 (6 years ago)
Author:
lincoln
Message:

clean up xmltv downloaded from oztivo to make XMLTV.pm happy

Files:
2 modified

Legend:

Unmodified
Added
Removed
  • grabbers/oztivo

    r328 r346  
    33# OzTivo grabber 
    44 
    5 my $version = '0.11'; 
     5my $version = '0.12'; 
    66 
    77# Requires configuration! 
     
    2323# 0.10  : Minor internal changes to be more forkable 
    2424# 0.11  : Exit on empty config file 
     25# 0.12  : oztivo has invalid XMLTV (fields in wrong order, empty fields etc) 
     26#         postprocess these 
    2527 
    2628use strict; 
     
    4143my $ready; 
    4244my $configure; 
     45my $raw_input; 
     46my $raw_output; 
    4347 
    4448print "$nicename Grabber v$version\n"; 
     
    4953            'channels_file=s'   => \$channels_file, 
    5054            'output=s'          => \$output_file, 
     55            'rawoutput=s'       => \$raw_output, 
     56            'rawinput=s'        => \$raw_input, 
    5157            'version'           => \$ver, 
    5258            'ready'             => \$ready, 
     
    110116$fn =~ s/YOURPASSWORD/$pw/; 
    111117 
    112 my $response = $ua->get($fn); 
    113 unless ($response->is_success()) 
    114 { 
    115     print "Download failed.\n" . $response->status_line() . "\nExiting.\n"; 
    116     exit; 
    117 } 
    118 my $data = $response->content(); 
    119 print "Downloaded " . int((do {use bytes; length($data)}) / 1024) . "KB.\n"; 
    120  
    121 if ($response->header('Content-Encoding') 
     118my $data; 
     119 
     120if (!defined $raw_input) { 
     121    my $response = $ua->get($fn); 
     122    unless ($response->is_success()) { 
     123        print "Download failed.\n" . $response->status_line() . "\nExiting.\n"; 
     124        exit; 
     125    } 
     126    $data = $response->content(); 
     127    print "Downloaded " . int((do {use bytes; length($data)}) / 1024) . "KB.\n"; 
     128 
     129    if ($response->header('Content-Encoding') 
    122130        and 
    123     $response->header('Content-Encoding') eq 'gzip') 
    124 { 
    125     print "Unzipping.\n"; 
    126     $data = Compress::Zlib::memGunzip($data); 
    127     #$data = Compress::Zlib::memGunzip($response->content()); 
     131        $response->header('Content-Encoding') eq 'gzip') { 
     132        print "Unzipping.\n"; 
     133        $data = Compress::Zlib::memGunzip($data); 
     134    } 
     135 
     136    if (defined $raw_output) { 
     137        open(F,">$raw_output") || die "could not write raw output to $raw_output: $!\n"; 
     138        print F $data; 
     139        close(F); 
     140        print "Raw output saved in $raw_output.\n"; 
     141    } 
     142} else { 
     143    open(F,"<$raw_input") || die "could not read raw input from $raw_input: $!\n"; 
     144    while(<F>) { 
     145        $data .= $_; 
     146    } 
     147    close(F); 
     148    print "Raw input read from $raw_input.\n"; 
    128149} 
    129150 
     
    138159 
    139160print "Writing output.\n"; 
    140 open (OUT, ">$output_file"); 
    141 print OUT $data; 
     161open (OUT, ">$output_file") || die "could not write to $output_file: $!\n"; 
     162 
     163# 
     164# oztivo generates invalid XMLTV with fields out of order and 
     165# some blank fields. 
     166# the standard XMLTV.pm perl module gets very unhappy about these 
     167# write output in a manner which addresses the bad input 
     168# 
     169 
     170my @xmltv_tag_order = qw [ title sub-title desc credits date category language 
     171        orig-language length icon url country episode-num video audio 
     172        previously-shown permiere last-chance new subtitles rating 
     173        star-rating ]; 
     174my %xmltv_tags = map { $_ => "" } @xmltv_tag_order; 
     175my $linenum = 0; 
     176my $cur_field = ""; 
     177 
     178foreach my $line (split/\n/,$data) { 
     179    $linenum++; 
     180 
     181    # oztivo generates blank data for these fields - skip if blank 
     182    next if ($line =~ /<director><\/director>/); 
     183    next if ($line =~ /<desc><\/desc>/); 
     184 
     185    if ($line =~ /\s*<([\/a-zA-Z\-]+)/) { 
     186        my $field = lc($1); 
     187 
     188        if (($field eq "programme") || ($field eq "/programme")) { 
     189            # print all previously seen tags in xmltv_tag_order 
     190            foreach my $xmltag (@xmltv_tag_order) { 
     191                if ($xmltv_tags{$xmltag} ne "") { 
     192                    print OUT $xmltv_tags{$xmltag}; 
     193                    $xmltv_tags{$xmltag} = ""; 
     194                } 
     195            } 
     196            print OUT $line."\n"; # programme tag 
     197            $cur_field = ""; 
     198        } else { 
     199            # do we know about this tag? 
     200            $cur_field = $field if (defined $xmltv_tags{$field}); 
     201 
     202            if ($cur_field eq "") { 
     203                print OUT $line."\n"; 
     204            } else { 
     205                $xmltv_tags{$cur_field} .= $line."\n"; 
     206            } 
     207        } 
     208    } else { 
     209        print OUT $line."\n"; 
     210    } 
     211}  
     212 
    142213close OUT; 
    143214 
  • status

    r345 r346  
    55grabber         abc2_website        2.03 
    66grabber         sbsnews_website     0.03 
    7 grabber         oztivo              0.11 
     7grabber         oztivo              0.12 
    88grabber         jrobbo              0.04-r4 
    99grabber         d1                  0.6.2.4-r3