From a1246db22a615b95edeb1196db6ac8ee17f73fab Mon Sep 17 00:00:00 2001 From: mvpossum Date: Sun, 11 May 2014 15:42:18 -0300 Subject: [PATCH] gzip support --- pirate-get.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/pirate-get.py b/pirate-get.py index 749bce4..84c743a 100755 --- a/pirate-get.py +++ b/pirate-get.py @@ -88,12 +88,11 @@ def main(): for page in xrange(pages): request = urllib2.Request(mirror + '/search/' + args.q.replace(" ", "+") + '/' + str(page) + '/7/0') request.add_header('Accept-encoding', 'gzip') - response = urllib2.urlopen(request) - if response.info().get('Content-Encoding') == 'gzip': - buf = StringIO(response.read()) - res = gzip.GzipFile(fileobj=buf).read() - else: - res = response.read() + f = urllib2.urlopen(request) + if f.info().get('Content-Encoding') == 'gzip': + buf = StringIO(f.read()) + f = gzip.GzipFile(fileobj=buf) + res = f.read() found = re.findall(""""(magnet\:\?xt=[^"]*)|([^<]+)""", res) # check for a blocked mirror