1
0
mirror of https://github.com/vikstrous/pirate-get synced 2025-01-10 10:04:21 +01:00

gzip support

This commit is contained in:
mvpossum 2014-05-11 15:37:22 -03:00
parent 380460503b
commit f028c3d50d

View File

@ -12,6 +12,8 @@ import random
from HTMLParser import HTMLParser
import argparse
from pprint import pprint
from StringIO import StringIO
import gzip
class NoRedirection(urllib2.HTTPErrorProcessor):
@ -84,8 +86,14 @@ def main():
# Catch the Ctrl-C exception and exit cleanly
try:
for page in xrange(pages):
f = urllib2.urlopen(mirror + '/search/' + args.q.replace(" ", "+") + '/' + str(page) + '/7/0')
res = f.read()
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()
found = re.findall(""""(magnet\:\?xt=[^"]*)|<td align="right">([^<]+)</td>""", res)
# check for a blocked mirror