Browse Source

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

adaptive-webui-19844
Christophe Dumez 15 years ago
parent
commit
17b8ba27b3
  1. 1
      Changelog
  2. 14
      src/search_engine/helpers.py

1
Changelog

@ -21,6 +21,7 @@
- FEATURE: Dropped Qt 4.3 support (Qt >= 4.4 is now required) - 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: Display close tab button into the tabs in search engine (Qt >= 4.5 only)
- FEATURE: Show official documentation when pressing F1 key - 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: 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: Added per-torrent super seeding mode (libtorrent >= v0.15 only)
- FEATURE: Support for storing symbolic links in .torrent files (libtorrent >= v0.15 only) - FEATURE: Support for storing symbolic links in .torrent files (libtorrent >= v0.15 only)

14
src/search_engine/helpers.py

@ -22,7 +22,7 @@
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE. # POSSIBILITY OF SUCH DAMAGE.
#VERSION: 1.02 #VERSION: 1.1
# Author: # Author:
# Christophe DUMEZ (chris@qbittorrent.org) # Christophe DUMEZ (chris@qbittorrent.org)
@ -31,6 +31,7 @@ import re, htmlentitydefs
import urllib2 import urllib2
import tempfile import tempfile
import os import os
import StringIO, gzip, httplib
def htmlentitydecode(s): def htmlentitydecode(s):
# First convert alpha entities (such as é) # First convert alpha entities (such as é)
@ -66,11 +67,20 @@ def retrieve_url(url):
def download_file(url): def download_file(url):
""" Download file at url and write it to a file, return the path to the file and the 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, path = tempfile.mkstemp()
file = os.fdopen(file, "wb") file = os.fdopen(file, "w")
# Download url # Download url
req = urllib2.Request(url) req = urllib2.Request(url)
response = urllib2.urlopen(req) response = urllib2.urlopen(req)
dat = response.read() 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 # Write it to a file
file.write(dat) file.write(dat)
file.close() file.close()

Loading…
Cancel
Save