Improved find propers code.

Backlog and manual searches now check cache first for search results.
This commit is contained in:
echel0n 2014-05-30 00:36:47 -07:00
parent 1abef89b29
commit f01c5852d4
13 changed files with 114 additions and 162 deletions

View file

@ -76,6 +76,7 @@ class FailedProcessor(object):
raise exceptions.FailedProcessingFailed()
segment = {parsed.season_number:[]}
for episode in parsed.episode_numbers:
epObj = parsed.show.getEpisode(parsed.season_number, episode)
segment[parsed.season_number].append(epObj)

View file

@ -116,11 +116,10 @@ class ProperFinder():
sortedPropers = sorted(propers.values(), key=operator.attrgetter('date'), reverse=True)
finalPropers = []
for curProper in sortedPropers:
in_cache = False
try:
myParser = NameParser(False)
parse_result = myParser.parse(curProper.name)
parse_result = myParser.parse(curProper.name).convert()
except InvalidNameException:
logger.log(u"Unable to parse the filename " + curProper.name + " into a valid episode", logger.DEBUG)
continue
@ -128,37 +127,26 @@ class ProperFinder():
if not parse_result.series_name:
continue
cacheResult = sickbeard.name_cache.retrieveNameFromCache(parse_result.series_name)
if cacheResult:
in_cache = True
curProper.indexerid = int(cacheResult)
elif cacheResult == 0:
return None
if not curProper.indexerid:
showResult = helpers.searchDBForShow(parse_result.series_name)
if showResult:
curProper.indexerid = int(showResult[0])
if not curProper.indexerid:
for curShow in sickbeard.showList:
if show_name_helpers.isGoodResult(curProper.name, curShow, False):
curProper.indexerid = curShow.indexerid
break
if not parse_result.show:
sickbeard.name_cache.addNameToCache(parse_result.series_name, 0)
continue
if not in_cache:
sickbeard.name_cache.addNameToCache(parse_result.series_name, parse_result.show.indexerid)
if not parse_result.episode_numbers:
logger.log(
u"Ignoring " + curProper.name + " because it's for a full season rather than specific episode",
logger.DEBUG)
continue
showObj = parse_result.show
logger.log(
u"Successful match! Result " + parse_result.series_name + " matched to show " + showObj.name,
logger.DEBUG)
# set the indexerid in the db to the show's indexerid
curProper.indexerid = showObj.indexerid
# set the indexer in the db to the show's indexer
curProper.indexer = showObj.indexer
# populate our Proper instance
if parse_result.air_by_date or parse_result.sports:
curProper.season = -1
@ -167,53 +155,17 @@ class ProperFinder():
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)
continue
curProper.episode = parse_result.ab_episode_numbers[0]
else:
curProper.season = parse_result.season_number if parse_result.season_number != None else 1
curProper.episode = parse_result.episode_numbers[0]
curProper.quality = Quality.nameQuality(curProper.name, parse_result.is_anime)
# for each show in our list
for curShow in sickbeard.showList:
genericName = self._genericName(parse_result.series_name)
# get the scene name masks
sceneNames = set(show_name_helpers.makeSceneShowSearchStrings(curShow))
# for each scene name mask
for curSceneName in sceneNames:
# if it matches
if genericName == self._genericName(curSceneName):
logger.log(
u"Successful match! Result " + parse_result.series_name + " matched to show " + curShow.name,
logger.DEBUG)
# set the indexerid in the db to the show's indexerid
curProper.indexerid = curShow.indexerid
# set the indexer in the db to the show's indexer
curProper.indexer = curShow.indexer
# since we found it, break out
break
# if we found something in the inner for loop break out of this one
if curProper.indexerid != -1:
break
if not show_name_helpers.filterBadReleases(curProper.name):
logger.log(u"Proper " + curProper.name + " isn't a valid scene release that we want, igoring it",
logger.DEBUG)
continue
showObj = helpers.findCertainShow(sickbeard.showList, curProper.indexerid)
if not showObj:
logger.log(u"Unable to find the show with indexerID " + str(curProper.indexerid), logger.ERROR)
continue
if showObj.rls_ignore_words and search.filter_release_name(curProper.name, showObj.rls_ignore_words):
logger.log(u"Ignoring " + curProper.name + " based on ignored words filter: " + showObj.rls_ignore_words,
logger.MESSAGE)

