| 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') |
| | 118 | my $data; |
| | 119 | |
| | 120 | if (!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') |
| 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"; |
| 140 | | open (OUT, ">$output_file"); |
| 141 | | print OUT $data; |
| | 161 | open (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 | |
| | 170 | my @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 ]; |
| | 174 | my %xmltv_tags = map { $_ => "" } @xmltv_tag_order; |
| | 175 | my $linenum = 0; |
| | 176 | my $cur_field = ""; |
| | 177 | |
| | 178 | foreach 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 | |