Added back in missing code for finding propers, was removed by mistake.

Fixed issue with torrent clients not snatching due to improper handling of torrent hashes/files.
This commit is contained in:
echel0n 2014-07-27 07:04:37 -07:00
parent f67fa660be
commit 9493a8f7e5
4 changed files with 42 additions and 31 deletions

View File

@ -82,5 +82,4 @@ def getClientIstance(name):
module = getClientModule(name)
className = module.api.__class__.__name__
return getattr(module, className)
return getattr(module, className)

View File

@ -60,7 +60,8 @@ class ProperFinder():
run_in = sickbeard.properFinderScheduler.lastRun + sickbeard.properFinderScheduler.cycleTime - datetime.datetime.now()
hours, remainder = divmod(run_in.seconds, 3600)
minutes, seconds = divmod(remainder, 60)
run_at = u", next check in approx. " + ("%dh, %dm" % (hours, minutes) if 0 < hours else "%dm, %ds" % (minutes, seconds))
run_at = u", next check in approx. " + (
"%dh, %dm" % (hours, minutes) if 0 < hours else "%dm, %ds" % (minutes, seconds))
logger.log(u"Completed the search for new propers%s" % run_at)
@ -136,7 +137,8 @@ class ProperFinder():
# populate our Proper instance
if parse_result.is_anime:
logger.log(u"I am sorry '"+curProper.name+"' seams to be an anime proper seach is not yet suported", logger.DEBUG)
logger.log(u"I am sorry '" + curProper.name + "' seams to be an anime proper seach is not yet suported",
logger.DEBUG)
continue
else:
curProper.season = parse_result.season_number if parse_result.season_number != None else 1
@ -149,19 +151,29 @@ class ProperFinder():
logger.DEBUG)
continue
if parse_result.show.rls_ignore_words and search.filter_release_name(curProper.name, parse_result.show.rls_ignore_words):
logger.log(u"Ignoring " + curProper.name + " based on ignored words filter: " + parse_result.show.rls_ignore_words,
logger.MESSAGE)
if parse_result.show.rls_ignore_words and search.filter_release_name(curProper.name,
parse_result.show.rls_ignore_words):
logger.log(
u"Ignoring " + curProper.name + " based on ignored words filter: " + parse_result.show.rls_ignore_words,
logger.MESSAGE)
continue
if parse_result.show.rls_require_words and not search.filter_release_name(curProper.name, parse_result.show.rls_require_words):
logger.log(u"Ignoring " + curProper.name + " based on required words filter: " + parse_result.show.rls_require_words,
logger.MESSAGE)
if parse_result.show.rls_require_words and not search.filter_release_name(curProper.name,
parse_result.show.rls_require_words):
logger.log(
u"Ignoring " + curProper.name + " based on required words filter: " + parse_result.show.rls_require_words,
logger.MESSAGE)
continue
oldStatus, oldQuality = Quality.splitCompositeStatus(int(sqlResults[0]["status"]))
# check if we actually want this proper (if it's the right quality)
myDB = db.DBConnection()
sqlResults = myDB.select("SELECT status FROM tv_episodes WHERE showid = ? AND season = ? AND episode = ?",
[curProper.indexerid, curProper.season, curProper.episode])
if not sqlResults:
continue
# only keep the proper if we have already retrieved the same quality ep (don't get better/worse ones)
oldStatus, oldQuality = Quality.splitCompositeStatus(int(sqlResults[0]["status"]))
if oldStatus not in (DOWNLOADED, SNATCHED) or oldQuality != curProper.quality:
continue
@ -212,7 +224,7 @@ class ProperFinder():
showObj = helpers.findCertainShow(sickbeard.showList, curProper.indexerid)
if showObj == None:
logger.log(u"Unable to find the show with indexerid " + str(
curProper .indexerid) + " so unable to download the proper", logger.ERROR)
curProper.indexerid) + " so unable to download the proper", logger.ERROR)
continue
epObj = showObj.getEpisode(curProper.season, curProper.episode)

View File

@ -23,7 +23,6 @@ import datetime
import os
import re
import itertools
import Queue
import sickbeard
import requests
@ -34,18 +33,14 @@ from sickbeard import encodingKludge as ek
from sickbeard.exceptions import ex
from sickbeard.name_parser.parser import NameParser, InvalidNameException, InvalidShowException
from sickbeard.common import Quality
from sickbeard import clients
from lib.hachoir_parser import createParser
from hachoir_parser import createParser
class GenericProvider:
NZB = "nzb"
TORRENT = "torrent"
def __init__(self, name):
self.queue = Queue.Queue()
# these need to be set in the subclass
self.providerType = None
self.name = name
@ -63,8 +58,8 @@ class GenericProvider:
self.cache = tvcache.TVCache(self)
self.cookies = None
self.session = requests.session()
self.headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.107 Safari/537.36'}
@ -134,19 +129,22 @@ class GenericProvider:
# check for auth
if not self._doLogin():
return
return False
if self.providerType == GenericProvider.TORRENT:
torrent_hash = re.findall('urn:btih:([\w]{32,40})', result.url)[0].upper()
if not torrent_hash:
logger.log("Unable to extract torrent hash from link: " + ex(result.url), logger.ERROR)
return False
try:
torrent_hash = re.findall('urn:btih:([\w]{32,40})', result.url)[0].upper()
if not torrent_hash:
logger.log("Unable to extract torrent hash from link: " + ex(result.url), logger.ERROR)
return False
urls = [
'http://torcache.net/torrent/' + torrent_hash + '.torrent',
'http://torrage.com/torrent/' + torrent_hash + '.torrent',
'http://zoink.it/torrent/' + torrent_hash + '.torrent',
]
urls = [
'http://torcache.net/torrent/' + torrent_hash + '.torrent',
'http://torrage.com/torrent/' + torrent_hash + '.torrent',
'http://zoink.it/torrent/' + torrent_hash + '.torrent',
]
except:
urls = [result.url]
filename = ek.ek(os.path.join, sickbeard.TORRENT_DIR,
helpers.sanitizeFileName(result.name) + '.' + self.providerType)
@ -155,7 +153,6 @@ class GenericProvider:
filename = ek.ek(os.path.join, sickbeard.NZB_DIR,
helpers.sanitizeFileName(result.name) + '.' + self.providerType)
else:
return

View File

@ -79,7 +79,6 @@ def _downloadResult(result):
except EnvironmentError, e:
logger.log(u"Error trying to save NZB to black hole: " + ex(e), logger.ERROR)
newResult = False
elif resProvider.providerType == "torrent":
newResult = resProvider.downloadResult(result)
else:
@ -132,7 +131,11 @@ def snatchEpisode(result, endStatus=SNATCHED):
else:
# Sets per provider seed ratio
result.ratio = result.provider.seedRatio()
# Gets torrent file contents if not magnet link
result.content = result.provider.getURL(result.url) if not result.url.startswith('magnet') else None
# Snatches torrent with client
client = clients.getClientIstance(sickbeard.TORRENT_METHOD)()
dlResult = client.sendTORRENT(result)
else: