Discussion:
[PATCH] Download files to sane temporary files
Philipp Matthias Hahn
2014-01-07 08:49:36 UTC
Permalink
Just use fixed file-names instead of using the name from
Content-Disposition header and sanitizing it.

The real name is only needed for extracting the channel group and for
nothing else. (I find the name only useful for debugging and probably
for caching, but this doesn't work with epgdata.com)

Also download directly to a file instead of going through the RAM.
---
tv_grab_eu_epgdata | 24 +++++++++---------------
1 file changed, 9 insertions(+), 15 deletions(-)

diff --git a/tv_grab_eu_epgdata b/tv_grab_eu_epgdata
index dfc73c3..c2bffac 100755
--- a/tv_grab_eu_epgdata
+++ b/tv_grab_eu_epgdata
@@ -326,27 +326,21 @@ sub downloadepg {
my $url = $grabber_baseurl . "index.php?action=sendPackage&iOEM=&pin=$pin&dayOffset=$dataoffset&dataType=xml";
# get file name from content-disposition header
warn "url=$url\n" if $opt->{debug};
- my $response = $ua->request(GET $url);
+ my $filespec = "$tmp/$i.zip";
+ warn 'Downloading zip file for day ', $dataoffset + 1, "\n" unless $opt->{quiet};
+ my $response = $ua->get($url, ':content_file' => $filespec,);

- my $filename = $response->header('Content-Disposition');
+ my $filename = $response->header('Content-Disposition');
unless ($filename) {
warn "No more zip files available for download\n" unless $opt->{quiet};
last;
}
+ warn "filename=$filename\n" if $opt->{debug};
+ ($country) = ($filename =~ /.*filename="[^_]*_[^_]*_([^_]*)_[^_]*/) unless $country; # format: YYYYMMDD_YYYYMMDD_de_qy.zip
+ $expiry_date = $response->header('X-Epgdata-Timeout');
+ $channelgroup = $response->header('X-Epgdata-ChannelGroup');

- $filename =~ s/^.*filename=//;
- $filename = sanitize($filename);
- $expiry_date = $response->{'_headers'}{'x-epgdata-timeout'};
- $channelgroup = sanitize($response->{'_headers'}{'x-epgdata-channelgroup'});
- ($country) = ($filename =~ /[^_]*_[^_]*_([^_]*)_[^_]*/) unless $country; # format: xyz########_########_de_qy.zip
-
- warn "filename=$filename\n" if $opt->{debug};
- warn 'Downloading zip file for day ', $dataoffset + 1, "\n" unless $opt->{quiet};
- open(F,">$tmp" . $filename);
- binmode(F);
- print F $response->content;
- close(F);
- push @filenames, $tmp . $filename;
+ push @filenames, $filespec;
}
warn 'Your PIN will expire around ' . time2str('%C', $expiry_date) . "\n" unless $opt->{quiet};
return unzip(@filenames);
--
1.9.2


--dTy3Mrz/UPE2dbVg--
Loading...