From a3ce3b110cd01dc984ee38587208b5527bf891f8 Mon Sep 17 00:00:00 2001 From: MageMinds Date: Thu, 26 Jan 2012 09:20:28 -0500 Subject: [PATCH] Update headphones/searcher.py --- headphones/searcher.py | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/headphones/searcher.py b/headphones/searcher.py index ff4b3e73..de919fe9 100644 --- a/headphones/searcher.py +++ b/headphones/searcher.py @@ -651,7 +651,15 @@ def searchTorrent(albumid=None, new=False): size = int(item.links[1]['length']) try: if format == "2": - torrent = urllib2.urlopen(url, timeout=30).read() + request = urllib2.Request(url) + request.add_header('Accept-encoding', 'gzip') + response = urllib2.urlopen(request) + if response.info().get('Content-Encoding') == 'gzip': + buf = StringIO( response.read()) + f = gzip.GzipFile(fileobj=buf) + torrent = f.read() + else: + torrent = response.read() if int(torrent.find(".mp3")) > 0 and int(torrent.find(".flac")) < 1: rightformat = False except Exception, e: @@ -716,7 +724,15 @@ def searchTorrent(albumid=None, new=False): size = int(item.links[1]['length']) try: if format == "2": - torrent = urllib2.urlopen(url, timeout=30).read() + request = urllib2.Request(url) + request.add_header('Accept-encoding', 'gzip') + response = urllib2.urlopen(request) + if response.info().get('Content-Encoding') == 'gzip': + buf = StringIO( response.read()) + f = gzip.GzipFile(fileobj=buf) + torrent = f.read() + else: + torrent = response.read() if int(torrent.find(".mp3")) > 0 and int(torrent.find(".flac")) < 1: rightformat = False except Exception, e: @@ -775,7 +791,15 @@ def searchTorrent(albumid=None, new=False): size = int(item.links[1]['length']) try: if format == "2": - torrent = urllib2.urlopen(url, timeout=30).read() + request = urllib2.Request(url) + request.add_header('Accept-encoding', 'gzip') + response = urllib2.urlopen(request) + if response.info().get('Content-Encoding') == 'gzip': + buf = StringIO( response.read()) + f = gzip.GzipFile(fileobj=buf) + torrent = f.read() + else: + torrent = response.read() if int(torrent.find(".mp3")) > 0 and int(torrent.find(".flac")) < 1: rightformat = False except Exception, e: