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

Merge pull request #21 from mvpossum/master

Gzip Support
This commit is contained in:
Viktor Stanchev 2014-05-11 14:54:41 -04:00
commit 7f8ed245a9

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,7 +86,12 @@ 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')
request = urllib2.Request(mirror + '/search/' + args.q.replace(" ", "+") + '/' + str(page) + '/7/0')
request.add_header('Accept-encoding', 'gzip')
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=[^"]*)|<td align="right">([^<]+)</td>""", res)