- FEATURE: Search engine plugins now handle HTTP protocol gzip compression

This commit is contained in:
Christophe Dumez 2009-11-27 23:46:40 +00:00
parent 3f9b74430a
commit 17b8ba27b3
2 changed files with 13 additions and 2 deletions

View file

@ -21,6 +21,7 @@
- FEATURE: Dropped Qt 4.3 support (Qt >= 4.4 is now required)
- FEATURE: Display close tab button into the tabs in search engine (Qt >= 4.5 only)
- FEATURE: Show official documentation when pressing F1 key
- FEATURE: Search engine plugins now handle HTTP protocol gzip compression
- FEATURE: Announce to all trackers specified for a torrent (µTorrent behavior) (libtorrent >= v0.15 only)
- FEATURE: Added per-torrent super seeding mode (libtorrent >= v0.15 only)
- FEATURE: Support for storing symbolic links in .torrent files (libtorrent >= v0.15 only)

View file

@ -22,7 +22,7 @@
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#VERSION: 1.02
#VERSION: 1.1
# Author:
# Christophe DUMEZ (chris@qbittorrent.org)
@ -31,6 +31,7 @@ import re, htmlentitydefs
import urllib2
import tempfile
import os
import StringIO, gzip, httplib
def htmlentitydecode(s):
# First convert alpha entities (such as é)
@ -66,11 +67,20 @@ def retrieve_url(url):
def download_file(url):
""" Download file at url and write it to a file, return the path to the file and the url """
file, path = tempfile.mkstemp()
file = os.fdopen(file, "wb")
file = os.fdopen(file, "w")
# Download url
req = urllib2.Request(url)
response = urllib2.urlopen(req)
dat = response.read()
# Check if data is gzip encoded
response_info = response.info()
content_encoding = response_info.get('Content-Encoding')
if content_encoding is not None and 'gzip' in content_encoding:
# Data is gzip encoded, decode it
compressedstream = StringIO.StringIO(dat)
gzipper = gzip.GzipFile(fileobj=compressedstream)
extracted_data = gzipper.read()
dat = extracted_data
# Write it to a file
file.write(dat)
file.close()