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

@ -83,4 +83,3 @@ def getClientIstance(name):
className = module.api.__class__.__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() run_in = sickbeard.properFinderScheduler.lastRun + sickbeard.properFinderScheduler.cycleTime - datetime.datetime.now()
hours, remainder = divmod(run_in.seconds, 3600) hours, remainder = divmod(run_in.seconds, 3600)
minutes, seconds = divmod(remainder, 60) 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) logger.log(u"Completed the search for new propers%s" % run_at)
@ -136,7 +137,8 @@ class ProperFinder():
# populate our Proper instance # populate our Proper instance
if parse_result.is_anime: 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 continue
else: else:
curProper.season = parse_result.season_number if parse_result.season_number != None else 1 curProper.season = parse_result.season_number if parse_result.season_number != None else 1
@ -149,19 +151,29 @@ class ProperFinder():
logger.DEBUG) logger.DEBUG)
continue continue
if parse_result.show.rls_ignore_words and search.filter_release_name(curProper.name, parse_result.show.rls_ignore_words): if parse_result.show.rls_ignore_words and search.filter_release_name(curProper.name,
logger.log(u"Ignoring " + curProper.name + " based on ignored words filter: " + parse_result.show.rls_ignore_words, parse_result.show.rls_ignore_words):
logger.MESSAGE) logger.log(
u"Ignoring " + curProper.name + " based on ignored words filter: " + parse_result.show.rls_ignore_words,
logger.MESSAGE)
continue continue
if parse_result.show.rls_require_words and not search.filter_release_name(curProper.name, parse_result.show.rls_require_words): if parse_result.show.rls_require_words and not search.filter_release_name(curProper.name,
logger.log(u"Ignoring " + curProper.name + " based on required words filter: " + parse_result.show.rls_require_words, parse_result.show.rls_require_words):
logger.MESSAGE) logger.log(
u"Ignoring " + curProper.name + " based on required words filter: " + parse_result.show.rls_require_words,
logger.MESSAGE)
continue 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) # 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: if oldStatus not in (DOWNLOADED, SNATCHED) or oldQuality != curProper.quality:
continue continue
@ -212,7 +224,7 @@ class ProperFinder():
showObj = helpers.findCertainShow(sickbeard.showList, curProper.indexerid) showObj = helpers.findCertainShow(sickbeard.showList, curProper.indexerid)
if showObj == None: if showObj == None:
logger.log(u"Unable to find the show with indexerid " + str( 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 continue
epObj = showObj.getEpisode(curProper.season, curProper.episode) epObj = showObj.getEpisode(curProper.season, curProper.episode)

View file

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

View file

@ -79,7 +79,6 @@ def _downloadResult(result):
except EnvironmentError, e: except EnvironmentError, e:
logger.log(u"Error trying to save NZB to black hole: " + ex(e), logger.ERROR) logger.log(u"Error trying to save NZB to black hole: " + ex(e), logger.ERROR)
newResult = False newResult = False
elif resProvider.providerType == "torrent": elif resProvider.providerType == "torrent":
newResult = resProvider.downloadResult(result) newResult = resProvider.downloadResult(result)
else: else:
@ -132,7 +131,11 @@ def snatchEpisode(result, endStatus=SNATCHED):
else: else:
# Sets per provider seed ratio # Sets per provider seed ratio
result.ratio = result.provider.seedRatio() 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 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)() client = clients.getClientIstance(sickbeard.TORRENT_METHOD)()
dlResult = client.sendTORRENT(result) dlResult = client.sendTORRENT(result)
else: else: