Fix for KAT gzip issue. Only start torrent search function if at least one provider is enabled.

This commit is contained in:
Remy Varma
2012-01-25 19:45:06 +00:00
parent 7c314a282c
commit d8ceabc7d2
+24 -12
View File
@@ -2,6 +2,9 @@ import urllib, urllib2, urlparse
import lib.feedparser as feedparser import lib.feedparser as feedparser
from xml.dom import minidom from xml.dom import minidom
from xml.parsers.expat import ExpatError from xml.parsers.expat import ExpatError
from StringIO import StringIO
import gzip
import os, re, time import os, re, time
import headphones, exceptions import headphones, exceptions
@@ -82,11 +85,8 @@ def searchforalbum(albumid=None, new=False):
if (headphones.NZBMATRIX or headphones.NEWZNAB or headphones.NZBSORG or headphones.NEWZBIN) and (headphones.SAB_HOST or headphones.BLACKHOLE): if (headphones.NZBMATRIX or headphones.NEWZNAB or headphones.NZBSORG or headphones.NEWZBIN) and (headphones.SAB_HOST or headphones.BLACKHOLE):
foundNZB = searchNZB(albumid, new) foundNZB = searchNZB(albumid, new)
if foundNZB == "none": if (headphones.KAT or headphones.ISOHUNT or headphones.MININOVA) and foundNZB == "none":
searchTorrent(albumid, new) searchTorrent(albumid, new)
def searchNZB(albumid=None, new=False): def searchNZB(albumid=None, new=False):
@@ -600,7 +600,7 @@ def searchTorrent(albumid=None, new=False):
term = re.sub('[\.\-\/]', ' ', term).encode('utf-8') term = re.sub('[\.\-\/]', ' ', term).encode('utf-8')
artistterm = re.sub('[\.\-\/]', ' ', cleanartist).encode('utf-8') artistterm = re.sub('[\.\-\/]', ' ', cleanartist).encode('utf-8')
logger.info("Searching for %s since it was marked as wanted" % term) logger.info("Searching torrents for %s since it was marked as wanted" % term)
resultlist = [] resultlist = []
minimumseeders = int(headphones.NUMBEROFSEEDERS) - 1 minimumseeders = int(headphones.NUMBEROFSEEDERS) - 1
@@ -649,7 +649,6 @@ def searchTorrent(albumid=None, new=False):
title = item.title title = item.title
seeders = item.seeds seeders = item.seeds
url = item.links[1]['url'] url = item.links[1]['url']
url = urllib2.urlopen(url, timeout=30).geturl()
size = int(item.links[1]['length']) size = int(item.links[1]['length'])
try: try:
if format == "2": if format == "2":
@@ -881,19 +880,32 @@ def searchTorrent(albumid=None, new=False):
myDB.action('UPDATE albums SET status = "Snatched" WHERE AlbumID=?', [albums[2]]) myDB.action('UPDATE albums SET status = "Snatched" WHERE AlbumID=?', [albums[2]])
myDB.action('INSERT INTO snatched VALUES( ?, ?, ?, ?, DATETIME("NOW", "localtime"), ?, ?)', [albums[2], bestqual[0], bestqual[1], bestqual[2], "Snatched", torrent_folder_name]) myDB.action('INSERT INTO snatched VALUES( ?, ?, ?, ?, DATETIME("NOW", "localtime"), ?, ?)', [albums[2], bestqual[0], bestqual[1], bestqual[2], "Snatched", torrent_folder_name])
def preprocesstorrent(resultlist): def preprocesstorrent(resultlist):
selresult = "" selresult = ""
for result in resultlist: for result in resultlist:
try: try:
if selresult == "": if selresult == "":
selresult = result selresult = result
torrent = urllib2.urlopen(result[2], timeout=30).read() request = urllib2.Request(result[2])
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()
elif int(selresult[1]) < int(result[1]): elif int(selresult[1]) < int(result[1]):
selresult = result selresult = result
torrent = urllib2.urlopen(result[2], timeout=30).read() request = urllib2.Request(result[2])
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()
except ExpatError: except ExpatError:
logger.error('Unable to torrent file. Skipping.') logger.error('Unable to torrent file. Skipping.')
continue continue