View file

@ -248,21 +248,15 @@ class GenericProvider:
# mark season searched for season pack searches so we can skip later on
searched_scene_season = epObj.scene_season
if not epObj.show.air_by_date:
if epObj.scene_season == 0 or epObj.scene_episode == 0:
logger.log(
u"Incomplete Indexer <-> Scene mapping detected for " + epObj.prettyName() + ", skipping search!")
continue
# cacheResult = self.cache.searchCache([epObj], manualSearch)
#if len(cacheResult):
# results.update({epObj.episode:cacheResult[epObj]})
# continue
if search_mode == 'sponly':
for curString in self._get_season_search_strings(epObj):
itemList += self._doSearch(curString, len(episodes))
else:
cacheResult = self.cache.searchCache([epObj], manualSearch)
if len(cacheResult):
results.update({epObj.episode: cacheResult[epObj]})
continue
for curString in self._get_episode_search_strings(epObj):
itemList += self._doSearch(curString, len(episodes))
@ -271,12 +265,11 @@ class GenericProvider:
continue
# remove duplicate items
#itemList = [i for n, i in enumerate(itemList) if i not in itemList[n + 1:]]
searchItems[epObj] = itemList
#if we have cached results return them.
# if len(results):
# return results
if len(results):
return results
for ep_obj in searchItems:
for item in searchItems[ep_obj]:

View file

@ -261,9 +261,9 @@ class IPTorrentsProvider(generic.TorrentProvider):
return []
for sqlshow in sqlResults:
self.show = curshow = helpers.findCertainShow(sickbeard.showList, int(sqlshow["showid"]))
if not self.show: continue
curEp = curshow.getEpisode(int(sqlshow["season"]), int(sqlshow["episode"]))
self.show = helpers.findCertainShow(sickbeard.showList, int(sqlshow["showid"]))
if self.show:
curEp = self.show.getEpisode(int(sqlshow["season"]), int(sqlshow["episode"]))
searchString = self._get_episode_search_strings(curEp, add_string='PROPER|REPACK')
for item in self._doSearch(searchString[0]):

View file

@ -397,9 +397,9 @@ class KATProvider(generic.TorrentProvider):
return []
for sqlshow in sqlResults:
self.show = curshow = helpers.findCertainShow(sickbeard.showList, int(sqlshow["showid"]))
if not self.show: continue
curEp = curshow.getEpisode(int(sqlshow["season"]), int(sqlshow["episode"]))
self.show = helpers.findCertainShow(sickbeard.showList, int(sqlshow["showid"]))
if self.show:
curEp = self.show.getEpisode(int(sqlshow["season"]), int(sqlshow["episode"]))
searchString = self._get_episode_search_strings(curEp, add_string='PROPER|REPACK')

View file

@ -309,9 +309,9 @@ class NextGenProvider(generic.TorrentProvider):
return []
for sqlshow in sqlResults:
self.show = curshow = helpers.findCertainShow(sickbeard.showList, int(sqlshow["showid"]))
if not self.show: continue
curEp = curshow.getEpisode(int(sqlshow["season"]), int(sqlshow["episode"]))
self.show = helpers.findCertainShow(sickbeard.showList, int(sqlshow["showid"]))
if self.show:
curEp = self.show.getEpisode(int(sqlshow["season"]), int(sqlshow["episode"]))
searchString = self._get_episode_search_strings(curEp, add_string='PROPER|REPACK')
for item in self._doSearch(searchString[0]):

View file

@ -288,9 +288,9 @@ class PublicHDProvider(generic.TorrentProvider):
return []
for sqlshow in sqlResults:
self.show = curshow = helpers.findCertainShow(sickbeard.showList, int(sqlshow["showid"]))
if not self.show: continue
curEp = curshow.getEpisode(int(sqlshow["season"]), int(sqlshow["episode"]))
self.show = helpers.findCertainShow(sickbeard.showList, int(sqlshow["showid"]))
if self.show:
curEp = self.show.getEpisode(int(sqlshow["season"]), int(sqlshow["episode"]))
searchString = self._get_episode_search_strings(curEp, add_string='PROPER|REPACK')

View file

@ -303,9 +303,9 @@ class SCCProvider(generic.TorrentProvider):
return []
for sqlshow in sqlResults:
self.show = curshow = helpers.findCertainShow(sickbeard.showList, int(sqlshow["showid"]))
if not self.show: continue
curEp = curshow.getEpisode(int(sqlshow["season"]), int(sqlshow["episode"]))
self.show = helpers.findCertainShow(sickbeard.showList, int(sqlshow["showid"]))
if self.show:
curEp = self.show.getEpisode(int(sqlshow["season"]), int(sqlshow["episode"]))
searchString = self._get_episode_search_strings(curEp, add_string='PROPER|REPACK')

View file

@ -37,8 +37,8 @@ from lib import requests
from lib.requests import exceptions
from sickbeard.helpers import sanitizeSceneName
class SpeedCDProvider(generic.TorrentProvider):
class SpeedCDProvider(generic.TorrentProvider):
urls = {'base_url': 'http://speed.cd/',
'login': 'http://speed.cd/takelogin.php',
'detail': 'http://speed.cd/t/%s',
@ -131,7 +131,8 @@ class SpeedCDProvider(generic.TorrentProvider):
else:
for show_name in set(show_name_helpers.allPossibleShowNames(self.show)):
ep_string = show_name_helpers.sanitizeSceneName(show_name) + ' ' + \
sickbeard.config.naming_ep_type[2] % {'seasonnumber': ep_obj.scene_season, 'episodenumber': ep_obj.scene_episode}
sickbeard.config.naming_ep_type[2] % {'seasonnumber': ep_obj.scene_season,
'episodenumber': ep_obj.scene_episode}
search_string['Episode'].append(re.sub('\s+', ' ', ep_string))
@ -152,7 +153,8 @@ class SpeedCDProvider(generic.TorrentProvider):
search_string = '+'.join(search_string.split())
post_data = dict({'/browse.php?' : None, 'cata': 'yes','jxt': 4,'jxw': 'b','search': search_string}, **self.categories[mode])
post_data = dict({'/browse.php?': None, 'cata': 'yes', 'jxt': 4, 'jxw': 'b', 'search': search_string},
**self.categories[mode])
data = self.session.post(self.urls['search'], data=post_data).json()
@ -220,7 +222,8 @@ class SpeedCDProvider(generic.TorrentProvider):
return None
if r.status_code != 200:
logger.log(self.name + u" page requested with url " + url +" returned status code is " + str(r.status_code) + ': ' + clients.http_error_code[r.status_code], logger.WARNING)
logger.log(self.name + u" page requested with url " + url + " returned status code is " + str(
r.status_code) + ': ' + clients.http_error_code[r.status_code], logger.WARNING)
return None
return r.content
@ -229,7 +232,8 @@ class SpeedCDProvider(generic.TorrentProvider):
results = []
sqlResults = db.DBConnection().select('SELECT s.show_name, e.showid, e.season, e.episode, e.status, e.airdate FROM tv_episodes AS e' +
sqlResults = db.DBConnection().select(
'SELECT s.show_name, e.showid, e.season, e.episode, e.status, e.airdate FROM tv_episodes AS e' +
' INNER JOIN tv_shows AS s ON (e.showid = s.indexer_id)' +
' WHERE e.airdate >= ' + str(search_date.toordinal()) +
' AND (e.status IN (' + ','.join([str(x) for x in Quality.DOWNLOADED]) + ')' +
@ -239,9 +243,9 @@ class SpeedCDProvider(generic.TorrentProvider):
return []
for sqlshow in sqlResults:
self.show = curshow = helpers.findCertainShow(sickbeard.showList, int(sqlshow["showid"]))
if not self.show: continue
curEp = curshow.getEpisode(int(sqlshow["season"]), int(sqlshow["episode"]))
self.show = helpers.findCertainShow(sickbeard.showList, int(sqlshow["showid"]))
if self.show:
curEp = self.show.getEpisode(int(sqlshow["season"]), int(sqlshow["episode"]))
searchString = self._get_episode_search_strings(curEp, add_string='PROPER|REPACK')
@ -254,8 +258,8 @@ class SpeedCDProvider(generic.TorrentProvider):
def seedRatio(self):
return self.ratio
class SpeedCDCache(tvcache.TVCache):
class SpeedCDCache(tvcache.TVCache):
def __init__(self, provider):
tvcache.TVCache.__init__(self, provider)
@ -302,5 +306,6 @@ class SpeedCDCache(tvcache.TVCache):
return self._addCacheEntry(title, url)
provider = SpeedCDProvider()

View file

@ -377,9 +377,10 @@ class ThePirateBayProvider(generic.TorrentProvider):
return []
for sqlshow in sqlResults:
self.show = curshow = helpers.findCertainShow(sickbeard.showList, int(sqlshow["showid"]))
if not self.show: continue
curEp = curshow.getEpisode(int(sqlshow["season"]), int(sqlshow["episode"]))
self.show = helpers.findCertainShow(sickbeard.showList, int(sqlshow["showid"]))
if self.show:
curEp = self.show.getEpisode(int(sqlshow["season"]), int(sqlshow["episode"]))
searchString = self._get_episode_search_strings(curEp, add_string='PROPER|REPACK')

View file

@ -266,9 +266,9 @@ class TorrentDayProvider(generic.TorrentProvider):
return []
for sqlshow in sqlResults:
self.show = curshow = helpers.findCertainShow(sickbeard.showList, int(sqlshow["showid"]))
if not self.show: continue
curEp = curshow.getEpisode(int(sqlshow["season"]), int(sqlshow["episode"]))
self.show = helpers.findCertainShow(sickbeard.showList, int(sqlshow["showid"]))
if self.show:
curEp = self.show.getEpisode(int(sqlshow["season"]), int(sqlshow["episode"]))
searchString = self._get_episode_search_strings(curEp, add_string='PROPER|REPACK')

View file

@ -262,9 +262,9 @@ class TorrentLeechProvider(generic.TorrentProvider):
return []
for sqlshow in sqlResults:
self.show = curshow = helpers.findCertainShow(sickbeard.showList, int(sqlshow["showid"]))
if not self.show: continue
curEp = curshow.getEpisode(int(sqlshow["season"]), int(sqlshow["episode"]))
self.show = helpers.findCertainShow(sickbeard.showList, int(sqlshow["showid"]))
if self.show:
curEp = self.show.getEpisode(int(sqlshow["season"]), int(sqlshow["episode"]))
searchString = self._get_episode_search_strings(curEp, add_string='PROPER|REPACK')

View file

@ -195,10 +195,10 @@ class TVShow(object):
return ep_list
def getEpisode(self, season=None, episode=None, file=None, noCreate=False, absolute_number=None):
def getEpisode(self, season=None, episode=None, file=None, noCreate=False, absolute_number=None, forceUpdate=False):
# Load XEM data to DB for show
sickbeard.scene_numbering.xem_refresh(self.indexerid, self.indexer)
sickbeard.scene_numbering.xem_refresh(self.indexerid, self.indexer, force=forceUpdate)
if not season in self.episodes:
self.episodes[season] = {}